Skip to content
GitLab
    • Explore Projects Groups Snippets
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • C create-react-app
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 1,547
    • Issues 1,547
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 417
    • Merge requests 417
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Meta
  • create-react-app
  • Merge requests
  • !1830

Make coverage and snapshot Jest options overridable in package.json

  • Review changes

  • Download
  • Email patches
  • Plain diff
Merged Administrator requested to merge github/fork/ryansully/coverage-exclude into master 8 years ago
  • Overview 8
  • Commits 7
  • Pipelines 0
  • Changes 2

Created by: ryansully

Solves #1455 (closed).

These options are now configurable:

  • collectCoverageFrom
  • coverageReporters
  • coverageThreshold
  • snapshotSerializers

Verified by creating a new project using this code and testing with example package.json configuration:

"jest": {
  "collectCoverageFrom": [
    "src/**/*.{js,jsx}",
    "!<rootDir>/node_modules/",
    "!<rootDir>/path/to/dir/"
  ]
}
Compare
  • master (base)

and
  • latest version
    11b8c67a
    7 commits, 2 years ago

2 files
+ 48
- 6

    Preferences

    File browser
    Compare changes
packages/react-‎scripts/scripts‎
ut‎ils‎
createJes‎tConfig.js‎ +40 -1
ejec‎t.js‎ +8 -5
packages/react-scripts/scripts/utils/createJestConfig.js
+ 40
- 1
  • View file @ 11b8c67a

  • Edit in single-file editor

  • Open in Web IDE


@@ -10,6 +10,7 @@
'use strict';
const fs = require('fs');
const chalk = require('chalk');
const paths = require('../../config/paths');
module.exports = (resolve, rootDir, isEjecting) => {
@@ -27,7 +28,7 @@ module.exports = (resolve, rootDir, isEjecting) => {
setupTestFrameworkScriptFile: setupTestsFile,
testMatch: [
'<rootDir>/src/**/__tests__/**/*.js?(x)',
'<rootDir>/src/**/?(*.)(spec|test).js?(x)'
'<rootDir>/src/**/?(*.)(spec|test).js?(x)',
],
testEnvironment: 'node',
testURL: 'http://localhost',
@@ -46,5 +47,43 @@ module.exports = (resolve, rootDir, isEjecting) => {
if (rootDir) {
config.rootDir = rootDir;
}
const overrides = Object.assign({}, require(paths.appPackageJson).jest);
const supportedKeys = [
'collectCoverageFrom',
'coverageReporters',
'coverageThreshold',
'snapshotSerializers',
];
if (overrides) {
supportedKeys.forEach(key => {
if (overrides.hasOwnProperty(key)) {
config[key] = overrides[key];
delete overrides[key];
}
});
const unsupportedKeys = Object.keys(overrides);
if (unsupportedKeys.length) {
console.error(
chalk.red(
'Out of the box, Create React App only supports overriding ' +
'these Jest options:\n\n' +
supportedKeys.map(key => chalk.bold(' \u2022 ' + key)).join('\n') +
'.\n\n' +
'These options in your package.json Jest configuration ' +
'are not currently supported by Create React App:\n\n' +
unsupportedKeys
.map(key => chalk.bold(' \u2022 ' + key))
.join('\n') +
'\n\nIf you wish to override other Jest options, you need to ' +
'eject from the default setup. You can do so by running ' +
chalk.bold('npm run eject') +
' but remember that this is a one-way operation. ' +
'You may also file an issue with Create React App to discuss ' +
'supporting more options out of the box.\n'
)
);
process.exit(1);
}
}
return config;
};
packages/react-scripts/scripts/eject.js
+ 8
- 5
  • View file @ 11b8c67a

  • Edit in single-file editor

  • Open in Web IDE


@@ -78,6 +78,13 @@ inquirer
folders.forEach(verifyAbsent);
files.forEach(verifyAbsent);
// Prepare Jest config early in case it throws
const jestConfig = createJestConfig(
filePath => path.posix.join('<rootDir>', filePath),
null,
true
);
console.log();
console.log(cyan(`Copying files into ${appPath}`));
@@ -151,11 +158,7 @@ inquirer
console.log(cyan('Configuring package.json'));
// Add Jest config
console.log(` Adding ${cyan('Jest')} configuration`);
appPackage.jest = createJestConfig(
filePath => path.posix.join('<rootDir>', filePath),
null,
true
);
appPackage.jest = jestConfig;
// Add Babel config
console.log(` Adding ${cyan('Babel')} preset`);
0 Assignees
None
Assign to
0 Reviewers
None
Request review from
Labels
2
CLA Signed tag: new feature
2
CLA Signed tag: new feature
    Assign labels
  • Manage project labels

Milestone
1.0.0
1.0.0
None
Time tracking
No estimate or time spent
Lock merge request
Unlocked
1
1 participant
Administrator
Reference: facebook/create-react-app!1830
Source branch: github/fork/ryansully/coverage-exclude

Menu

Explore Projects Groups Snippets