Skip to content
This repository has been archived by the owner on Jun 1, 2022. It is now read-only.

Move "jest" config out of packages.json and put it inside "jest.conf.js" file #861

Closed
nashwaan opened this issue Oct 10, 2017 · 2 comments
Closed

Comments

@nashwaan
Copy link

nashwaan commented Oct 10, 2017

I'm submitting a feature request

  • Aurelia Skeleton Version
    skeleton-esnext-webpack
    skeleton-typescript-webpack

  • Framework Version:
    1.1.5

Please tell us about your environment:

  • Operating System:
    Windows 10

  • Node Version:
    8.6.0

  • NPM Version:
    5.4.2

  • JSPM OR Webpack AND Version
    webpack 3.6.0

  • Browser:
    all

  • Language:
    TypeScript and ESNext

Current behavior:
Configurations of jest is currently inside package.json in these skeletons skeleton-esnext-webpack and skeleton-typescript-webpack.

Desired behavior:
Configurations of jest should be in a separate file jest.conf.js. To acheive this, first we create this file:

// test/jest.conf.js
const path = require('path');

module.exports = {

  rootDir: path.dirname(__dirname),

  modulePaths: [
    "<rootDir>/src",
    "<rootDir>/node_modules"
  ],

  moduleFileExtensions: ["js", "json"],

  transform: {
    "^.+\\.jsx?$": "babel-jest"
  },

  testRegex: "\\.spec\\.(ts|js)x?$",

  setupFiles: [
    "<rootDir>/test/jest-pretest.js"
  ],

  testEnvironment: "node",

  moduleNameMapper: {
    "aurelia-(.*)": "<rootDir>/node_modules/aurelia-$1"
  },

  collectCoverage: true,

  collectCoverageFrom: [
    "src/**/*.{js,ts}",
    "!**/*.spec.{js,ts}",
    "!**/node_modules/**",
    "!**/test/**"
  ],

  coverageDirectory: "<rootDir>/test/coverage-jest",

  coverageReporters: ["json", "lcov", "text", "html"]

};

Then remove "jest" property object from package.json.

Then make changes to the following lines in package-scripts.js :

      jest: {
        default: series(
          rimraf('test/coverage-jest'),
          crossEnv('BABEL_TARGET=node jest')
        ),
        accept: crossEnv('BABEL_TARGET=node jest -u'),
        watch: crossEnv('BABEL_TARGET=node jest --watch'),
      },

so they should take --config=test/jest.conf.js as an extra argument:

      jest: {
        default: series(
          rimraf('test/coverage-jest'),
          crossEnv('BABEL_TARGET=node jest --config=test/jest.conf.js')
        ),
        accept: crossEnv('BABEL_TARGET=node jest --config=test/jest.conf.js -u'),
        watch: crossEnv('BABEL_TARGET=node jest --config=test/jest.conf.js --watch'),
      },
  • What is the motivation / use case for changing the behavior?
    Having separate jest.conf.js will make it more consistent with karma.conf.js and protractor.conf.js way of setup.
    Also, package.json will be less cluttered.
    Shouldn't mix concerns inside package.json.
@Alexander-Taran
Copy link

@3cp I think we can close this one..

@3cp
Copy link
Member

3cp commented May 30, 2022

This skeleton is deprecated.
The latest one is in https://github.com/aurelia/v1
But the jest config is still in package.json, it's quite easy to extract the part out to jest.config.js/ts. But I am not sure how the community will respond. I am fine with both ways, but some users prefer one way over the other.

@bigopon bigopon closed this as completed Jun 1, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants