forked from jestjs/jest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_examples.js
60 lines (51 loc) · 1.95 KB
/
test_examples.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
/**
* 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.
*/
const path = require('path');
const fs = require('graceful-fs');
const mkdirp = require('mkdirp');
const rimraf = require('rimraf');
const runCommand = require('./_runCommand');
const ROOT = path.resolve(__dirname, '..');
const BABEL_JEST_PATH = path.resolve(ROOT, 'packages/babel-jest');
const EXAMPLES_DIR = path.resolve(ROOT, 'examples');
const JEST_CLI_PATH = path.resolve(ROOT, 'packages/jest-cli');
const JEST_BIN_PATH = path.resolve(JEST_CLI_PATH, 'bin/jest.js');
const NODE_VERSION = Number(process.version.match(/^v(\d+\.\d+)/)[1]);
const SKIP_ON_OLD_NODE = ['react-native'];
const INSTALL = ['react-native'];
const examples = fs
.readdirSync(EXAMPLES_DIR)
.map(file => path.resolve(EXAMPLES_DIR, file))
.filter(f => fs.lstatSync(path.resolve(f)).isDirectory());
const link = (exampleDirectory, from) => {
const nodeModules = exampleDirectory + path.sep + 'node_modules' + path.sep;
const localBabelJest = path.join(nodeModules, 'babel-jest');
mkdirp.sync(nodeModules);
rimraf.sync(localBabelJest);
runCommand('ln', ['-fs', from, nodeModules], exampleDirectory);
};
examples.forEach(exampleDirectory => {
const exampleName = path.basename(exampleDirectory);
if (NODE_VERSION < 6 && SKIP_ON_OLD_NODE.indexOf(exampleName) !== -1) {
console.log(`Skipping ${exampleName} on node ${process.version}.`);
return;
}
if (INSTALL.indexOf(exampleName) !== -1) {
runCommand('yarn', ['--production'], exampleDirectory);
}
link(exampleDirectory, BABEL_JEST_PATH);
});
runCommand(
JEST_BIN_PATH,
['--projects'].concat(
examples.map(
(example, index) => example + (index > 3 ? path.sep + 'package.json' : '')
)
),
EXAMPLES_DIR
);