Skip to content

Commit 3ec2df5

Browse files
Dmitrii AbramovFacebook Github Bot 9
authored andcommitted
Run tests for all packages and example projects
Summary: Closes jestjs#822 Differential Revision: D3104247 fb-gh-sync-id: 4513775f0b824084b9ab1f730af73b31d758c39b fbshipit-source-id: 4513775f0b824084b9ab1f730af73b31d758c39b
1 parent 9c978bb commit 3ec2df5

File tree

10 files changed

+96
-10
lines changed

10 files changed

+96
-10
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ node_js:
33
- "4"
44
- "5"
55
sudo: false
6+
before_install: npm i -g npm@latest

examples/getting_started/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
{
2+
"devDependencies": {
3+
"jest-cli": "*"
4+
},
25
"scripts": {
3-
"test": "node ../../bin/jest.js"
6+
"test": "jest"
47
}
58
}

examples/manual_mocks/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
{
2+
"devDependencies": {
3+
"jest-cli": "*"
4+
},
25
"scripts": {
3-
"test": "node ../../bin/jest.js"
6+
"test": "jest"
47
}
58
}

examples/timer/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
{
2+
"devDependencies": {
3+
"jest-cli": "*"
4+
},
25
"scripts": {
3-
"test": "node ../../bin/jest.js"
6+
"test": "jest"
47
}
58
}

examples/tutorial/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
{
2+
"devDependencies": {
3+
"jest-cli": "*"
4+
},
25
"dependencies": {
36
"jquery": "*"
47
},
58
"scripts": {
6-
"test": "node ../../bin/jest.js"
9+
"test": "jest"
710
}
811
}

examples/typescript/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44
"react-dom": "*"
55
},
66
"devDependencies": {
7+
"jest-cli": "*",
78
"react-addons-test-utils": "*",
89
"typescript": ">=1.6.2"
910
},
1011
"scripts": {
11-
"test": "node ../../bin/jest.js"
12+
"test": "jest"
1213
},
1314
"jest": {
1415
"scriptPreprocessor": "<rootDir>/preprocessor.js",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"lint": "eslint .",
4646
"postinstall": "node postinstall.js",
4747
"prepublish": "npm test",
48-
"test": "npm run lint && node bin/jest.js && npm run jasmine1"
48+
"test": "npm run lint && node bin/jest.js && npm run jasmine1 && npm link --ignore-scripts && node ./run_tests.js"
4949
},
5050
"jest": {
5151
"rootDir": "src",

packages/babel-plugin-jest-hoist/package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,13 @@
1010
"devDependencies": {
1111
"babel-jest": "*",
1212
"babel-preset-es2015": "*",
13-
"jest-cli": "*",
1413
"react": "^0.14.0"
1514
},
1615
"jest": {
17-
"testEnvironment": "<rootDir>/node_modules/jest-cli/src/environments/NodeEnvironment"
16+
"testEnvironment": "<rootDir>/../../src/environments/NodeEnvironment"
1817
},
1918
"scripts": {
2019
"prepublish": "npm test",
21-
"test": "jest"
20+
"test": "../../bin/jest.js"
2221
}
2322
}

packages/jest-mock/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,7 @@
77
},
88
"license": "BSD-3-Clause",
99
"main": "src/index.js",
10-
"dependencies": {}
10+
"scripts": {
11+
"test": "../../bin/jest.js"
12+
}
1113
}

run_tests.js

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/**
2+
* Copyright (c) 2014, Facebook, Inc. All rights reserved.
3+
*
4+
* This source code is licensed under the BSD-style license found in the
5+
* LICENSE file in the root directory of this source tree. An additional grant
6+
* of patent rights can be found in the PATENTS file in the same directory.
7+
*/
8+
9+
/**
10+
* This script runs tests for all packages in `./packages` and
11+
* example projects in `./examples`.
12+
*/
13+
14+
const fs = require('graceful-fs');
15+
const path = require('path');
16+
const chalk = require('chalk');
17+
const execSync = require('child_process').execSync;
18+
19+
const PACKAGES_DIR = './packages';
20+
const EXAMPLES_DIR = './examples';
21+
22+
const packages = fs.readdirSync(PACKAGES_DIR)
23+
.map(file => path.resolve(PACKAGES_DIR, file))
24+
.filter(f => fs.lstatSync(path.resolve(f)).isDirectory());
25+
26+
const examples = fs.readdirSync(EXAMPLES_DIR)
27+
.map(file => path.resolve(EXAMPLES_DIR, file))
28+
.filter(f => fs.lstatSync(path.resolve(f)).isDirectory());
29+
30+
function runCommands(commands, cwd) {
31+
commands = [].concat(commands);
32+
commands.forEach(cmd => {
33+
console.log(chalk.green('-> ') + chalk.underline.bold('running:') +
34+
' ' + chalk.bold.cyan(cmd));
35+
execSync(cmd, {
36+
cwd,
37+
stdio: [0, 1, 2],
38+
});
39+
});
40+
}
41+
42+
packages.forEach(cwd => {
43+
console.log(chalk.bold(chalk.cyan('Testing package: ') + cwd));
44+
runCommands('npm test', cwd);
45+
});
46+
47+
examples.forEach(cwd => {
48+
console.log(chalk.bold(chalk.cyan('Testing example: ') + cwd));
49+
50+
runCommands([
51+
'npm update',
52+
'rm -rf ./node_modules/jest-cli',
53+
'mkdir -p ./node_modules/jest-cli',
54+
'mkdir -p ./node_modules/.bin',
55+
], cwd);
56+
57+
// Using `npm link jest-cli` can create problems with module resolution,
58+
// so instead of this we'll create an `index.js` file that will export the
59+
// local `jest-cli` package.
60+
fs.writeFileSync(
61+
path.resolve(cwd, './node_modules/jest-cli/index.js'),
62+
`module.exports = require('../../../../');\n`, // link to the local jest
63+
'utf8'
64+
);
65+
66+
// overwrite the jest link and point it to the local jest-cli
67+
runCommands(
68+
['ln -sf ../../bin/jest.js ./node_modules/.bin/jest', 'npm test'],
69+
cwd
70+
);
71+
});

0 commit comments

Comments
 (0)