-
Notifications
You must be signed in to change notification settings - Fork 498
/
Copy pathnpm_test.js
141 lines (125 loc) · 5.35 KB
/
npm_test.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
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
const childProcess = require('child_process');
const fs = require('fs');
const path = require('path');
const utils = require('./utils');
const Flags = {
DEBUG_DEVTOOLS: '--debug-devtools',
DEBUG_DEVTOOLS_SHORTHAND: '-d',
FETCH_CONTENT_SHELL: '--fetch-content-shell',
CHROMIUM_PATH: '--chromium-path', // useful for bisecting
TARGET: '--target', // build sub-directory (e.g. Release, Default)
};
const IS_DEBUG_ENABLED =
utils.includes(process.argv, Flags.DEBUG_DEVTOOLS) || utils.includes(process.argv, Flags.DEBUG_DEVTOOLS_SHORTHAND);
const CUSTOM_CHROMIUM_PATH = utils.parseArgs(process.argv)[Flags.CHROMIUM_PATH];
const TARGET = utils.parseArgs(process.argv)[Flags.TARGET] || 'Release';
const CURRENT_PATH = process.env.PWD || process.cwd(); // Using env.PWD to account for symlinks.
const isThirdParty = CURRENT_PATH.includes('third_party');
const CHROMIUM_SRC_PATH = CUSTOM_CHROMIUM_PATH || getChromiumSrcPath(isThirdParty);
const RELEASE_PATH = path.resolve(CHROMIUM_SRC_PATH, 'out', TARGET);
const BLINK_TEST_PATH = path.resolve(CHROMIUM_SRC_PATH, 'third_party', 'blink', 'tools', 'run_web_tests.py');
const DEVTOOLS_PATH = path.resolve(CHROMIUM_SRC_PATH, 'third_party', 'devtools-frontend', 'src');
const CACHE_PATH = path.resolve(DEVTOOLS_PATH, '.test_cache');
function main() {
if (!utils.isDir(CACHE_PATH)) {
fs.mkdirSync(CACHE_PATH);
}
const contentShellBinaryPath = getContentShellBinaryPath(RELEASE_PATH);
const hasUserCompiledContentShell = utils.isFile(contentShellBinaryPath);
if (!hasUserCompiledContentShell) {
throw new Error(
`${contentShellBinaryPath} not found. ` +
'Ensure you have built a release version of `chrome` or use ' +
'`--target=Debug`.');
}
const outDir = path.resolve(RELEASE_PATH, '..');
runTests(outDir, IS_DEBUG_ENABLED);
}
main();
function getChromiumSrcPath(isThirdParty) {
if (isThirdParty)
// Assume we're in `chromium/src/third_party/devtools-frontend/src`.
{
return path.resolve(CURRENT_PATH, '..', '..', '..');
}
// Assume we're in `devtools/devtools-frontend`, where `devtools` is
// on the same level as `chromium`.
const srcPath = path.resolve(CURRENT_PATH, '..', '..', 'chromium', 'src');
if (!utils.isDir(srcPath)) {
throw new Error(
`Chromium source directory not found at \`${srcPath}\`. ` +
'Either move your standalone `devtools/devtools-frontend` checkout ' +
'so that `devtools` is at the same level as `chromium` in ' +
'`chromium/src`, or use `--chromium-path`.');
}
return srcPath;
}
function getContentShellBinaryPath(dirPath) {
if (process.platform === 'linux') {
return path.resolve(dirPath, 'content_shell');
}
if (process.platform === 'win32') {
return path.resolve(dirPath, 'content_shell.exe');
}
if (process.platform === 'darwin') {
return path.resolve(dirPath, 'Content Shell.app', 'Contents', 'MacOS', 'Content Shell');
}
}
function runTests(buildDirectoryPath, useDebugDevtools) {
const testArgs = getInspectorTests().concat([
'--build-directory',
buildDirectoryPath,
'--target',
TARGET,
]);
if (useDebugDevtools) {
testArgs.push('--additional-driver-flag=--debug-devtools');
} else {
console.log('TIP: You can debug a test using: npm run debug-test inspector/test-name.html');
}
if (IS_DEBUG_ENABLED) {
testArgs.push('--additional-driver-flag=--remote-allow-origins=*');
testArgs.push('--additional-driver-flag=--remote-debugging-port=9222');
testArgs.push('--timeout-ms=6000000');
console.log('\n=============================================');
const unitTest = testArgs.find(arg => arg.includes('http/tests/devtools/unit/'));
if (unitTest) {
const unitTestPath = `http://localhost:8080/${unitTest.slice('http/tests/'.length)}`;
const link =
`http://localhost:8080/inspector-sources/debug/integration_test_runner.html?test=${unitTestPath}`;
console.log('1) Go to: ', link);
console.log('2) Go to: http://localhost:9222/, click on "inspected-page.html", and copy the ws query parameter');
console.log('3) Open DevTools on DevTools and you can refresh to re-run the test');
} else {
console.log('Go to: http://localhost:9222/');
console.log('Click on link and in console execute: test()');
}
console.log('=============================================\n');
}
const args = [...testArgs, ...getTestFlags()];
console.log(`Running web tests with args: ${args.join(' ')}`);
childProcess.spawn(BLINK_TEST_PATH, args, {stdio: 'inherit'});
}
function getTestFlags() {
const flagValues = Object.keys(Flags).map(key => Flags[key]);
return process.argv.slice(2).filter(arg => {
const flagName = utils.includes(arg, '=') ? arg.slice(0, arg.indexOf('=')) : arg;
return !utils.includes(flagValues, flagName) && !utils.includes(arg, 'inspector') &&
!utils.includes(arg, 'http/tests/devtools');
});
}
function getInspectorTests() {
const specificTests =
process.argv.filter(arg => utils.includes(arg, 'inspector') || utils.includes(arg, 'http/tests/devtools'));
if (specificTests.length) {
return specificTests;
}
return [
'inspector*',
'http/tests/inspector*',
'http/tests/devtools',
];
}