Skip to content

Commit

Permalink
Copy all jest packages into example folders.
Browse files Browse the repository at this point in the history
This ensures we are using the latest version of every package.
  • Loading branch information
cpojer committed Jul 5, 2016
1 parent 2ed698d commit e730a46
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 16 deletions.
4 changes: 2 additions & 2 deletions examples/react/package.json
Original file line number Diff line number Diff line change
@@ -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": "*",
Expand Down
39 changes: 25 additions & 14 deletions scripts/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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
Expand All @@ -65,8 +77,7 @@ function runExampleTests(exampleDirectory) {
runCommands('npm test', exampleDirectory);
}


getPackages().forEach(runPackageTests);
packages.forEach(runPackageTests);

if (packagesOnly) {
return;
Expand Down

0 comments on commit e730a46

Please sign in to comment.