Skip to content

Commit 6bd253d

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 6bd253d

File tree

3 files changed

+38
-17
lines changed

3 files changed

+38
-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.bundles.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
'use strict';
2+
3+
const {readdirSync, statSync} = require('fs');
4+
const {join} = require('path');
5+
const sourceConfig = require('./config.source');
6+
7+
// Find all folders in packages/* with package.json
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+
// Create a module map to point React packages to the build output
17+
const moduleNameMapper = {};
18+
packages.forEach(name => {
19+
// Root entry point
20+
moduleNameMapper[`^${name}$`] = `<rootDir>/build/packages/${name}`;
21+
// Named entry points
22+
moduleNameMapper[`^${name}/(.*)$`] = `<rootDir>/build/packages/${name}/$1`;
23+
});
24+
25+
module.exports = Object.assign({}, sourceConfig, {
26+
// Redirect imports to the compiled bundles
27+
moduleNameMapper,
28+
// Only run bundle tests on whitelisted .public.* files
29+
// TODO: switch to a blacklist instead when enough tests are opted in
30+
testRegex: '/__tests__/.*\\.public\\.js$',
31+
// Exclude the build output from transforms
32+
transformIgnorePatterns: ['/node_modules/', '<rootDir>/build/'],
33+
});

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)