-
Notifications
You must be signed in to change notification settings - Fork 919
/
Copy pathrun_tests_in_ci.js
99 lines (88 loc) · 2.84 KB
/
run_tests_in_ci.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
/**
* @license
* Copyright 2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
const yargs = require('yargs');
const path = require('path');
const { spawn } = require('child-process-promise');
const { writeFileSync } = require('fs');
const LOGDIR = process.env.CI ? process.env.HOME : '/tmp';
// Maps the packages where we should not run `test:all` and instead isolate the cross-browser tests.
// TODO(dwyfrequency): Update object with `storage` and `firestore` packages.
const crossBrowserPackages = {
'packages/auth': 'test:browser:unit',
'packages/auth-compat': 'test:browser:unit',
'packages/firestore': 'test:browser:unit',
'packages/firestore-compat': 'test:browser'
};
function writeLogs(status, name, logText) {
const safeName = name.replace(/@/g, 'at_').replace(/\//g, '_');
writeFileSync(path.join(LOGDIR, `${safeName}-ci-log.txt`), logText, {
encoding: 'utf8'
});
writeFileSync(
path.join(LOGDIR, `${safeName}-ci-summary.txt`),
`${status}: ${name}`,
{ encoding: 'utf8' }
);
}
const argv = yargs.options({
d: {
type: 'string',
desc: 'current working directory',
default: '.'
},
s: {
type: 'string',
desc: 'the npm script to run',
default: 'test'
}
}).argv;
(async () => {
const myPath = argv.d;
let scriptName = argv.s;
const dir = path.resolve(myPath);
const { name } = require(`${dir}/package.json`);
let testProcessOutput = '';
try {
if (process.env?.BROWSERS) {
for (const package in crossBrowserPackages) {
if (dir.endsWith(package)) {
scriptName = crossBrowserPackages[package];
}
}
}
const testProcess = spawn('yarn', ['--cwd', dir, scriptName]);
testProcess.childProcess.stdout.on('data', data => {
testProcessOutput += '[stdout]' + data.toString();
});
testProcess.childProcess.stderr.on('data', data => {
testProcessOutput += '[stderr]' + data.toString();
});
await testProcess;
console.log('Success: ' + name);
writeLogs('Success', name, testProcessOutput);
} catch (e) {
console.error('Failure: ' + name);
console.error(testProcessOutput);
if (process.env.CHROME_VERSION_NOTES) {
console.error();
console.error(process.env.CHROME_VERSION_NOTES);
console.error();
}
writeLogs('Failure', name, testProcessOutput);
process.exit(1);
}
})();