From e730a46c9c8fa17c0fa4e70d862797d3bbc80ea7 Mon Sep 17 00:00:00 2001 From: cpojer Date: Tue, 5 Jul 2016 11:03:40 +0900 Subject: [PATCH] Copy all jest packages into example folders. This ensures we are using the latest version of every package. --- examples/react/package.json | 4 ++-- scripts/test.js | 39 ++++++++++++++++++++++++------------- 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/examples/react/package.json b/examples/react/package.json index 833c43c17b2d..2628bf6d9407 100644 --- a/examples/react/package.json +++ b/examples/react/package.json @@ -1,7 +1,7 @@ { "dependencies": { - "react": "~0.14.0", - "react-dom": "~0.14.0" + "react": "~15.2.0", + "react-dom": "~15.2.0" }, "devDependencies": { "babel-jest": "*", diff --git a/scripts/test.js b/scripts/test.js index fee34308638b..8fe9120e0206 100644 --- a/scripts/test.js +++ b/scripts/test.js @@ -28,7 +28,9 @@ const rimraf = require('rimraf'); const EXAMPLES_DIR = path.resolve(__dirname, '../examples'); const INTEGRATION_TESTS_DIR = path.resolve(__dirname, '../integration_tests'); const JEST_CLI_PATH = path.resolve(__dirname, '../packages/jest-cli'); +const VERSION = require('../lerna').version; +const packages = getPackages(); const examples = fs.readdirSync(EXAMPLES_DIR) .map(file => path.resolve(EXAMPLES_DIR, file)) @@ -43,20 +45,30 @@ function runExampleTests(exampleDirectory) { console.log(chalk.bold(chalk.cyan('Testing example: ') + exampleDirectory)); runCommands('npm update', exampleDirectory); - rimraf.sync(path.resolve(exampleDirectory, './node_modules/jest-cli')); - mkdirp.sync(path.resolve(exampleDirectory, './node_modules/jest-cli')); - mkdirp.sync(path.resolve(exampleDirectory, './node_modules/.bin')); - - // Using `npm link jest-cli` can create problems with module resolution, - // so instead of this we'll create an `index.js` file that will export the - // local `jest-cli` package. - fs.writeFileSync( - path.resolve(exampleDirectory, './node_modules/jest-cli/index.js'), - `module.exports = require('${JEST_CLI_PATH}');\n`, // link to the local jest - 'utf8' - ); + packages.forEach(pkg => { + const name = path.basename(pkg); + const directory = path.resolve(exampleDirectory, 'node_modules', name); + + if (fs.existsSync(directory)) { + rimraf.sync(directory); + mkdirp.sync(directory); + // Using `npm link jest-*` can create problems with module resolution, + // so instead of this we'll create a proxy module. + fs.writeFileSync( + path.resolve(directory, 'index.js'), + `module.exports = require('${pkg}');\n`, + 'utf8' + ); + fs.writeFileSync( + path.resolve(directory, 'package.json'), + `{"name": "${name}", "version": "${VERSION}"}\n`, + 'utf8' + ); + } + }); // overwrite the jest link and point it to the local jest-cli + mkdirp.sync(path.resolve(exampleDirectory, './node_modules/.bin')); runCommands( `ln -sf ${JEST_CLI_PATH}/bin/jest.js ./node_modules/.bin/jest`, exampleDirectory @@ -65,8 +77,7 @@ function runExampleTests(exampleDirectory) { runCommands('npm test', exampleDirectory); } - -getPackages().forEach(runPackageTests); +packages.forEach(runPackageTests); if (packagesOnly) { return;