forked from jestjs/jest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrunTests.js
75 lines (63 loc) · 2.34 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
/**
* 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';
/**
* This script runs tests for all packages in `./packages` and
* example projects in `./examples`.
*/
if (process.platform === 'win32') {
console.error('Tests for examples and packages are skipped on Windows.');
return;
}
const fs = require('graceful-fs');
const path = require('path');
const chalk = require('chalk');
const execSync = require('child_process').execSync;
const mkdirp = require('mkdirp');
const PACKAGES_DIR = './packages';
const EXAMPLES_DIR = './examples';
const rimraf = require('rimraf');
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', cwd);
rimraf.sync(path.resolve(cwd, './node_modules/jest-cli'));
mkdirp.sync(path.resolve(cwd, './node_modules/jest-cli'));
mkdirp.sync(path.resolve(cwd, './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(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', cwd);
runCommands('npm test', cwd);
});