Skip to content

Commit 347990d

Browse files
committed
Copy all jest packages into example folders.
This ensures we are using the latest version of every package.
1 parent d3f8b25 commit 347990d

File tree

2 files changed

+27
-16
lines changed

2 files changed

+27
-16
lines changed

examples/react/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"dependencies": {
3-
"react": "~0.14.0",
4-
"react-dom": "~0.14.0"
3+
"react": "~15.2.0",
4+
"react-dom": "~15.2.0"
55
},
66
"devDependencies": {
77
"babel-jest": "*",

scripts/test.js

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ const rimraf = require('rimraf');
2828
const EXAMPLES_DIR = path.resolve(__dirname, '../examples');
2929
const INTEGRATION_TESTS_DIR = path.resolve(__dirname, '../integration_tests');
3030
const JEST_CLI_PATH = path.resolve(__dirname, '../packages/jest-cli');
31+
const VERSION = require('../lerna').version;
3132

33+
const packages = getPackages();
3234

3335
const examples = fs.readdirSync(EXAMPLES_DIR)
3436
.map(file => path.resolve(EXAMPLES_DIR, file))
@@ -43,20 +45,30 @@ function runExampleTests(exampleDirectory) {
4345
console.log(chalk.bold(chalk.cyan('Testing example: ') + exampleDirectory));
4446

4547
runCommands('npm update', exampleDirectory);
46-
rimraf.sync(path.resolve(exampleDirectory, './node_modules/jest-cli'));
47-
mkdirp.sync(path.resolve(exampleDirectory, './node_modules/jest-cli'));
48-
mkdirp.sync(path.resolve(exampleDirectory, './node_modules/.bin'));
49-
50-
// Using `npm link jest-cli` can create problems with module resolution,
51-
// so instead of this we'll create an `index.js` file that will export the
52-
// local `jest-cli` package.
53-
fs.writeFileSync(
54-
path.resolve(exampleDirectory, './node_modules/jest-cli/index.js'),
55-
`module.exports = require('${JEST_CLI_PATH}');\n`, // link to the local jest
56-
'utf8'
57-
);
48+
packages.forEach(pkg => {
49+
const name = path.basename(pkg);
50+
const directory = path.resolve(exampleDirectory, 'node_modules', name);
51+
52+
if (fs.existsSync(directory)) {
53+
rimraf.sync(directory);
54+
mkdirp.sync(directory);
55+
// Using `npm link jest-*` can create problems with module resolution,
56+
// so instead of this we'll create a proxy module.
57+
fs.writeFileSync(
58+
path.resolve(directory, 'index.js'),
59+
`module.exports = require('${pkg}');\n`,
60+
'utf8'
61+
);
62+
fs.writeFileSync(
63+
path.resolve(directory, 'package.json'),
64+
`{"name": "${name}", "version": "${VERSION}"}\n`,
65+
'utf8'
66+
);
67+
}
68+
});
5869

5970
// overwrite the jest link and point it to the local jest-cli
71+
mkdirp.sync(path.resolve(exampleDirectory, './node_modules/.bin'));
6072
runCommands(
6173
`ln -sf ${JEST_CLI_PATH}/bin/jest.js ./node_modules/.bin/jest`,
6274
exampleDirectory
@@ -65,8 +77,7 @@ function runExampleTests(exampleDirectory) {
6577
runCommands('npm test', exampleDirectory);
6678
}
6779

68-
69-
getPackages().forEach(runPackageTests);
80+
packages.forEach(runPackageTests);
7081

7182
if (packagesOnly) {
7283
return;

0 commit comments

Comments
 (0)