Skip to content

Chrome DevTools for coding agents

chore: prepare paths, build, and test runner for devtools-frontend merge (#3465)

Nikolay Vitkovec6fd2cf7a84
diff --git a/.gitignore b/.gitignore
index cbcc0d20..4da34c63 100644
--- a/.gitignore
+++ b/.gitignore
@@ -88,11 +88,11 @@ web_modules/
# Next.js build output
.next
-out
+/out
# Nuxt.js build / generate output
.nuxt
-dist
+/dist
# Gatsby files
.cache/
@@ -144,7 +144,7 @@ dist
.pnp.*
# Build output directory
-build/
+/build/
log.txt
diff --git a/.nvmrc b/.nvmrc
index 18c92ea9..54c65116 100644
--- a/.nvmrc
+++ b/.nvmrc
@@ -1 +1 @@
-v24
\ No newline at end of file
+v24
diff --git a/LICENSE b/LICENSE
index 7a4a3ea2..d6456956 100644
--- a/LICENSE
+++ b/LICENSE
@@ -199,4 +199,4 @@
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.
\ No newline at end of file
+ limitations under the License.
diff --git a/scripts/test.js b/scripts/test.js
index b47bb49a..fb5c0f2c 100644
--- a/scripts/test.js
+++ b/scripts/test.js
@@ -8,6 +8,7 @@
// Node 20 does not support --experimental-strip-types flag.
import {spawn} from 'node:child_process';
+import fs from 'node:fs';
import {glob, readFile} from 'node:fs/promises';
import os from 'node:os';
import path from 'node:path';
@@ -16,6 +17,55 @@ import {parseArgs} from 'node:util';
const callerCwd = process.cwd();
const projectRoot = path.resolve(import.meta.dirname, '..');
+const devtoolsRoot = path.resolve(projectRoot, '..');
+
+function resolveDefaultChromePath(buildDir) {
+ if (!fs.existsSync(path.join(devtoolsRoot, 'front_end'))) {
+ return undefined;
+ }
+ const platform = os.platform();
+ let cftRel;
+ if (platform === 'linux') {
+ cftRel = path.join('chrome-linux', 'chrome-linux64', 'chrome');
+ } else if (platform === 'darwin') {
+ const name = os.arch() === 'arm64' ? 'chrome-mac-arm64' : 'chrome-mac-x64';
+ cftRel = path.join(
+ name,
+ name,
+ 'Google Chrome for Testing.app',
+ 'Contents',
+ 'MacOS',
+ 'Google Chrome for Testing',
+ );
+ } else if (platform === 'win32') {
+ cftRel = path.join('chrome-win', 'chrome-win64', 'chrome.exe');
+ }
+
+ if (cftRel) {
+ const cftCandidate = path.join(
+ devtoolsRoot,
+ 'third_party',
+ 'chrome',
+ cftRel,
+ );
+ if (fs.existsSync(cftCandidate)) {
+ return cftCandidate;
+ }
+ }
+
+ const builtNames = {
+ linux: 'chrome',
+ darwin: path.join('Chromium.app', 'Contents', 'MacOS', 'Chromium'),
+ win32: 'chrome.exe',
+ };
+ if (platform in builtNames) {
+ const builtCandidate = path.join(buildDir, builtNames[platform]);
+ if (fs.existsSync(builtCandidate)) {
+ return builtCandidate;
+ }
+ }
+ return undefined;
+}
const ownOptions = {
retry: {
@@ -39,9 +89,28 @@ const {
});
const shouldRetry = values.retry;
+const defaultBuildDir = fs.existsSync(path.join(projectRoot, 'out', 'Default'))
+ ? path.join(projectRoot, 'out', 'Default')
+ : path.join(devtoolsRoot, 'out', 'Default');
const buildDir = values['build-dir']
? path.resolve(callerCwd, values['build-dir'])
- : path.join(projectRoot, 'out', 'Default');
+ : defaultBuildDir;
+
+const genCandidates = [
+ path.join(buildDir, 'gen', 'for_agents'),
+ path.join(
+ buildDir,
+ 'gen',
+ 'third_party',
+ 'devtools-frontend',
+ 'src',
+ 'for_agents',
+ ),
+ path.join(buildDir, 'gen'),
+];
+const genDir =
+ genCandidates.find(candidate => fs.existsSync(candidate)) ??
+ path.join(buildDir, 'gen');
const flags = tokens
.filter(token => token.kind === 'option' && !(token.name in ownOptions))
@@ -51,22 +120,37 @@ const flags = tokens
: token.rawName,
);
-const relGenDir = path
- .relative(projectRoot, path.join(buildDir, 'gen'))
- .replaceAll('\\', '/');
+const relGenDir = path.relative(projectRoot, genDir).replaceAll('\\', '/');
const relGenTestsDir = `${relGenDir}/tests`;
const files = [];
if (userArgs.length > 0) {
for (const arg of userArgs) {
- // Map .ts files to <buildDir>/gen/ .js files
- let testPath = arg;
+ let testPath = arg.replaceAll('\\', '/');
+ if (path.isAbsolute(arg)) {
+ const relToProject = path
+ .relative(projectRoot, arg)
+ .replaceAll('\\', '/');
+ const relToGen = path.relative(genDir, arg).replaceAll('\\', '/');
+ if (!relToGen.startsWith('..')) {
+ testPath = relToGen;
+ } else if (!relToProject.startsWith('..')) {
+ testPath = relToProject;
+ }
+ } else if (testPath.startsWith('for_agents/')) {
+ testPath = testPath.slice('for_agents/'.length);
+ }
+
if (testPath.endsWith('.ts')) {
testPath = testPath.replace(/\.ts$/, '.js');
- if (!testPath.startsWith(`${relGenDir}/`)) {
- testPath = path.posix.join(relGenDir, testPath.replaceAll('\\', '/'));
- }
+ }
+ if (testPath === 'tests' || testPath === 'tests/') {
+ files.push(`${relGenTestsDir}/**/*.test.js`);
+ continue;
+ }
+ if (!testPath.startsWith(`${relGenDir}/`)) {
+ testPath = path.posix.join(relGenDir, testPath);
}
files.push(testPath);
}
@@ -92,12 +176,14 @@ if (userArgs.length > 0) {
// Node runs `availableParallelism() - 1` test files at a time by default, so
// a 2-core CI runner runs one file at a time. Most test files wait on Chrome
-// and child processes, so a second file uses the idle CPU. On 2 cores, 2
-// files at a time cut the suite from 304 s to 222 s.
+// and child processes, so a second file uses the idle CPU. On Windows CI/LUCI
+// bots, keep concurrency at 1 to avoid browser contention.
if (!flags.some(flag => flag.startsWith('--test-concurrency'))) {
- flags.push(
- `--test-concurrency=${Math.max(2, os.availableParallelism() - 1)}`,
- );
+ const defaultConcurrency =
+ process.platform === 'win32'
+ ? 1
+ : Math.max(2, os.availableParallelism() - 1);
+ flags.push(`--test-concurrency=${defaultConcurrency}`);
}
const nodeArgs = [
@@ -105,7 +191,11 @@ const nodeArgs = [
`./${relGenTestsDir}/setup.js`,
'--no-warnings=ExperimentalWarning',
'--test-reporter',
- (process.env['NODE_TEST_REPORTER'] ?? process.env['CI']) ? 'spec' : 'dot',
+ (process.env['NODE_TEST_REPORTER'] ??
+ process.env['CI'] ??
+ process.env['LUCI_CONTEXT'])
+ ? 'spec'
+ : 'dot',
'--test-force-exit',
'--test',
'--test-timeout=120000',
@@ -113,6 +203,10 @@ const nodeArgs = [
...files,
];
+const defaultChromeExecutable =
+ process.env['PUPPETEER_EXECUTABLE_PATH'] ??
+ resolveDefaultChromePath(buildDir);
+
async function runTests(attempt) {
if (attempt > 1) {
console.log(`\nRun attempt ${attempt}...\n`);
@@ -123,10 +217,13 @@ async function runTests(attempt) {
stdio: 'inherit',
env: {
...process.env,
- CHROME_DEVTOOLS_MCP_NO_USAGE_STATISTICS: true,
- CHROME_DEVTOOLS_MCP_CRASH_ON_UNCAUGHT: true,
- CHROME_DEVTOOLS_MCP_NO_UPDATE_CHECKS: true,
- CHROME_DEVTOOLS_MCP_NO_CONFIG_DISCOVERY: true,
+ ...(defaultChromeExecutable
+ ? {PUPPETEER_EXECUTABLE_PATH: defaultChromeExecutable}
+ : {}),
+ CHROME_DEVTOOLS_MCP_NO_USAGE_STATISTICS: 'true',
+ CHROME_DEVTOOLS_MCP_CRASH_ON_UNCAUGHT: 'true',
+ CHROME_DEVTOOLS_MCP_NO_UPDATE_CHECKS: 'true',
+ CHROME_DEVTOOLS_MCP_NO_CONFIG_DISCOVERY: 'true',
...(process.env['RUNNER_DEBUG'] === '1'
? {NODE_DEBUG: 'puppeteer:*'}
: {}),
diff --git a/scripts/update-lighthouse.ts b/scripts/update-lighthouse.ts
index 5485e70c..b8e1d92c 100644
--- a/scripts/update-lighthouse.ts
+++ b/scripts/update-lighthouse.ts
@@ -48,9 +48,10 @@ function main() {
);
console.log(`Copying notices from ${noticesPath} to ${DEST_DIR}...`);
- fs.copyFileSync(
- noticesPath,
+ const noticesContent = fs.readFileSync(noticesPath, 'utf8');
+ fs.writeFileSync(
path.join(DEST_DIR, 'LIGHTHOUSE_MCP_BUNDLE_THIRD_PARTY_NOTICES'),
+ noticesContent.endsWith('\n') ? noticesContent : `${noticesContent}\n`,
);
console.log('Done.');
diff --git a/src/BUILD.gn b/src/BUILD.gn
index 8f4e99cb..df8023f3 100644
--- a/src/BUILD.gn
+++ b/src/BUILD.gn
@@ -66,7 +66,10 @@ template("third_party_bundle") {
metafile = "$target_gen_dir/$target_name.meta.json"
bundle_all = true
platform = "node"
- deps = [ ":third_party_sources" ]
+ deps = [
+ ":third_party",
+ ":third_party_sources",
+ ]
forward_variables_from(invoker,
[
"external",
diff --git a/src/third_party/LIGHTHOUSE_MCP_BUNDLE_THIRD_PARTY_NOTICES b/src/third_party/LIGHTHOUSE_MCP_BUNDLE_THIRD_PARTY_NOTICES
index 59499180..46b8d1d3 100644
--- a/src/third_party/LIGHTHOUSE_MCP_BUNDLE_THIRD_PARTY_NOTICES
+++ b/src/third_party/LIGHTHOUSE_MCP_BUNDLE_THIRD_PARTY_NOTICES
@@ -1649,4 +1649,4 @@ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
-PERFORMANCE OF THIS SOFTWARE.
\ No newline at end of file
+PERFORMANCE OF THIS SOFTWARE.
diff --git a/tests/McpContext.test.ts b/tests/McpContext.test.ts
index 2f91889d..55ad5955 100644
--- a/tests/McpContext.test.ts
+++ b/tests/McpContext.test.ts
@@ -11,7 +11,6 @@ import path from 'node:path';
import {describe, it} from 'node:test';
import {pathToFileURL} from 'node:url';
-import {Locator} from 'puppeteer';
import sinon from 'sinon';
import {UncaughtError} from '../src/collectors/PageCollector.js';
@@ -25,6 +24,7 @@ import {TextSnapshot} from '../src/TextSnapshot.js';
import {
type Browser,
type HTTPResponse,
+ Locator,
ScreenRecorder,
type Target,
TargetType,
@@ -60,13 +60,11 @@ import {
stabilizeStructuredContent,
} from './utils.js';
-const EXTENSION_WITH_SW_PATH = path.join(
- import.meta.dirname,
- '../../../../tests/tools/fixtures/extension-sw',
+const EXTENSION_WITH_SW_PATH = path.resolve(
+ 'tests/tools/fixtures/extension-sw',
);
-const EXTENSION_CONTENT_SCRIPT_PATH = path.join(
- import.meta.dirname,
- '../../../../tests/tools/fixtures/extension-content-script',
+const EXTENSION_CONTENT_SCRIPT_PATH = path.resolve(
+ 'tests/tools/fixtures/extension-content-script',
);
describe('McpContext', () => {
diff --git a/tests/browser.test.ts b/tests/browser.test.ts
index 856159d2..8cb0f709 100644
--- a/tests/browser.test.ts
+++ b/tests/browser.test.ts
@@ -9,7 +9,6 @@ import os from 'node:os';
import path from 'node:path';
import {describe, it} from 'node:test';
-import {executablePath} from 'puppeteer';
import sinon from 'sinon';
import {BrowserManager} from '../src/BrowserManager.js';
@@ -21,6 +20,7 @@ import {
createMockServerConfig,
} from './mocks.js';
import {serverHooks} from './server.js';
+import {getExecutablePath} from './utils.js';
async function safeClose(browser: Browser) {
try {
@@ -802,7 +802,7 @@ describe('browser', () => {
headless: true,
isolated: false,
userDataDir: folderPath,
- executablePath: await executablePath(),
+ executablePath: await getExecutablePath(),
}),
);
const browser1 = await manager1.ensureBrowser();
@@ -813,7 +813,7 @@ describe('browser', () => {
headless: true,
isolated: false,
userDataDir: folderPath,
- executablePath: await executablePath(),
+ executablePath: await getExecutablePath(),
}),
);
const browser2 = await manager2.ensureBrowser();
@@ -844,7 +844,7 @@ describe('browser', () => {
headless: true,
isolated: false,
userDataDir: folderPath,
- executablePath: await executablePath(),
+ executablePath: await getExecutablePath(),
viewport: {
width: 1501,
height: 801,
@@ -879,7 +879,7 @@ describe('browser', () => {
headless: true,
isolated: false,
userDataDir: folderPath,
- executablePath: await executablePath(),
+ executablePath: await getExecutablePath(),
chromeArg: ['--remote-debugging-port=0'],
}),
);
@@ -919,7 +919,7 @@ describe('browser', () => {
createMockServerConfig({
headless: true,
isolated: true,
- executablePath: await executablePath(),
+ executablePath: await getExecutablePath(),
blockedUrlPattern: ['*://*:*/blocked.html'],
}),
);
@@ -964,7 +964,7 @@ describe('browser', () => {
createMockServerConfig({
headless: true,
isolated: true,
- executablePath: await executablePath(),
+ executablePath: await getExecutablePath(),
allowedUrlPattern: ['*://*:*/allowed.html'],
}),
);
diff --git a/tests/e2e/chrome-devtools-commands.test.ts b/tests/e2e/chrome-devtools-commands.test.ts
index f3f1fbce..7714cdcf 100644
--- a/tests/e2e/chrome-devtools-commands.test.ts
+++ b/tests/e2e/chrome-devtools-commands.test.ts
@@ -15,6 +15,7 @@ import {
createCliSession,
createTempDir,
runCli,
+ startCli,
stopDaemonForCleanup,
} from '../utils.js';
@@ -22,7 +23,7 @@ import {
describe('chrome-devtools', {concurrency: true}, () => {
it('can invoke list_pages', async t => {
const sessionId = createCliSession(t);
- const startResult = await runCli(['start'], sessionId);
+ const startResult = await startCli(sessionId);
assert.strictEqual(
startResult.status,
0,
@@ -45,7 +46,7 @@ describe('chrome-devtools', {concurrency: true}, () => {
it('can take screenshot', async t => {
const sessionId = createCliSession(t);
- const startResult = await runCli(['start'], sessionId);
+ const startResult = await startCli(sessionId);
assert.strictEqual(
startResult.status,
0,
@@ -80,7 +81,7 @@ describe('chrome-devtools', {concurrency: true}, () => {
'utf8',
);
try {
- const startResult = await runCli(['start'], sessionId, {
+ const startResult = await startCli(sessionId, [], {
cwd: daemonDirectory,
});
assert.strictEqual(
diff --git a/tests/e2e/chrome-devtools-disabled-tools.test.ts b/tests/e2e/chrome-devtools-disabled-tools.test.ts
index 3fc2e5d2..1ac01f4f 100644
--- a/tests/e2e/chrome-devtools-disabled-tools.test.ts
+++ b/tests/e2e/chrome-devtools-disabled-tools.test.ts
@@ -7,13 +7,13 @@
import assert from 'node:assert';
import {describe, it} from 'node:test';
-import {createCliSession, runCli} from '../utils.js';
+import {createCliSession, runCli, startCli} from '../utils.js';
// Each test uses its own daemon session, so the tests run in parallel.
describe('chrome-devtools', {concurrency: true}, () => {
it('fails to invoke list_network_requests when categoryNetwork is disabled', async t => {
const sessionId = createCliSession(t);
- await runCli(['start', '--categoryNetwork=false'], sessionId);
+ await startCli(sessionId, ['--categoryNetwork=false']);
const result = await runCli(['list_network_requests', '1'], sessionId);
assert.strictEqual(result.status, 0);
@@ -32,7 +32,7 @@ describe('chrome-devtools', {concurrency: true}, () => {
it('fails to invoke click_at when experimentalVision is disabled (default)', async t => {
const sessionId = createCliSession(t);
- await runCli(['start'], sessionId);
+ await startCli(sessionId);
const result = await runCli(['click_at', '1', '100', '100'], sessionId);
assert.strictEqual(result.status, 0);
@@ -50,7 +50,7 @@ describe('chrome-devtools', {concurrency: true}, () => {
it('fails to invoke evaluate_script when javascriptEvaluation is disabled', async t => {
const sessionId = createCliSession(t);
- await runCli(['start', '--no-javascript-evaluation'], sessionId);
+ await startCli(sessionId, ['--no-javascript-evaluation']);
// The three commands do not change daemon state, so they run in
// parallel.
diff --git a/tests/e2e/chrome-devtools-hyphen-positionals.test.ts b/tests/e2e/chrome-devtools-hyphen-positionals.test.ts
index 99fbae9b..8a07ecab 100644
--- a/tests/e2e/chrome-devtools-hyphen-positionals.test.ts
+++ b/tests/e2e/chrome-devtools-hyphen-positionals.test.ts
@@ -8,7 +8,7 @@ import assert from 'node:assert';
import crypto from 'node:crypto';
import {describe, it, after, before} from 'node:test';
-import {runCli, stopDaemonForCleanup} from '../utils.js';
+import {runCli, startCli, stopDaemonForCleanup} from '../utils.js';
describe('chrome-devtools positional values starting with a hyphen', () => {
const fillCases: Array<{value: string[]; expected: string}> = [
@@ -30,7 +30,7 @@ describe('chrome-devtools positional values starting with a hyphen', () => {
before(async () => {
sessionId = crypto.randomUUID();
- const startResult = await runCli(['start'], sessionId);
+ const startResult = await startCli(sessionId);
assert.strictEqual(
startResult.status,
0,
diff --git a/tests/e2e/chrome-devtools-performance.test.ts b/tests/e2e/chrome-devtools-performance.test.ts
index a239b1bd..4164cdd8 100644
--- a/tests/e2e/chrome-devtools-performance.test.ts
+++ b/tests/e2e/chrome-devtools-performance.test.ts
@@ -8,7 +8,7 @@ import assert from 'node:assert';
import crypto from 'node:crypto';
import {describe, it, afterEach, beforeEach} from 'node:test';
-import {runCli, stopDaemonForCleanup} from '../utils.js';
+import {runCli, startCli, stopDaemonForCleanup} from '../utils.js';
describe('chrome-devtools', () => {
let sessionId: string;
@@ -22,10 +22,7 @@ describe('chrome-devtools', () => {
});
it('can record a performance trace', async () => {
- const startResult = await runCli(
- ['start', '--performanceCrux=false'],
- sessionId,
- );
+ const startResult = await startCli(sessionId, ['--performanceCrux=false']);
assert.strictEqual(
startResult.status,
0,
diff --git a/tests/index.test.ts b/tests/index.test.ts
index 93013afc..7a200a04 100644
--- a/tests/index.test.ts
+++ b/tests/index.test.ts
@@ -10,13 +10,11 @@ import path from 'node:path';
import {describe, it} from 'node:test';
import {pathToFileURL} from 'node:url';
-import {executablePath} from 'puppeteer';
-
import {Client, type ClientCapabilities} from '@modelcontextprotocol/client';
import {StdioClientTransport} from '@modelcontextprotocol/client/stdio';
import type {TextContent} from '../src/third_party/index.js';
-import {createTempDir} from './utils.js';
+import {createTempDir, getExecutablePath} from './utils.js';
// Each test starts its own server process, so the tests run in parallel. Most
// of the test time is server start and waits, not CPU work.
@@ -41,7 +39,7 @@ describe('e2e', {concurrency: true}, () => {
'--headless',
'--isolated',
'--executable-path',
- await executablePath(),
+ await getExecutablePath(),
...extraArgs,
],
env: {...process.env, CHROME_DEVTOOLS_MCP_NO_USAGE_STATISTICS: 'true'},
diff --git a/tests/shutdown.test.ts b/tests/shutdown.test.ts
index ee48dcc3..aa39f919 100644
--- a/tests/shutdown.test.ts
+++ b/tests/shutdown.test.ts
@@ -10,7 +10,7 @@ import path from 'node:path';
import type {Readable, Writable} from 'node:stream';
import {describe, it} from 'node:test';
-import {executablePath} from 'puppeteer';
+import {getExecutablePath} from './utils.js';
type Server = ChildProcessByStdio<Writable, Readable, Readable>;
@@ -30,7 +30,7 @@ async function spawnServer(): Promise<Server> {
'--headless',
'--isolated',
'--executable-path',
- await executablePath(),
+ await getExecutablePath(),
],
{
env: {
diff --git a/tests/third_party_notices.test.js.snapshot b/tests/third_party_notices.test.js.snapshot
index 2532e2ed..29756e8d 100644
--- a/tests/third_party_notices.test.js.snapshot
+++ b/tests/third_party_notices.test.js.snapshot
@@ -3773,4 +3773,5 @@ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
+
`;
diff --git a/tests/tools/console.test.ts b/tests/tools/console.test.ts
index f5881264..dbeaee04 100644
--- a/tests/tools/console.test.ts
+++ b/tests/tools/console.test.ts
@@ -32,9 +32,8 @@ import {
stabilizeResponseOutput,
} from '../utils.js';
-const EXTENSION_LOGGING_PATH = path.join(
- import.meta.dirname,
- '../../../../../tests/tools/fixtures/extension-logging',
+const EXTENSION_LOGGING_PATH = path.resolve(
+ 'tests/tools/fixtures/extension-logging',
);
describe('console', () => {
diff --git a/tests/tools/pages.test.ts b/tests/tools/pages.test.ts
index 8ba2b98e..4366a1ef 100644
--- a/tests/tools/pages.test.ts
+++ b/tests/tools/pages.test.ts
@@ -30,17 +30,10 @@ import {
} from '../mocks.js';
import {assertNoServiceWorkerReported, html, withMcpContext} from '../utils.js';
-const EXTENSION_SW_PATH = path.join(
- import.meta.dirname,
- '../../../../../tests/tools/fixtures/extension-sw',
-);
-const EXTENSION_PATH = path.join(
- import.meta.dirname,
- '../../../../../tests/tools/fixtures/extension',
-);
-const EXTENSION_SIDE_PANEL_PATH = path.join(
- import.meta.dirname,
- '../../../../../tests/tools/fixtures/extension-side-panel',
+const EXTENSION_SW_PATH = path.resolve('tests/tools/fixtures/extension-sw');
+const EXTENSION_PATH = path.resolve('tests/tools/fixtures/extension');
+const EXTENSION_SIDE_PANEL_PATH = path.resolve(
+ 'tests/tools/fixtures/extension-side-panel',
);
describe('pages', () => {
diff --git a/tests/tools/script.test.ts b/tests/tools/script.test.ts
index ab0694f7..31d4e0a6 100644
--- a/tests/tools/script.test.ts
+++ b/tests/tools/script.test.ts
@@ -28,10 +28,7 @@ import {
withMcpContext,
} from '../utils.js';
-const EXTENSION_PATH = path.join(
- import.meta.dirname,
- '../../../../../tests/tools/fixtures/extension-sw',
-);
+const EXTENSION_PATH = path.resolve('tests/tools/fixtures/extension-sw');
describe('script', () => {
const server = serverHooks();
diff --git a/tests/trace-processing/fixtures/load.ts b/tests/trace-processing/fixtures/load.ts
index 22bafa04..d235d84c 100644
--- a/tests/trace-processing/fixtures/load.ts
+++ b/tests/trace-processing/fixtures/load.ts
@@ -17,20 +17,7 @@ import zlib from 'node:zlib';
export function loadTraceAsBuffer(filePath: string): Uint8Array {
try {
const compressedData = fs.readFileSync(
- path.join(
- import.meta.dirname,
- // Get back up to the root directory as fixtures aren't moved into the out/Default/gen/ dir.
- '..',
- '..',
- '..',
- '..',
- '..',
- '..',
- 'tests',
- 'trace-processing',
- 'fixtures',
- filePath,
- ),
+ path.resolve('tests', 'trace-processing', 'fixtures', filePath),
);
const decompressedData = zlib.gunzipSync(compressedData);
const jsonString = decompressedData.toString('utf-8');
diff --git a/tests/utils.ts b/tests/utils.ts
index 5a0ab2d6..a016e81e 100644
--- a/tests/utils.ts
+++ b/tests/utils.ts
@@ -15,7 +15,7 @@ import path from 'node:path';
import type {TestContext} from 'node:test';
import type {Browser} from 'puppeteer';
-import puppeteer, {Locator} from 'puppeteer';
+import puppeteer, {executablePath, Locator} from 'puppeteer';
import type {
Frame,
@@ -458,6 +458,10 @@ export function getMockBrowser(options?: {
return browser;
}
+export async function getExecutablePath(): Promise<string> {
+ return process.env['PUPPETEER_EXECUTABLE_PATH'] ?? (await executablePath());
+}
+
export const CLI_PATH: string = path.resolve(
import.meta.dirname,
'../src/bin/chrome-devtools.js',
@@ -493,6 +497,20 @@ export async function runCli(
});
}
+/**
+ * Runs `chrome-devtools start` for tests that use the browser. Passes
+ * `PUPPETEER_EXECUTABLE_PATH` as `--executablePath` when it is set.
+ */
+export async function startCli(
+ sessionId: string,
+ args: string[] = [],
+ options?: {cwd?: string},
+): Promise<{status: number | null; stdout: string; stderr: string}> {
+ const chromePath = process.env['PUPPETEER_EXECUTABLE_PATH'];
+ const pathArgs = chromePath ? [`--executablePath=${chromePath}`] : [];
+ return await runCli(['start', ...args, ...pathArgs], sessionId, options);
+}
+
export async function assertDaemonIsNotRunning(
sessionId?: string,
): Promise<void> {