forked from jestjs/jest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrunTests.js
113 lines (90 loc) · 3.68 KB
/
runTests.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/**
* 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.
*/
'use strict';
if (process.platform === 'win32') {
console.error('Tests are skipped on Windows.');
return;
}
const packagesOnly =
process.argv.indexOf('-p') !== -1 ||
process.argv.indexOf('--packages-only') !== -1;
const fs = require('graceful-fs');
const path = require('path');
const chalk = require('chalk');
const execSync = require('child_process').execSync;
const mkdirp = require('mkdirp');
const rimraf = require('rimraf');
const PACKAGES_DIR = path.resolve(__dirname, 'packages');
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 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) {
if (!cwd) {
cwd = __dirname;
}
[].concat(commands).forEach(cmd => {
let msg = chalk.green('-> ') + chalk.underline.bold('running:') +
' ' + chalk.bold.cyan(cmd);
if (cwd) {
msg += ' cwd: ' + chalk.underline.bold(cwd);
}
console.log(msg);
execSync(cmd, {
cwd,
stdio: [0, 1, 2],
});
});
}
function runPackageTests(packageDirectory) {
console.log(chalk.bold(chalk.cyan('Testing package: ') + packageDirectory));
runCommands('npm test', packageDirectory);
}
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'
);
// overwrite the jest link and point it to the local jest-cli
runCommands(
`ln -sf ${JEST_CLI_PATH}/bin/jest.js ./node_modules/.bin/jest`,
exampleDirectory
);
runCommands('npm test', exampleDirectory);
}
packages.forEach(runPackageTests);
if (packagesOnly) {
return;
}
// Run all tests, these are order dependent.
runCommands('node bin/jest.js --no-cache', 'packages/jest-cli');
runCommands('node bin/jest.js', 'packages/jest-cli');
runCommands('node bin/jest.js --no-watchman --no-cache', 'packages/jest-cli');
runCommands('node bin/jest.js --no-watchman', 'packages/jest-cli');
runCommands('node bin/jest.js --testRunner=jasmine1', 'packages/jest-cli');
runCommands('node bin/jest.js --runInBand', 'packages/jest-cli');
runCommands('node bin/jest.js --runInBand --logHeapUsage', 'packages/jest-cli');
runCommands('node bin/jest.js --json', 'packages/jest-cli');
runCommands('node bin/jest.js --verbose', 'packages/jest-cli');
examples.forEach(runExampleTests);
console.log(chalk.bold(chalk.cyan('Running integration tests:')));
runCommands('../packages/jest-cli/bin/jest.js', INTEGRATION_TESTS_DIR);