1 |
|
2 |
|
3 |
|
4 |
|
5 | const childProcess = require('child_process');
|
6 | const fs = require('fs');
|
7 | const path = require('path');
|
8 | const utils = require('./utils');
|
9 |
|
10 | const Flags = {
|
11 | DEBUG_DEVTOOLS: '--debug-devtools',
|
12 | DEBUG_DEVTOOLS_SHORTHAND: '-d',
|
13 | FETCH_CONTENT_SHELL: '--fetch-content-shell',
|
14 | CHROMIUM_PATH: '--chromium-path',
|
15 | TARGET: '--target',
|
16 | };
|
17 |
|
18 | const IS_DEBUG_ENABLED =
|
19 | utils.includes(process.argv, Flags.DEBUG_DEVTOOLS) || utils.includes(process.argv, Flags.DEBUG_DEVTOOLS_SHORTHAND);
|
20 | const CUSTOM_CHROMIUM_PATH = utils.parseArgs(process.argv)[Flags.CHROMIUM_PATH];
|
21 | const TARGET = utils.parseArgs(process.argv)[Flags.TARGET] || 'Release';
|
22 |
|
23 | const CURRENT_PATH = process.env.PWD || process.cwd();
|
24 | const isThirdParty = CURRENT_PATH.includes('third_party');
|
25 | const CHROMIUM_SRC_PATH = CUSTOM_CHROMIUM_PATH || getChromiumSrcPath(isThirdParty);
|
26 | const RELEASE_PATH = path.resolve(CHROMIUM_SRC_PATH, 'out', TARGET);
|
27 | const BLINK_TEST_PATH = path.resolve(CHROMIUM_SRC_PATH, 'third_party', 'blink', 'tools', 'run_web_tests.py');
|
28 | const DEVTOOLS_PATH = path.resolve(CHROMIUM_SRC_PATH, 'third_party', 'devtools-frontend', 'src');
|
29 | const CACHE_PATH = path.resolve(DEVTOOLS_PATH, '.test_cache');
|
30 |
|
31 | function main() {
|
32 | if (!utils.isDir(CACHE_PATH)) {
|
33 | fs.mkdirSync(CACHE_PATH);
|
34 | }
|
35 |
|
36 | const hasUserCompiledContentShell = utils.isFile(getContentShellBinaryPath(RELEASE_PATH));
|
37 | if (!hasUserCompiledContentShell) {
|
38 | return;
|
39 | }
|
40 | const outDir = path.resolve(RELEASE_PATH, '..');
|
41 |
|
42 | runTests(outDir, IS_DEBUG_ENABLED);
|
43 | }
|
44 | main();
|
45 |
|
46 | function getChromiumSrcPath(isThirdParty) {
|
47 | if (isThirdParty)
|
48 |
|
49 | {
|
50 | return path.resolve(CURRENT_PATH, '..', '..', '..');
|
51 | }
|
52 |
|
53 |
|
54 | const srcPath = path.resolve(CURRENT_PATH, '..', '..', 'chromium', 'src');
|
55 | if (!utils.isDir(srcPath)) {
|
56 | throw new Error(
|
57 | `Chromium source directory not found at \`${srcPath}\`. ` +
|
58 | 'Either move your standalone `devtools/devtools-frontend` checkout ' +
|
59 | 'so that `devtools` is at the same level as `chromium` in ' +
|
60 | '`chromium/src`, or use `--chromium-path`.');
|
61 | }
|
62 | return srcPath;
|
63 | }
|
64 |
|
65 | function getContentShellBinaryPath(dirPath) {
|
66 | if (process.platform === 'linux') {
|
67 | return path.resolve(dirPath, 'content_shell');
|
68 | }
|
69 |
|
70 | if (process.platform === 'win32') {
|
71 | return path.resolve(dirPath, 'content_shell.exe');
|
72 | }
|
73 |
|
74 | if (process.platform === 'darwin') {
|
75 | return path.resolve(dirPath, 'Content Shell.app', 'Contents', 'MacOS', 'Content Shell');
|
76 | }
|
77 | }
|
78 |
|
79 | function runTests(buildDirectoryPath, useDebugDevtools) {
|
80 | const testArgs = getInspectorTests().concat([
|
81 | '--build-directory',
|
82 | buildDirectoryPath,
|
83 | '--target',
|
84 | TARGET,
|
85 | ]);
|
86 | if (useDebugDevtools) {
|
87 | testArgs.push('--additional-driver-flag=--debug-devtools');
|
88 | } else {
|
89 | console.log('TIP: You can debug a test using: npm run debug-test inspector/test-name.html');
|
90 | }
|
91 |
|
92 | if (IS_DEBUG_ENABLED) {
|
93 | testArgs.push('--additional-driver-flag=--remote-debugging-port=9222');
|
94 | testArgs.push('--time-out-ms=6000000');
|
95 | console.log('\n=============================================');
|
96 | const unitTest = testArgs.find(arg => arg.includes('http/tests/devtools/unit/'));
|
97 | if (unitTest) {
|
98 | const unitTestPath = `http://localhost:8080/${unitTest.slice('http/tests/'.length)}`;
|
99 | const link =
|
100 | `http://localhost:8080/inspector-sources/debug/integration_test_runner.html?test=${unitTestPath}`;
|
101 | console.log('1) Go to: ', link);
|
102 | console.log('2) Go to: http://localhost:9222/, click on "inspected-page.html", and copy the ws query parameter');
|
103 | console.log('3) Open DevTools on DevTools and you can refresh to re-run the test');
|
104 | } else {
|
105 | console.log('Go to: http://localhost:9222/');
|
106 | console.log('Click on link and in console execute: test()');
|
107 | }
|
108 | console.log('=============================================\n');
|
109 | }
|
110 | const args = [...testArgs, ...getTestFlags()];
|
111 | console.log(`Running web tests with args: ${args.join(' ')}`);
|
112 | childProcess.spawn(BLINK_TEST_PATH, args, {stdio: 'inherit'});
|
113 | }
|
114 |
|
115 | function getTestFlags() {
|
116 | const flagValues = Object.keys(Flags).map(key => Flags[key]);
|
117 | return process.argv.slice(2).filter(arg => {
|
118 | const flagName = utils.includes(arg, '=') ? arg.slice(0, arg.indexOf('=')) : arg;
|
119 | return !utils.includes(flagValues, flagName) && !utils.includes(arg, 'inspector') &&
|
120 | !utils.includes(arg, 'http/tests/devtools');
|
121 | });
|
122 | }
|
123 |
|
124 | function getInspectorTests() {
|
125 | const specificTests =
|
126 | process.argv.filter(arg => utils.includes(arg, 'inspector') || utils.includes(arg, 'http/tests/devtools'));
|
127 | if (specificTests.length) {
|
128 | return specificTests;
|
129 | }
|
130 | return [
|
131 | 'inspector*',
|
132 | 'http/tests/inspector*',
|
133 | 'http/tests/devtools',
|
134 | ];
|
135 | }
|