Giter Site home page Giter Site logo

natterstefan / jest-preset-ns Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 577 KB

An opinionated Jest preset for both react and non-react projects.

Home Page: https://www.npmjs.com/package/jest-preset-ns

License: Apache License 2.0

JavaScript 99.10% Shell 0.90%
jest jest-preset typescript babel jest-config jest-configuration jest-preset-react

jest-preset-ns's Introduction

jest-preset-ns

npm version Node CI

An opinionated Jest preset for both react and non-react projects.

It comes with two default presets with both babel and typescript support.

Features

  • default preset and preset for react are available
  • modern javascript (babel) and typescript (ts-jest) support
  • mocks files (eg. png, gif, jpg, ...) and date (jest-date-mock) automatically
  • looks for tests in __tests__ and for *.(spec|test).[jt]s(x)? files
  • easy extendable

Installation

npm install --save-dev jest-preset-ns jest
# or
yarn add jest-preset-ns jest --dev

Usage

Add jest-preset-ns as preset to your Jest config. This can be done by adding it to your package.json or jest.config.js:

// package.json
{
  "jest": {
    "preset": "jest-preset-ns"
  }
}
// jest.config.js
module.exports = {
  preset: 'jest-preset-ns',
  // or: preset: 'jest-preset-ns/presets/default'
  // [...]
}

Feel free to extend the "jest"-configuration object along the way with your own settings.

For running tests, use the Jest CLI.

Compatibility

This package is compatible only with React 16+.

Helpful tips

How to Publish

# create the tags and the version
yarn lerna:version

# create the changelog entry
npx lerna-changelog --from <tag> --to <tag>
git add CHANGELOG.md && git commit -m "chore: updated CHANGELOG"

# push the tags and the changelog update
git push --follow-tags

# publish to npm
yarn lerna:publish

References

jest-preset-ns's People

Contributors

dependabot[bot] avatar natterstefan avatar

Stargazers

 avatar

Watchers

 avatar  avatar

jest-preset-ns's Issues

Issue: Finalize and test TypeScript support

Bug Report

Relevant information

It was not possible to use the react preset in a NextJS TypeScript project (https://github.com/natterstefan/nextjs-tailwind-template) directly. The current setup with ts-loader did not work. This is most likely because of the current module and target in the tsconfig.json in the NextJS project. There is no way to customize this now. Adding tsconfig in globals.["ts-jest"] did not work.

In the end, creating a babel.config.js (according to https://dev.to/ericdouglas/how-to-configure-jest-on-a-next-js-project-2ic6) and using only jest-preset-ns/presets/react/jest-setup.js helped.

Steps to reproduce

  1. add the preset again https://github.com/natterstefan/nextjs-tailwind-template/blob/63ad8fd335c0dfda1b8be24c12a2c630b88feee2/jest.config.js#L2
  2. run yarn test

It also did not work with the ts-jest preset, but that's maybe a different problem. Maybe adding the preset directly works?

Observed Results

Jest was not able to transpile the files and work with them.

Expected Results

Jest can run the tests

feat: update dependencies and rules

Feature Request

Keep rules up to date.

Basic example

 /**
* Deactive support for removed rules which are still part of one of our
* presets.
*/
'jest/prefer-to-be-null': 0,
'jest/prefer-to-be-undefined': 0,

Add .gql and .graphql support

Feature Request

Add support for .gql and .graphql files -> https://www.npmjs.com/package/jest-transform-graphql.

Basic example

 "jest": {
    "transform": {
      "\\.(gql|graphql)$": "jest-transform-graphql",
      ".*": "babel-jest"
    }

Motivation

Add more use-cases for this applying this preset.

References

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.