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 23, 2017
1 parent e944d7e commit 18dbd55
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 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
33 changes: 33 additions & 0 deletions scripts/jest/config.bundles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
'use strict';

const {readdirSync, statSync} = require('fs');
const {join} = require('path');
const sourceConfig = require('./config.source');

// Find all folders in packages/* with package.json
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();
});
// Create a module map to point React packages to the build output
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({}, sourceConfig, {
// 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/'],
});

0 comments on commit 18dbd55

Please sign in to comment.