forked from facebook/react-native
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrun-ci-javascript-tests.js
More file actions
132 lines (114 loc) · 3.49 KB
/
run-ci-javascript-tests.js
File metadata and controls
132 lines (114 loc) · 3.49 KB
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
* @noflow
*/
'use strict';
/**
* This script runs JavaScript tests.
* Available arguments:
* --maxWorkers [num] - how many workers, default 1
* --jestBinary [path] - path to jest binary, defaults to local node modules
* --yarnBinary [path] - path to yarn binary, defaults to yarn
*/
const {echo, exec, exit} = require('shelljs');
const argv = require('yargs').argv;
const numberOfMaxWorkers = argv.maxWorkers || 1;
let exitCode;
const JEST_BINARY = argv.jestBinary || './node_modules/.bin/jest';
const FLOW_BINARY = argv.flowBinary;
const YARN_BINARY = argv.yarnBinary || 'yarn';
function describe(message) {
echo(`\n\n>>>>> ${message}\n\n\n`);
}
try {
echo('Executing JavaScript tests');
describe('Test: Validate JS API snapshot');
if (exec(`${YARN_BINARY} run build-types --withSnapshot --validate`).code) {
echo(
'JS API snapshot validation failed. Please run `yarn build-types --withSnapshot` to update the snapshot.',
);
exitCode = 1;
throw Error(exitCode);
}
describe('Test: feature flags codegen');
if (exec(`${YARN_BINARY} run featureflags --verify-unchanged`).code) {
echo('Failed to run featureflags check.');
exitCode = 1;
throw Error(exitCode);
}
describe('Test: eslint');
if (exec(`${YARN_BINARY} run lint`).code) {
echo('Failed to run eslint.');
exitCode = 1;
throw Error(exitCode);
}
describe('Test: No JS build artifacts');
if (exec(`${YARN_BINARY} run build --validate`).code) {
echo('Failed, there are build artifacts in this commit.');
exitCode = 1;
throw Error(exitCode);
}
describe('Test: Flow check');
const flowCommand =
FLOW_BINARY == null
? `${YARN_BINARY} run flow-check`
: `${FLOW_BINARY} check`;
if (exec(flowCommand).code) {
echo('Failed to run flow.');
exitCode = 1;
throw Error(exitCode);
}
/*
* Build @react-native/codegen and @react-native/codegen-typescript-test
*
* The typescript-test project use TypeScript to write test cases
* In order to make these tests discoverable to jest
* *-test.ts must be compiled to *-test.js before running jest
*/
describe('Test: Build @react-native/codegen');
if (
exec(`${YARN_BINARY} --cwd ./packages/react-native-codegen run build`).code
) {
echo('Failed to build @react-native/codegen.');
exitCode = 1;
throw Error(exitCode);
}
describe('Test: Build @react-native/codegen-typescript-test');
if (
exec(
`${YARN_BINARY} --cwd ./private/react-native-codegen-typescript-test run build`,
).code
) {
echo('Failed to build @react-native/codegen-typescript-test.');
exitCode = 1;
throw Error(exitCode);
}
// TODO: Improve handling of `exec` (e.g. check `signal`). Also, why use `shelljs`?
describe('Test: Jest');
if (
exec(
`${JEST_BINARY} --maxWorkers=${numberOfMaxWorkers} --ci --reporters="default" --reporters="jest-junit"`,
).code
) {
echo('Failed to run JavaScript tests.');
echo('Most likely the code is broken.');
exitCode = 1;
throw Error(exitCode);
}
describe('Test: TypeScript tests');
if (exec(`${YARN_BINARY} run test-typescript`).code) {
echo('Failed to run TypeScript tests.');
exitCode = 1;
throw Error(exitCode);
}
exitCode = 0;
} finally {
// Do cleanup here
echo('Finished.');
}
exit(exitCode);