|
| 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 | +}); |
0 commit comments