Skip to content

Commit

Permalink
Add yarn test-bundles and yarn test-prod-bundles
Browse files Browse the repository at this point in the history
Only files ending with -test.public.js are opted in (so far we don't have any).
  • Loading branch information
gaearon committed Nov 22, 2017
1 parent 9bb8e67 commit e2278a8
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 28 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@
"postinstall": "node node_modules/fbjs-scripts/node/check-dev-engines.js package.json",
"test": "cross-env NODE_ENV=development jest --config ./scripts/jest/config.source.js",
"test-prod": "cross-env NODE_ENV=production jest --config ./scripts/jest/config.source.js",
"test-bundles": "cross-env NODE_ENV=development jest --config ./scripts/jest/config.bundles.js",
"test-bundles-prod": "cross-env NODE_ENV=production jest --config ./scripts/jest/config.bundles.js",
"flow": "node ./scripts/tasks/flow.js",
"prettier": "node ./scripts/prettier/index.js write-changed",
"prettier-all": "node ./scripts/prettier/index.js write",
Expand Down
19 changes: 19 additions & 0 deletions scripts/jest/config.base.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
'use strict';

module.exports = {
modulePathIgnorePatterns: [
'<rootDir>/scripts/rollup/shims/',
'<rootDir>/scripts/bench/',
],
transform: {
'.*': require.resolve('./preprocessor.js'),
},
setupFiles: [require.resolve('./setupEnvironment.js')],
setupTestFrameworkScriptFile: require.resolve('./setupTests.js'),
testRegex: '/__tests__/.*(\\.js|\\.coffee|[^d]\\.ts)$',
moduleFileExtensions: ['js', 'json', 'node', 'coffee', 'ts'],
rootDir: process.cwd(),
roots: ['<rootDir>/packages', '<rootDir>/scripts'],
collectCoverageFrom: ['packages/**/*.js'],
timers: 'fake',
};
32 changes: 32 additions & 0 deletions scripts/jest/config.bundles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
'use strict';

const {readdirSync, statSync} = require('fs');
const {join} = require('path');

// Create a module map to point React packages to the build output.
const baseConfig = require('./config.base');
const packagesRoot = join(__dirname, '..', '..', 'packages');
const packages = readdirSync(packagesRoot).filter(dir => {
if (dir.charAt(0) === '.') {
return false;
}
const packagePath = join(packagesRoot, dir, 'package.json');
return statSync(packagePath).isFile();
});
const moduleNameMapper = {};
packages.forEach(name => {
// Root entry point
moduleNameMapper[`^${name}$`] = `<rootDir>/build/packages/${name}`;
// Named entry points
moduleNameMapper[`^${name}/(.*)$`] = `<rootDir>/build/packages/${name}/$1`;
});

module.exports = Object.assign({}, baseConfig, {
// Redirect imports to the compiled bundles.
moduleNameMapper,
// Only run bundle tests on whitelisted .public.* files.
// TODO: switch to a blacklist instead when enough tests are opted in.
testRegex: '/__tests__/.*\\.public\\.js$',
// Exclude the build output from transforms.
transformIgnorePatterns: ['/node_modules/', '<rootDir>/build/'],
});
20 changes: 3 additions & 17 deletions scripts/jest/config.source.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,5 @@
'use strict';

module.exports = {
modulePathIgnorePatterns: [
'<rootDir>/scripts/rollup/shims/',
'<rootDir>/scripts/bench/',
],
transform: {
'.*': require.resolve('./preprocessor.js'),
},
setupFiles: [require.resolve('./setupEnvironment.js')],
setupTestFrameworkScriptFile: require.resolve('./setupTests.js'),
testRegex: '/__tests__/.*(\\.js|\\.coffee|[^d]\\.ts)$',
moduleFileExtensions: ['js', 'json', 'node', 'coffee', 'ts'],
rootDir: process.cwd(),
roots: ['<rootDir>/packages', '<rootDir>/scripts'],
collectCoverageFrom: ['packages/**/*.js'],
timers: 'fake',
};
const baseConfig = require('./config.base');

module.exports = Object.assign({}, baseConfig);
11 changes: 0 additions & 11 deletions scripts/jest/setupEnvironment.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
/* eslint-disable */

jest.mock('shared/ReactFeatureFlags', () => {
// We can alter flags based on environment here
// (e.g. for CI runs with different flags).
return require.requireActual('shared/ReactFeatureFlags');
});

// Error logging varies between Fiber and Stack;
// Rather than fork dozens of tests, mock the error-logging file by default.
// TODO: direct imports like some-package/src/* are bad. Fix me.
jest.mock('react-reconciler/src/ReactFiberErrorLogger');

const NODE_ENV = process.env.NODE_ENV;
if (NODE_ENV !== 'development' && NODE_ENV !== 'production') {
throw new Error('NODE_ENV must either be set to development or production.');
Expand Down

0 comments on commit e2278a8

Please sign in to comment.