Skip to content

Commit 0ba8587

Browse files
committed
Add yarn test-bundles and yarn test-prod-bundles
Only files ending with -test.public.js are opted in (so far we don't have any).
1 parent e944d7e commit 0ba8587

File tree

4 files changed

+56
-17
lines changed

4 files changed

+56
-17
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@
105105
"postinstall": "node node_modules/fbjs-scripts/node/check-dev-engines.js package.json",
106106
"test": "cross-env NODE_ENV=development jest --config ./scripts/jest/config.source.js",
107107
"test-prod": "cross-env NODE_ENV=production jest --config ./scripts/jest/config.source.js",
108+
"test-bundles": "cross-env NODE_ENV=development jest --config ./scripts/jest/config.bundles.js",
109+
"test-bundles-prod": "cross-env NODE_ENV=production jest --config ./scripts/jest/config.bundles.js",
108110
"flow": "node ./scripts/tasks/flow.js",
109111
"prettier": "node ./scripts/prettier/index.js write-changed",
110112
"prettier-all": "node ./scripts/prettier/index.js write",

scripts/jest/config.base.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
'use strict';
2+
3+
module.exports = {
4+
modulePathIgnorePatterns: [
5+
'<rootDir>/scripts/rollup/shims/',
6+
'<rootDir>/scripts/bench/',
7+
],
8+
transform: {
9+
'.*': require.resolve('./preprocessor.js'),
10+
},
11+
setupFiles: [require.resolve('./setupEnvironment.js')],
12+
setupTestFrameworkScriptFile: require.resolve('./setupTests.js'),
13+
testRegex: '/__tests__/.*(\\.js|\\.coffee|[^d]\\.ts)$',
14+
moduleFileExtensions: ['js', 'json', 'node', 'coffee', 'ts'],
15+
rootDir: process.cwd(),
16+
roots: ['<rootDir>/packages', '<rootDir>/scripts'],
17+
collectCoverageFrom: ['packages/**/*.js'],
18+
timers: 'fake',
19+
};

scripts/jest/config.bundles.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
'use strict';
2+
3+
const {readdirSync, statSync} = require('fs');
4+
const {join} = require('path');
5+
6+
// Create a module map to point React packages to the build output.
7+
const baseConfig = require('./config.base');
8+
const packagesRoot = join(__dirname, '..', '..', 'packages');
9+
const packages = readdirSync(packagesRoot).filter(dir => {
10+
if (dir.charAt(0) === '.') {
11+
return false;
12+
}
13+
const packagePath = join(packagesRoot, dir, 'package.json');
14+
return statSync(packagePath).isFile();
15+
});
16+
const moduleNameMapper = {};
17+
packages.forEach(name => {
18+
// Root entry point
19+
moduleNameMapper[`^${name}$`] = `<rootDir>/build/packages/${name}`;
20+
// Named entry points
21+
moduleNameMapper[`^${name}/(.*)$`] = `<rootDir>/build/packages/${name}/$1`;
22+
});
23+
24+
module.exports = Object.assign({}, baseConfig, {
25+
// Redirect imports to the compiled bundles.
26+
moduleNameMapper,
27+
// Only run bundle tests on whitelisted .public.* files.
28+
// TODO: switch to a blacklist instead when enough tests are opted in.
29+
testRegex: '/__tests__/.*\\.public\\.js$',
30+
// Exclude the build output from transforms.
31+
transformIgnorePatterns: ['/node_modules/', '<rootDir>/build/'],
32+
});

scripts/jest/config.source.js

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,5 @@
11
'use strict';
22

3-
module.exports = {
4-
modulePathIgnorePatterns: [
5-
'<rootDir>/scripts/rollup/shims/',
6-
'<rootDir>/scripts/bench/',
7-
],
8-
transform: {
9-
'.*': require.resolve('./preprocessor.js'),
10-
},
11-
setupFiles: [require.resolve('./setupEnvironment.js')],
12-
setupTestFrameworkScriptFile: require.resolve('./setupTests.js'),
13-
testRegex: '/__tests__/.*(\\.js|\\.coffee|[^d]\\.ts)$',
14-
moduleFileExtensions: ['js', 'json', 'node', 'coffee', 'ts'],
15-
rootDir: process.cwd(),
16-
roots: ['<rootDir>/packages', '<rootDir>/scripts'],
17-
collectCoverageFrom: ['packages/**/*.js'],
18-
timers: 'fake',
19-
};
3+
const baseConfig = require('./config.base');
4+
5+
module.exports = Object.assign({}, baseConfig);

0 commit comments

Comments
 (0)