Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

chore: use rootPath instead of cwd when resolving seedFile (#37603)

Dmitry Gozman6e88894622cc
diff --git a/packages/playwright/src/mcp/test/testTools.ts b/packages/playwright/src/mcp/test/testTools.ts
index e22a2f9e2b..747c49f4c2 100644
--- a/packages/playwright/src/mcp/test/testTools.ts
+++ b/packages/playwright/src/mcp/test/testTools.ts
@@ -147,7 +147,7 @@ test.describe('Test group', () => {
const candidateFiles: string[] = [];
candidateFiles.push(path.resolve(testDir, params.seedFile));
candidateFiles.push(path.resolve(configDir, params.seedFile));
- candidateFiles.push(path.resolve(process.cwd(), params.seedFile));
+ candidateFiles.push(path.resolve(context.rootPath, params.seedFile));
for (const candidateFile of candidateFiles) {
if (await fileExistsAsync(candidateFile)) {
seedFile = candidateFile;
diff --git a/tests/mcp/test-setup-page.spec.ts b/tests/mcp/test-setup-page.spec.ts
index 19afd4340d..6afcd9f5dd 100644
--- a/tests/mcp/test-setup-page.spec.ts
+++ b/tests/mcp/test-setup-page.spec.ts
@@ -18,6 +18,7 @@ import { test, expect, writeFiles } from './fixtures';
import fs from 'fs';
import path from 'path';
+import url from 'url';
test.use({ mcpServerType: 'test-mcp' });
@@ -99,14 +100,14 @@ test('test_setup_page seed resolution', async ({ startClient }) => {
})).toHaveTextResponse(expect.stringContaining(`### Paused at end of test.`));
});
-test('test_setup_page seed resolution - cwd', async ({ startClient }) => {
+test('test_setup_page seed resolution - rootPath', async ({ startClient }) => {
await writeFiles({
- 'configs/playwright.config.ts': `
+ 'packages/my-app/configs/playwright.config.ts': `
module.exports = {
testDir: '../tests',
};
`,
- 'tests/seed.test.ts': `
+ 'packages/my-app/tests/seed.test.ts': `
import { test, expect } from '@playwright/test';
test('template', async ({ page }) => {
await page.setContent('<button>Submit</button>');
@@ -115,13 +116,14 @@ test('test_setup_page seed resolution - cwd', async ({ startClient }) => {
});
const { client } = await startClient({
- args: ['--config=configs/playwright.config.ts'],
+ args: ['--config=packages/my-app/configs/playwright.config.ts'],
+ roots: [{ name: 'root', uri: url.pathToFileURL(test.info().outputPath('')).toString() }],
});
expect(await client.callTool({
name: 'test_setup_page',
arguments: {
- seedFile: 'tests/seed.test.ts',
+ seedFile: 'packages/my-app/tests/seed.test.ts',
},
})).toHaveTextResponse(expect.stringContaining(`### Paused at end of test.`));
});