forked from googleapis/cloud-trace-nodejs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
120 lines (112 loc) · 3.44 KB
/
index.ts
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
/**
* The main entry point for cross-platform build scripts.
* Usage (in repository root directory):
* ts-node -P ./scripts ./scripts [step1] [step2 ... stepN]
* Alias for above:
* npm run script [step1] [step2 ... stepN]
*/
const [bin, script, ...steps] = process.argv;
import { checkInstall } from './check-install';
import { encryptCredentials, decryptCredentials } from './credentials';
import { initTestFixtures } from './init-test-fixtures';
import { reportCoverage } from './report-coverage';
import { runTests } from './run-tests';
import { testNonInterference } from './test-non-interference';
import { BUILD_DIRECTORY, existsP, spawnP } from './utils';
// The identifying string in the service account credentials file path.
const keyID = 'de480e4f9023';
/**
* Sequentially runs a list of commands.
*/
async function run(steps: string[]) {
for (const step of steps) {
console.log(`> Running step: ${step}`);
// If the step string is prefixed with "npm-", treat it as an "npm run"
// command, and then short-circuit.
if (step.indexOf('npm-') === 0) {
const moduleAndArgs = step.split('-');
await spawnP(
'npm',
[
'run',
moduleAndArgs.slice(1).join('-')
]
);
continue;
}
switch (step) {
case 'check-install':
await checkInstall();
break;
case 'encrypt-service-account-credentials':
const keyAndIV = await encryptCredentials(`node-team-test-${keyID}.json`);
console.log([
`key: ${keyAndIV.key}`,
`iv: ${keyAndIV.iv}`
].join('\n'));
break;
case 'decrypt-service-account-credentials':
const {
TRACE_SYSTEM_TEST_ENCRYPTED_CREDENTIALS_KEY: key,
TRACE_SYSTEM_TEST_ENCRYPTED_CREDENTIALS_IV: iv,
} = process.env;
if (!key || !iv) {
console.log('> Environment insufficient to decrypt service account credentials');
break;
}
await decryptCredentials({ key, iv }, `node-team-test-${keyID}.json`);
break;
case 'init-test-fixtures':
await initTestFixtures();
break;
case 'run-unit-tests':
await runTests({
globs: [
`${BUILD_DIRECTORY}/test/test-*.js`,
`${BUILD_DIRECTORY}/test/plugins/test-*.js`
],
rootDir: BUILD_DIRECTORY,
coverage: false,
timeout: 4000
});
break;
case 'run-unit-tests-with-coverage':
await runTests({
globs: [
`${BUILD_DIRECTORY}/test/test-*.js`,
`${BUILD_DIRECTORY}/test/plugins/test-*.js`
],
rootDir: BUILD_DIRECTORY,
coverage: true,
timeout: 4000
});
break;
case 'run-system-tests':
if (process.env.CI_PULL_REQUEST && !(await existsP('node-team-test-d0b0be11c23d.json'))) {
console.log('> Not running system tests in PRs');
} else {
await runTests({
globs: [
`system-test/*.js`,
],
rootDir: '.',
coverage: false
});
}
break;
case 'report-coverage':
await reportCoverage();
break;
case 'test-non-interference':
await testNonInterference();
break;
default:
console.log(`> ${step}: not found`);
break;
}
}
}
run(steps).catch((err) => {
console.error(err);
process.exit(1);
});