Skip to content

Commit

Permalink
Run tests for all packages and example projects
Browse files Browse the repository at this point in the history
Summary: Closes jestjs#822

Differential Revision: D3104247

fb-gh-sync-id: 4513775f0b824084b9ab1f730af73b31d758c39b
fbshipit-source-id: 4513775f0b824084b9ab1f730af73b31d758c39b
  • Loading branch information
Dmitrii Abramov authored and Facebook Github Bot 9 committed Mar 28, 2016
1 parent 9c978bb commit 3ec2df5
Show file tree
Hide file tree
Showing 10 changed files with 96 additions and 10 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ node_js:
- "4"
- "5"
sudo: false
before_install: npm i -g npm@latest
5 changes: 4 additions & 1 deletion examples/getting_started/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"devDependencies": {
"jest-cli": "*"
},
"scripts": {
"test": "node ../../bin/jest.js"
"test": "jest"
}
}
5 changes: 4 additions & 1 deletion examples/manual_mocks/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"devDependencies": {
"jest-cli": "*"
},
"scripts": {
"test": "node ../../bin/jest.js"
"test": "jest"
}
}
5 changes: 4 additions & 1 deletion examples/timer/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"devDependencies": {
"jest-cli": "*"
},
"scripts": {
"test": "node ../../bin/jest.js"
"test": "jest"
}
}
5 changes: 4 additions & 1 deletion examples/tutorial/package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
{
"devDependencies": {
"jest-cli": "*"
},
"dependencies": {
"jquery": "*"
},
"scripts": {
"test": "node ../../bin/jest.js"
"test": "jest"
}
}
3 changes: 2 additions & 1 deletion examples/typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
"react-dom": "*"
},
"devDependencies": {
"jest-cli": "*",
"react-addons-test-utils": "*",
"typescript": ">=1.6.2"
},
"scripts": {
"test": "node ../../bin/jest.js"
"test": "jest"
},
"jest": {
"scriptPreprocessor": "<rootDir>/preprocessor.js",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"lint": "eslint .",
"postinstall": "node postinstall.js",
"prepublish": "npm test",
"test": "npm run lint && node bin/jest.js && npm run jasmine1"
"test": "npm run lint && node bin/jest.js && npm run jasmine1 && npm link --ignore-scripts && node ./run_tests.js"
},
"jest": {
"rootDir": "src",
Expand Down
5 changes: 2 additions & 3 deletions packages/babel-plugin-jest-hoist/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@
"devDependencies": {
"babel-jest": "*",
"babel-preset-es2015": "*",
"jest-cli": "*",
"react": "^0.14.0"
},
"jest": {
"testEnvironment": "<rootDir>/node_modules/jest-cli/src/environments/NodeEnvironment"
"testEnvironment": "<rootDir>/../../src/environments/NodeEnvironment"
},
"scripts": {
"prepublish": "npm test",
"test": "jest"
"test": "../../bin/jest.js"
}
}
4 changes: 3 additions & 1 deletion packages/jest-mock/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@
},
"license": "BSD-3-Clause",
"main": "src/index.js",
"dependencies": {}
"scripts": {
"test": "../../bin/jest.js"
}
}
71 changes: 71 additions & 0 deletions run_tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/**
* Copyright (c) 2014, Facebook, Inc. All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/

/**
* This script runs tests for all packages in `./packages` and
* example projects in `./examples`.
*/

const fs = require('graceful-fs');
const path = require('path');
const chalk = require('chalk');
const execSync = require('child_process').execSync;

const PACKAGES_DIR = './packages';
const EXAMPLES_DIR = './examples';

const packages = fs.readdirSync(PACKAGES_DIR)
.map(file => path.resolve(PACKAGES_DIR, file))
.filter(f => fs.lstatSync(path.resolve(f)).isDirectory());

const examples = fs.readdirSync(EXAMPLES_DIR)
.map(file => path.resolve(EXAMPLES_DIR, file))
.filter(f => fs.lstatSync(path.resolve(f)).isDirectory());

function runCommands(commands, cwd) {
commands = [].concat(commands);
commands.forEach(cmd => {
console.log(chalk.green('-> ') + chalk.underline.bold('running:') +
' ' + chalk.bold.cyan(cmd));
execSync(cmd, {
cwd,
stdio: [0, 1, 2],
});
});
}

packages.forEach(cwd => {
console.log(chalk.bold(chalk.cyan('Testing package: ') + cwd));
runCommands('npm test', cwd);
});

examples.forEach(cwd => {
console.log(chalk.bold(chalk.cyan('Testing example: ') + cwd));

runCommands([
'npm update',
'rm -rf ./node_modules/jest-cli',
'mkdir -p ./node_modules/jest-cli',
'mkdir -p ./node_modules/.bin',
], cwd);

// 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(cwd, './node_modules/jest-cli/index.js'),
`module.exports = require('../../../../');\n`, // link to the local jest
'utf8'
);

// overwrite the jest link and point it to the local jest-cli
runCommands(
['ln -sf ../../bin/jest.js ./node_modules/.bin/jest', 'npm test'],
cwd
);
});

0 comments on commit 3ec2df5

Please sign in to comment.