From 6bd253db2770366e4c99b146ed6d07f90a02fc4c Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Wed, 22 Nov 2017 21:35:13 +0000 Subject: [PATCH] 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). --- package.json | 2 ++ scripts/jest/config.bundles.js | 33 +++++++++++++++++++++++++++++++++ scripts/jest/config.source.js | 20 +++----------------- 3 files changed, 38 insertions(+), 17 deletions(-) create mode 100644 scripts/jest/config.bundles.js diff --git a/package.json b/package.json index b556450f39feb..1ca628761578f 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/scripts/jest/config.bundles.js b/scripts/jest/config.bundles.js new file mode 100644 index 0000000000000..9a5cca3f4da84 --- /dev/null +++ b/scripts/jest/config.bundles.js @@ -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}$`] = `/build/packages/${name}`; + // Named entry points + moduleNameMapper[`^${name}/(.*)$`] = `/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/', '/build/'], +}); diff --git a/scripts/jest/config.source.js b/scripts/jest/config.source.js index 179c18c50c33a..ffb17e302d354 100644 --- a/scripts/jest/config.source.js +++ b/scripts/jest/config.source.js @@ -1,19 +1,5 @@ 'use strict'; -module.exports = { - modulePathIgnorePatterns: [ - '/scripts/rollup/shims/', - '/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: ['/packages', '/scripts'], - collectCoverageFrom: ['packages/**/*.js'], - timers: 'fake', -}; +const baseConfig = require('./config.base'); + +module.exports = Object.assign({}, baseConfig);