forked from finos/perspective
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_js.js
157 lines (141 loc) · 5.79 KB
/
test_js.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/******************************************************************************
*
* Copyright (c) 2017, the Perspective Authors.
*
* This file is part of the Perspective library, distributed under the terms of
* the Apache License 2.0. The full license can be found in the LICENSE file.
*
*/
require("dotenv").config({path: "./.perspectiverc"});
const minimatch = require("minimatch");
const execSync = require("child_process").execSync;
const fs = require("fs");
const execute = cmd => execSync(cmd, {stdio: "inherit"});
const args = process.argv.slice(2);
const IS_PUPPETEER = args.indexOf("--private-puppeteer") !== -1;
const IS_EMSDK = args.indexOf("--private-emsdk") !== -1;
const IS_WRITE = args.indexOf("--write") !== -1 || process.env.WRITE_TESTS;
const IS_DOCKER = args.indexOf("--docker") !== -1 || process.env.PSP_DOCKER;
const IS_LOCAL_PUPPETEER = fs.existsSync("node_modules/puppeteer");
function jest() {
let cmd = "TZ=UTC node_modules/.bin/jest --rootDir=. --config=packages/perspective-test/jest.all.config.js --color --verbose";
if (args.indexOf("--saturate") > -1) {
console.log("-- Running the test suite in saturate mode");
cmd = "PSP_SATURATE=1 " + cmd;
}
if (args.indexOf("--bail") > -1) {
cmd += " --bail";
}
if (args.indexOf("--debug") > -1) {
console.log("-- Running tests in debug mode - all console.log statements are preserved.");
} else {
cmd += " --silent 2>&1";
}
if (args.indexOf("-t") > -1) {
const regex = args
.slice(args.indexOf("-t") + 1)
.join(".")
.replace(/ /g, ".");
console.log(`-- Qualifying search '${regex}'`);
cmd += ` -t "${regex}"`;
}
return (IS_WRITE ? "WRITE_TESTS=1 " : "") + cmd;
}
function slow_jest() {
if (!process.env.PACKAGE || minimatch("perspective-phosphor", process.env.PACKAGE)) {
return (IS_WRITE ? "WRITE_TESTS=1 " : "") + 'TZ=UTC node_modules/.bin/lerna exec --scope="@finos/perspective-jupyterlab" --concurrency 1 --no-bail -- yarn --silent test:run';
} else {
return 'echo ""';
}
}
function docker() {
console.log("-- Creating puppeteer docker image");
let cmd = `docker run -it --rm --shm-size=2g -u root ${process.env.PACKAGE ? `-e PACKAGE=${process.env.PACKAGE}` : ""} -v ${process.cwd()}:/src -w /src`;
if (IS_WRITE) {
console.log("-- Running the test suite in Write mode");
cmd += " -e WRITE_TESTS=1";
}
if (process.env.PSP_CPU_COUNT) {
cmd += ` --cpus="${parseInt(process.env.PSP_CPU_COUNT)}.0"`;
}
cmd += " perspective/puppeteer node scripts/test_js.js --private-puppeteer";
return cmd;
}
function emsdk() {
console.log("-- Creating emsdk docker image");
return "npm run --silent _emsdk -- node scripts/test_js.js --private-emsdk " + args.join(" ");
}
function emsdk() {
console.log("-- Creating emsdk docker image");
let cmd = "docker run --rm -it";
if (process.env.PSP_CPU_COUNT) {
cmd += ` --cpus="${parseInt(process.env.PSP_CPU_COUNT)}.0"`;
}
cmd += ` -v ${process.cwd()}:/src ${process.env.PACKAGE ? `-e PACKAGE=${process.env.PACKAGE}` : ""} perspective/emsdk node scripts/test_js.js --private-emsdk ` + args.join(" ");
return cmd;
}
try {
if (!IS_PUPPETEER && !IS_LOCAL_PUPPETEER) {
if (IS_DOCKER && !IS_EMSDK) {
execute(emsdk());
} else {
execute("node_modules/.bin/lerna exec -- mkdir -p dist/umd");
let cmd = "node_modules/.bin/lerna run test:build --stream";
if (process.env.PACKAGE) {
cmd += " --scope=@finos/${PACKAGE}";
}
execute(cmd);
}
if (!IS_EMSDK) {
execute(`yarn --silent clean --screenshots`);
execute(
docker() +
" " +
args
.map(function(arg) {
return "'" + arg.replace(/'/g, "'\\''") + "'";
})
.join(" ")
);
}
} else {
if (IS_LOCAL_PUPPETEER) {
execute(`yarn --silent clean --screenshots`);
execute("node_modules/.bin/lerna exec -- mkdir -p dist/umd");
let cmd = "node_modules/.bin/lerna run test:build --stream";
if (process.env.PACKAGE) {
cmd += " --scope=@finos/${PACKAGE}";
}
execute(cmd);
}
if (args.indexOf("--quiet") > -1) {
console.log("-- Running test suite in quiet mode");
execSync(`output=$(${jest()}); ret=$?; echo "\${output}"; exit $ret`, {stdio: "inherit"});
execSync(`output=$(${slow_jest()}); ret=$?; echo "\${output}"; exit $ret`, {stdio: "inherit"});
} else if (process.env.PACKAGE) {
console.log("-- Running test suite in individual mode");
let cmd = "TZ=UTC node_modules/.bin/lerna exec --concurrency 1 --no-bail";
if (process.env.PACKAGE) {
cmd += " --scope=@finos/${PACKAGE}";
}
cmd += " -- yarn --silent test:run";
if (args.indexOf("-t") > -1) {
let regex = args.slice(args.indexOf("-t") + 1);
const len = regex.findIndex(x => x.indexOf('"' > -1));
regex = regex.slice(0, len + 1);
console.log(`-- Qualifying search '${regex.join(" ")}'`);
regex = regex.join(".").replace(/ /g, ".");
cmd += ` -t "${regex}"`;
}
execute((IS_WRITE ? "WRITE_TESTS=1 " : "") + cmd);
execute(slow_jest());
} else {
console.log("-- Running test suite in fast mode");
execute(jest());
execute(slow_jest());
}
}
} catch (e) {
console.log(e.message);
process.exit(1);
}