Skip to content

Commit 31f2a8b

Browse files
Integration tests for command line arguments
Use different server startup commands in Playwright to allow tests that command line arguments initialize form inputs as intended. A full integration test is used because the Inspector comprises multiple components (package bin entry point, start command, webClient, server), making benefit to test-effort higher, and less dependent on implementation details. The webServer start command uses the package entry point to ensure tests follow the exact user experience provided by: `npx @m/inspector [...]` Playwright's `webServer.command` cannot be [re]configured after it has started, so multiple Playwright invocations are necessary. To do this, use an environment variable and a command-generating function (instead of multiple config files). Test tagging (`@cli`) is used to select which tests execute, while keeping the entire test suite together. Future: Playwright has a feature under consideration to permit a web server per project, which might simplify the config: microsoft/playwright#22496
1 parent 700464e commit 31f2a8b

File tree

7 files changed

+74
-6
lines changed

7 files changed

+74
-6
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ sdk
1414
client/playwright-report/
1515
client/results.json
1616
client/test-results/
17+
client/e2e/test-results/
1718
mcp.json

client/e2e/cli-arguments.spec.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { test, expect } from "@playwright/test";
22

3+
// Adjust the URL if your dev server runs on a different port
4+
const APP_URL = "http://localhost:6274/?MCP_PROXY_AUTH_TOKEN=abc123";
5+
36
// These tests verify that CLI arguments correctly set URL parameters
47
// The CLI should parse config files and pass transport/serverUrl as URL params
58
test.describe("CLI Arguments @cli", () => {
@@ -63,3 +66,28 @@ test.describe("CLI Arguments @cli", () => {
6366
await expect(page.locator("#arguments-input")).toBeVisible();
6467
});
6568
});
69+
70+
test.describe("CLI npx (npm exec) start up", { tag: "@cli" }, () => {
71+
test("CLI arguments should populate form fields", async ({ page }) => {
72+
const cliTestScenario = process.env.CLI_TEST_SCENARIO;
73+
74+
// Skip this test if not running a CLI test scenario
75+
if (
76+
!cliTestScenario ||
77+
(cliTestScenario !== "inline" && cliTestScenario !== "file")
78+
) {
79+
test.skip();
80+
return;
81+
}
82+
83+
await page.goto(APP_URL);
84+
85+
const commandInput = page.getByRole("textbox", { name: "Command" });
86+
const argsInput = page.getByRole("textbox", { name: "Arguments" });
87+
88+
await expect(commandInput).toHaveValue("npm");
89+
await expect(argsInput).toHaveValue(
90+
"--silent --prefix /path/to/mcp/servers/src/everything run start",
91+
);
92+
});
93+
});
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"mcpServers": {
3+
"everything": {
4+
"command": "npm",
5+
"args": [
6+
"--silent",
7+
"--prefix",
8+
"/path/to/mcp/servers/src/everything",
9+
"run",
10+
"start"
11+
],
12+
"env": {
13+
"FOO": "bar",
14+
"BAZ": "bat"
15+
}
16+
}
17+
}
18+
}

client/e2e/startup-state.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { test, expect } from "@playwright/test";
22

33
// Adjust the URL if your dev server runs on a different port
4-
const APP_URL = "http://localhost:6274/";
4+
const APP_URL = "http://localhost:6274/?MCP_PROXY_AUTH_TOKEN=abc123";
55

66
test.describe("Startup State", () => {
77
test("should not navigate to a tab when Inspector first opens", async ({

client/e2e/transport-type-dropdown.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { test, expect } from "@playwright/test";
22

33
// Adjust the URL if your dev server runs on a different port
4-
const APP_URL = "http://localhost:6274/";
4+
const APP_URL = "http://localhost:6274/?MCP_PROXY_AUTH_TOKEN=abc123";
55

66
test.describe("Transport Type Dropdown", () => {
77
test("should have options for STDIO, SSE, and Streamable HTTP", async ({

client/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
"preview": "vite preview --port 6274",
2222
"test": "jest --config jest.config.cjs",
2323
"test:watch": "jest --config jest.config.cjs --watch",
24-
"test:e2e": "playwright test e2e && npm run cleanup:e2e",
24+
"test:e2e": "playwright test --grep-invert @cli e2e && npm run test:e2e:cli-file && npm run test:e2e:cli-inline && npm run cleanup:e2e",
25+
"test:e2e:cli-file": "CLI_TEST_SCENARIO=file playwright test --grep @cli e2e",
26+
"test:e2e:cli-inline": "CLI_TEST_SCENARIO=inline playwright test --grep @cli e2e",
2527
"cleanup:e2e": "node e2e/global-teardown.js"
2628
},
2729
"dependencies": {

client/playwright.config.ts

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,33 @@
11
import { defineConfig, devices } from "@playwright/test";
22

3+
const getWebServerCommand = () => {
4+
/**
5+
* The content of the fixture configuration file matches the inline arguments such
6+
* that the same set of tests (tagged `@cli`) can run in both scenarios.
7+
*/
8+
switch (process.env.CLI_TEST_SCENARIO) {
9+
case "inline":
10+
return "npx . -e FOO=bar -e BAZ=bat npm --silent --prefix /path/to/mcp/servers/src/everything run start";
11+
case "file":
12+
return "npx . --config client/e2e/fixtures/everything-server.json --server everything";
13+
default:
14+
return "npm run dev";
15+
}
16+
};
17+
318
/**
419
* @see https://playwright.dev/docs/test-configuration
520
*/
621
export default defineConfig({
722
/* Run your local dev server before starting the tests */
823
webServer: {
924
cwd: "..",
10-
command: "npm run dev",
11-
url: "http://localhost:6274",
25+
command: getWebServerCommand(),
26+
url: "http://localhost:6274/?MCP_PROXY_AUTH_TOKEN=abc123",
1227
reuseExistingServer: !process.env.CI,
1328
env: {
1429
MCP_AUTO_OPEN_ENABLED: "false",
30+
MCP_PROXY_AUTH_TOKEN: "abc123",
1531
},
1632
},
1733

@@ -36,7 +52,7 @@ export default defineConfig({
3652
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
3753
use: {
3854
/* Base URL to use in actions like `await page.goto('/')`. */
39-
baseURL: "http://localhost:6274",
55+
baseURL: "http://localhost:6274/?MCP_PROXY_AUTH_TOKEN=abc123",
4056

4157
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
4258
trace: "on-first-retry",
@@ -46,6 +62,9 @@ export default defineConfig({
4662

4763
/* Record video on failure */
4864
video: "retain-on-failure",
65+
66+
/* Useful for local debugging */
67+
// headless: false,
4968
},
5069

5170
/* Configure projects for major browsers */

0 commit comments

Comments
 (0)