Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 1 | // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Yang Guo | b7a4426 | 2019-11-05 15:25:23 +0100 | [diff] [blame] | 5 | const childProcess = require('child_process'); |
| 6 | const fs = require('fs'); |
| 7 | const path = require('path'); |
| 8 | const shell = require('child_process').execSync; |
| 9 | const utils = require('./utils'); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 10 | |
Yang Guo | b7a4426 | 2019-11-05 15:25:23 +0100 | [diff] [blame] | 11 | const Flags = { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 12 | DEBUG_DEVTOOLS: '--debug-devtools', |
| 13 | DEBUG_DEVTOOLS_SHORTHAND: '-d', |
| 14 | FETCH_CONTENT_SHELL: '--fetch-content-shell', |
| 15 | CHROMIUM_PATH: '--chromium-path', // useful for bisecting |
| 16 | TARGET: '--target', // build sub-directory (e.g. Release, Default) |
| 17 | }; |
| 18 | |
Yang Guo | b7a4426 | 2019-11-05 15:25:23 +0100 | [diff] [blame] | 19 | const IS_DEBUG_ENABLED = |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 20 | utils.includes(process.argv, Flags.DEBUG_DEVTOOLS) || utils.includes(process.argv, Flags.DEBUG_DEVTOOLS_SHORTHAND); |
Yang Guo | b7a4426 | 2019-11-05 15:25:23 +0100 | [diff] [blame] | 21 | const CUSTOM_CHROMIUM_PATH = utils.parseArgs(process.argv)[Flags.CHROMIUM_PATH]; |
| 22 | const IS_FETCH_CONTENT_SHELL = utils.includes(process.argv, Flags.FETCH_CONTENT_SHELL); |
| 23 | const TARGET = utils.parseArgs(process.argv)[Flags.TARGET] || 'Release'; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 24 | |
Yang Guo | b7a4426 | 2019-11-05 15:25:23 +0100 | [diff] [blame] | 25 | const CONTENT_SHELL_ZIP = 'content-shell.zip'; |
| 26 | const MAX_CONTENT_SHELLS = 10; |
| 27 | const PLATFORM = getPlatform(); |
| 28 | const PYTHON = process.platform === 'win32' ? 'python.bat' : 'python'; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 29 | |
Yang Guo | b7a4426 | 2019-11-05 15:25:23 +0100 | [diff] [blame] | 30 | const CURRENT_PATH = process.env.PWD; // Using env.PWD to account for symlinks. |
Mathias Bynens | 9866999 | 2019-11-28 08:50:08 +0100 | [diff] [blame] | 31 | const isThirdParty = CURRENT_PATH.includes('third_party'); |
| 32 | const CHROMIUM_SRC_PATH = CUSTOM_CHROMIUM_PATH || getChromiumSrcPath(isThirdParty); |
Yang Guo | b7a4426 | 2019-11-05 15:25:23 +0100 | [diff] [blame] | 33 | const RELEASE_PATH = path.resolve(CHROMIUM_SRC_PATH, 'out', TARGET); |
| 34 | const BLINK_TEST_PATH = path.resolve(CHROMIUM_SRC_PATH, 'third_party', 'blink', 'tools', 'run_web_tests.py'); |
| 35 | const DEVTOOLS_PATH = path.resolve(CHROMIUM_SRC_PATH, 'third_party', 'devtools-frontend', 'src'); |
| 36 | const CACHE_PATH = path.resolve(DEVTOOLS_PATH, '.test_cache'); |
| 37 | const SOURCE_PATH = path.resolve(DEVTOOLS_PATH, 'front_end'); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 38 | |
| 39 | function main() { |
Tim van der Lippe | ba26b2b | 2020-03-11 14:40:00 +0000 | [diff] [blame] | 40 | if (!utils.isDir(CACHE_PATH)) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 41 | fs.mkdirSync(CACHE_PATH); |
Tim van der Lippe | ba26b2b | 2020-03-11 14:40:00 +0000 | [diff] [blame] | 42 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 43 | deleteOldContentShells(); |
| 44 | |
Mathias Bynens | 9866999 | 2019-11-28 08:50:08 +0100 | [diff] [blame] | 45 | const hasUserCompiledContentShell = utils.isFile(getContentShellBinaryPath(RELEASE_PATH)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 46 | if (!IS_FETCH_CONTENT_SHELL && hasUserCompiledContentShell) { |
Mathias Bynens | 9866999 | 2019-11-28 08:50:08 +0100 | [diff] [blame] | 47 | const outDir = path.resolve(RELEASE_PATH, '..'); |
Tim van der Lippe | ba26b2b | 2020-03-11 14:40:00 +0000 | [diff] [blame] | 48 | if (!IS_DEBUG_ENABLED) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 49 | compileFrontend(); |
Tim van der Lippe | ba26b2b | 2020-03-11 14:40:00 +0000 | [diff] [blame] | 50 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 51 | |
| 52 | runTests(outDir, IS_DEBUG_ENABLED); |
| 53 | return; |
| 54 | } |
| 55 | |
Mathias Bynens | 9866999 | 2019-11-28 08:50:08 +0100 | [diff] [blame] | 56 | findPreviousUploadedPosition(findMostRecentChromiumCommit()) |
| 57 | .then(onUploadedCommitPosition) |
| 58 | .catch(onError); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 59 | |
| 60 | function onError(error) { |
| 61 | console.log('Unable to run tests because of error:', error); |
| 62 | console.log(`Try removing the .test_cache folder [${CACHE_PATH}] and retrying`); |
| 63 | } |
| 64 | } |
| 65 | main(); |
| 66 | |
| 67 | function compileFrontend() { |
| 68 | console.log('Compiling devtools frontend'); |
| 69 | try { |
| 70 | shell(`ninja -C ${RELEASE_PATH} devtools_frontend_resources`, {cwd: CHROMIUM_SRC_PATH}); |
| 71 | } catch (err) { |
| 72 | console.log(err.stdout.toString()); |
| 73 | console.log('ERROR: Cannot compile frontend\n' + err); |
| 74 | process.exit(1); |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | function onUploadedCommitPosition(commitPosition) { |
Mathias Bynens | 9866999 | 2019-11-28 08:50:08 +0100 | [diff] [blame] | 79 | const contentShellDirPath = path.resolve(CACHE_PATH, commitPosition, 'out', TARGET); |
| 80 | const contentShellResourcesPath = path.resolve(contentShellDirPath, 'resources'); |
| 81 | const contentShellPath = path.resolve(CACHE_PATH, commitPosition, 'out'); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 82 | |
Mathias Bynens | 9866999 | 2019-11-28 08:50:08 +0100 | [diff] [blame] | 83 | const hasCachedContentShell = utils.isFile(getContentShellBinaryPath(contentShellDirPath)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 84 | if (hasCachedContentShell) { |
| 85 | console.log(`Using cached content shell at: ${contentShellPath}`); |
| 86 | copyFrontend(contentShellResourcesPath); |
| 87 | return runTests(contentShellPath, true); |
| 88 | } |
Mathias Bynens | 9866999 | 2019-11-28 08:50:08 +0100 | [diff] [blame] | 89 | const url = `http://commondatastorage.googleapis.com/chromium-browser-snapshots/${PLATFORM}/${commitPosition |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 90 | }/${CONTENT_SHELL_ZIP}`; |
| 91 | return prepareContentShellDirectory(commitPosition) |
| 92 | .then(() => downloadContentShell(url, commitPosition)) |
| 93 | .then(extractContentShell) |
| 94 | .then(() => copyFrontend(contentShellResourcesPath)) |
| 95 | .then(() => runTests(contentShellPath, true)); |
| 96 | } |
| 97 | |
| 98 | function copyFrontend(contentShellResourcesPath) { |
Mathias Bynens | 9866999 | 2019-11-28 08:50:08 +0100 | [diff] [blame] | 99 | const devtoolsResourcesPath = path.resolve(contentShellResourcesPath, 'inspector'); |
| 100 | const copiedFrontendPath = path.resolve(devtoolsResourcesPath, 'front_end'); |
| 101 | const debugFrontendPath = path.resolve(devtoolsResourcesPath, 'debug'); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 102 | utils.removeRecursive(copiedFrontendPath); |
| 103 | utils.removeRecursive(debugFrontendPath); |
| 104 | utils.copyRecursive(SOURCE_PATH, devtoolsResourcesPath); |
| 105 | fs.renameSync(copiedFrontendPath, debugFrontendPath); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 106 | } |
| 107 | |
Mathias Bynens | 9866999 | 2019-11-28 08:50:08 +0100 | [diff] [blame] | 108 | function getChromiumSrcPath(isThirdParty) { |
| 109 | if (isThirdParty) |
Tim van der Lippe | ba26b2b | 2020-03-11 14:40:00 +0000 | [diff] [blame] | 110 | // Assume we're in `chromium/src/third_party/devtools-frontend/src`. |
| 111 | { |
Mathias Bynens | 9866999 | 2019-11-28 08:50:08 +0100 | [diff] [blame] | 112 | return path.resolve(CURRENT_PATH, '..', '..', '..'); |
Tim van der Lippe | ba26b2b | 2020-03-11 14:40:00 +0000 | [diff] [blame] | 113 | } |
Mathias Bynens | 9866999 | 2019-11-28 08:50:08 +0100 | [diff] [blame] | 114 | // Assume we're in `devtools/devtools-frontend`, where `devtools` is |
| 115 | // on the same level as `chromium`. |
| 116 | const srcPath = path.resolve(CURRENT_PATH, '..', '..', 'chromium', 'src'); |
Tim van der Lippe | ba26b2b | 2020-03-11 14:40:00 +0000 | [diff] [blame] | 117 | if (!utils.isDir(srcPath)) { |
| 118 | throw new Error( |
| 119 | `Chromium source directory not found at \`${srcPath}\`. ` + |
| 120 | 'Either move your standalone `devtools/devtools-frontend` checkout ' + |
| 121 | 'so that `devtools` is at the same level as `chromium` in ' + |
| 122 | '`chromium/src`, or use `--chromium-path`.'); |
| 123 | } |
Mathias Bynens | 9866999 | 2019-11-28 08:50:08 +0100 | [diff] [blame] | 124 | return srcPath; |
| 125 | } |
| 126 | |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 127 | function getPlatform() { |
| 128 | if (process.platform === 'linux') { |
| 129 | return 'Linux_x64'; |
| 130 | } |
| 131 | if (process.platform === 'win32') { |
| 132 | return 'Win_x64'; |
| 133 | } |
Tim van der Lippe | ba26b2b | 2020-03-11 14:40:00 +0000 | [diff] [blame] | 134 | if (process.platform === 'darwin') { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 135 | return 'Mac'; |
Tim van der Lippe | ba26b2b | 2020-03-11 14:40:00 +0000 | [diff] [blame] | 136 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 137 | |
| 138 | throw new Error(`Unrecognized platform detected: ${process.platform}`); |
| 139 | } |
| 140 | |
| 141 | function findMostRecentChromiumCommit() { |
Tim van der Lippe | ba26b2b | 2020-03-11 14:40:00 +0000 | [diff] [blame] | 142 | const commitMessage = shell('git log --max-count=1 --grep="Cr-Commit-Position"').toString().trim(); |
Mathias Bynens | 9866999 | 2019-11-28 08:50:08 +0100 | [diff] [blame] | 143 | const commitPosition = commitMessage.match(/Cr-Commit-Position: refs\/heads\/master@\{#([0-9]+)\}/)[1]; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 144 | return commitPosition; |
| 145 | } |
| 146 | |
| 147 | function deleteOldContentShells() { |
Mathias Bynens | 9866999 | 2019-11-28 08:50:08 +0100 | [diff] [blame] | 148 | const files = fs.readdirSync(CACHE_PATH); |
Tim van der Lippe | ba26b2b | 2020-03-11 14:40:00 +0000 | [diff] [blame] | 149 | if (files.length < MAX_CONTENT_SHELLS) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 150 | return; |
Tim van der Lippe | ba26b2b | 2020-03-11 14:40:00 +0000 | [diff] [blame] | 151 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 152 | files.sort((a, b) => parseInt(b, 10) - parseInt(a, 10)); |
Mathias Bynens | 9866999 | 2019-11-28 08:50:08 +0100 | [diff] [blame] | 153 | const remainingNumberOfContentShells = MAX_CONTENT_SHELLS / 2; |
| 154 | const oldContentShellDirs = files.slice(remainingNumberOfContentShells); |
Tim van der Lippe | ba26b2b | 2020-03-11 14:40:00 +0000 | [diff] [blame] | 155 | for (let i = 0; i < oldContentShellDirs.length; i++) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 156 | utils.removeRecursive(path.resolve(CACHE_PATH, oldContentShellDirs[i])); |
Tim van der Lippe | ba26b2b | 2020-03-11 14:40:00 +0000 | [diff] [blame] | 157 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 158 | console.log(`Removed old content shells: ${oldContentShellDirs}`); |
| 159 | } |
| 160 | |
| 161 | function findPreviousUploadedPosition(commitPosition) { |
Mathias Bynens | 9866999 | 2019-11-28 08:50:08 +0100 | [diff] [blame] | 162 | const previousPosition = commitPosition - 100; |
| 163 | const positionsListURL = |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 164 | `http://commondatastorage.googleapis.com/chromium-browser-snapshots/?delimiter=/&prefix=${PLATFORM |
| 165 | }/&marker=${PLATFORM}/${previousPosition}/`; |
| 166 | return utils.fetch(positionsListURL).then(onPositionsList).catch(onError); |
| 167 | |
| 168 | function onPositionsList(buffer) { |
Mathias Bynens | 9866999 | 2019-11-28 08:50:08 +0100 | [diff] [blame] | 169 | const positions = buffer.toString('binary') |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 170 | .match(/([^<>]+)(?=<\/Prefix><\/CommonPrefixes>)/g) |
| 171 | .map(prefixedPosition => prefixedPosition.split('/')[1]) |
| 172 | .map(positionString => parseInt(positionString, 10)); |
Mathias Bynens | 9866999 | 2019-11-28 08:50:08 +0100 | [diff] [blame] | 173 | const positionSet = new Set(positions); |
| 174 | let previousUploadedPosition = commitPosition; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 175 | while (commitPosition - previousUploadedPosition < 100) { |
Tim van der Lippe | ba26b2b | 2020-03-11 14:40:00 +0000 | [diff] [blame] | 176 | if (positionSet.has(previousUploadedPosition)) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 177 | return previousUploadedPosition.toString(); |
Tim van der Lippe | ba26b2b | 2020-03-11 14:40:00 +0000 | [diff] [blame] | 178 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 179 | previousUploadedPosition--; |
| 180 | } |
| 181 | onError(); |
| 182 | } |
| 183 | |
| 184 | function onError(error) { |
Tim van der Lippe | ba26b2b | 2020-03-11 14:40:00 +0000 | [diff] [blame] | 185 | if (error) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 186 | console.log(`Received error: ${error} trying to fetch positions list from url: ${positionsListURL}`); |
Tim van der Lippe | ba26b2b | 2020-03-11 14:40:00 +0000 | [diff] [blame] | 187 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 188 | throw new Error(`Unable to find a previous upload position for commit position: ${commitPosition}`); |
| 189 | } |
| 190 | } |
| 191 | |
Mathias Bynens | 9866999 | 2019-11-28 08:50:08 +0100 | [diff] [blame] | 192 | async function prepareContentShellDirectory(folder) { |
| 193 | const contentShellPath = path.join(CACHE_PATH, folder); |
Tim van der Lippe | ba26b2b | 2020-03-11 14:40:00 +0000 | [diff] [blame] | 194 | if (utils.isDir(contentShellPath)) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 195 | utils.removeRecursive(contentShellPath); |
Tim van der Lippe | ba26b2b | 2020-03-11 14:40:00 +0000 | [diff] [blame] | 196 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 197 | fs.mkdirSync(contentShellPath); |
Mathias Bynens | 9866999 | 2019-11-28 08:50:08 +0100 | [diff] [blame] | 198 | return folder; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | function downloadContentShell(url, folder) { |
| 202 | console.log('Downloading content shell from:', url); |
| 203 | console.log('NOTE: Download is ~35-65 MB depending on OS'); |
| 204 | return utils.fetch(url).then(writeZip).catch(onError); |
| 205 | |
| 206 | function writeZip(buffer) { |
| 207 | console.log('Completed download of content shell'); |
Mathias Bynens | 9866999 | 2019-11-28 08:50:08 +0100 | [diff] [blame] | 208 | const contentShellZipPath = path.join(CACHE_PATH, folder, CONTENT_SHELL_ZIP); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 209 | fs.writeFileSync(contentShellZipPath, buffer); |
| 210 | return contentShellZipPath; |
| 211 | } |
| 212 | |
| 213 | function onError(error) { |
| 214 | console.log(`Received error: ${error} trying to download content shell from url: ${url}`); |
| 215 | throw new Error('Unable to download content shell'); |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | function extractContentShell(contentShellZipPath) { |
| 220 | console.log(`Extracting content shell zip: ${contentShellZipPath}`); |
Mathias Bynens | 9866999 | 2019-11-28 08:50:08 +0100 | [diff] [blame] | 221 | const unzipScriptPath = path.resolve(__dirname, 'unzip.py'); |
| 222 | const src = contentShellZipPath; |
| 223 | const dest = path.resolve(path.dirname(src), 'out'); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 224 | shell(`${PYTHON} ${unzipScriptPath} ${src} ${dest}`); |
| 225 | fs.unlinkSync(src); |
Mathias Bynens | 9866999 | 2019-11-28 08:50:08 +0100 | [diff] [blame] | 226 | const originalDirPath = path.resolve(dest, 'content-shell'); |
| 227 | const newDirPath = path.resolve(dest, TARGET); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 228 | fs.renameSync(originalDirPath, newDirPath); |
| 229 | fs.chmodSync(getContentShellBinaryPath(newDirPath), '755'); |
| 230 | if (process.platform === 'darwin') { |
Mathias Bynens | 9866999 | 2019-11-28 08:50:08 +0100 | [diff] [blame] | 231 | const helperPath = path.resolve( |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 232 | newDirPath, 'Content Shell.app', 'Contents', 'Frameworks', 'Content Shell Helper.app', 'Contents', 'MacOS', |
| 233 | 'Content Shell Helper'); |
| 234 | fs.chmodSync(helperPath, '755'); |
| 235 | } |
| 236 | return dest; |
| 237 | } |
| 238 | |
| 239 | function getContentShellBinaryPath(dirPath) { |
Tim van der Lippe | ba26b2b | 2020-03-11 14:40:00 +0000 | [diff] [blame] | 240 | if (process.platform === 'linux') { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 241 | return path.resolve(dirPath, 'content_shell'); |
Tim van der Lippe | ba26b2b | 2020-03-11 14:40:00 +0000 | [diff] [blame] | 242 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 243 | |
Tim van der Lippe | ba26b2b | 2020-03-11 14:40:00 +0000 | [diff] [blame] | 244 | if (process.platform === 'win32') { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 245 | return path.resolve(dirPath, 'content_shell.exe'); |
Tim van der Lippe | ba26b2b | 2020-03-11 14:40:00 +0000 | [diff] [blame] | 246 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 247 | |
Tim van der Lippe | ba26b2b | 2020-03-11 14:40:00 +0000 | [diff] [blame] | 248 | if (process.platform === 'darwin') { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 249 | return path.resolve(dirPath, 'Content Shell.app', 'Contents', 'MacOS', 'Content Shell'); |
Tim van der Lippe | ba26b2b | 2020-03-11 14:40:00 +0000 | [diff] [blame] | 250 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 251 | } |
| 252 | |
| 253 | function runTests(buildDirectoryPath, useDebugDevtools) { |
Mathias Bynens | 9866999 | 2019-11-28 08:50:08 +0100 | [diff] [blame] | 254 | const testArgs = getInspectorTests().concat([ |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 255 | '--build-directory', |
| 256 | buildDirectoryPath, |
| 257 | '--target', |
| 258 | TARGET, |
| 259 | ]); |
Tim van der Lippe | ba26b2b | 2020-03-11 14:40:00 +0000 | [diff] [blame] | 260 | if (useDebugDevtools) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 261 | testArgs.push('--additional-driver-flag=--debug-devtools'); |
Tim van der Lippe | ba26b2b | 2020-03-11 14:40:00 +0000 | [diff] [blame] | 262 | } else { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 263 | console.log('TIP: You can debug a test using: npm run debug-test inspector/test-name.html'); |
Tim van der Lippe | ba26b2b | 2020-03-11 14:40:00 +0000 | [diff] [blame] | 264 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 265 | |
| 266 | if (IS_DEBUG_ENABLED) { |
| 267 | testArgs.push('--additional-driver-flag=--remote-debugging-port=9222'); |
| 268 | testArgs.push('--time-out-ms=6000000'); |
| 269 | console.log('\n============================================='); |
Mathias Bynens | 9866999 | 2019-11-28 08:50:08 +0100 | [diff] [blame] | 270 | const unitTest = testArgs.find(arg => arg.includes('http/tests/devtools/unit/')); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 271 | if (unitTest) { |
Mathias Bynens | 9866999 | 2019-11-28 08:50:08 +0100 | [diff] [blame] | 272 | const unitTestPath = `http://localhost:8080/${unitTest.slice('http/tests/'.length)}`; |
| 273 | const link = |
Yang Guo | 49346f1 | 2020-02-06 10:52:02 +0100 | [diff] [blame] | 274 | `http://localhost:8080/inspector-sources/debug/integration_test_runner.html?test=${unitTestPath}`; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 275 | console.log('1) Go to: ', link); |
| 276 | console.log('2) Go to: http://localhost:9222/, click on "inspected-page.html", and copy the ws query parameter'); |
Tim van der Lippe | ba26b2b | 2020-03-11 14:40:00 +0000 | [diff] [blame] | 277 | console.log('3) Open DevTools on DevTools and you can refresh to re-run the test'); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 278 | } else { |
| 279 | console.log('Go to: http://localhost:9222/'); |
| 280 | console.log('Click on link and in console execute: test()'); |
| 281 | } |
| 282 | console.log('=============================================\n'); |
| 283 | } |
Mathias Bynens | 9866999 | 2019-11-28 08:50:08 +0100 | [diff] [blame] | 284 | const args = [BLINK_TEST_PATH].concat(testArgs).concat(getTestFlags()); |
Mathias Bynens | b0693f2 | 2020-01-23 13:17:15 +0100 | [diff] [blame] | 285 | console.log(`Running web tests with args: ${args.join(' ')}`); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 286 | childProcess.spawn(PYTHON, args, {stdio: 'inherit'}); |
| 287 | } |
| 288 | |
| 289 | function getTestFlags() { |
Mathias Bynens | 9866999 | 2019-11-28 08:50:08 +0100 | [diff] [blame] | 290 | const flagValues = Object.keys(Flags).map(key => Flags[key]); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 291 | return process.argv.slice(2).filter(arg => { |
Mathias Bynens | 9866999 | 2019-11-28 08:50:08 +0100 | [diff] [blame] | 292 | const flagName = utils.includes(arg, '=') ? arg.slice(0, arg.indexOf('=')) : arg; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 293 | return !utils.includes(flagValues, flagName) && !utils.includes(arg, 'inspector') && |
| 294 | !utils.includes(arg, 'http/tests/devtools'); |
| 295 | }); |
| 296 | } |
| 297 | |
| 298 | function getInspectorTests() { |
Mathias Bynens | 9866999 | 2019-11-28 08:50:08 +0100 | [diff] [blame] | 299 | const specificTests = |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 300 | process.argv.filter(arg => utils.includes(arg, 'inspector') || utils.includes(arg, 'http/tests/devtools')); |
Tim van der Lippe | ba26b2b | 2020-03-11 14:40:00 +0000 | [diff] [blame] | 301 | if (specificTests.length) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 302 | return specificTests; |
Tim van der Lippe | ba26b2b | 2020-03-11 14:40:00 +0000 | [diff] [blame] | 303 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 304 | return [ |
| 305 | 'inspector*', |
| 306 | 'http/tests/inspector*', |
| 307 | 'http/tests/devtools', |
| 308 | ]; |
Kent Tamura | d3d3f04 | 2018-12-12 02:45:28 +0000 | [diff] [blame] | 309 | } |