@testspectra/cli 1.1.8-rc.3 → 1.1.8-rc.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +50 -0
- package/bin/spectra.js +0 -0
- package/dist/.tsbuildinfo +1 -1
- package/dist/commands/__tests__/doctor-filter.test.d.ts +1 -0
- package/dist/commands/__tests__/doctor-filter.test.js +37 -0
- package/dist/commands/__tests__/run-e2e.test.js +49 -49
- package/dist/commands/__tests__/test-error-streaming.test.d.ts +1 -0
- package/dist/commands/__tests__/test-error-streaming.test.js +85 -0
- package/dist/commands/__tests__/test-scaffolding.test.d.ts +1 -0
- package/dist/commands/__tests__/test-scaffolding.test.js +32 -0
- package/dist/commands/__tests__/upgrade.test.d.ts +1 -0
- package/dist/commands/__tests__/upgrade.test.js +95 -0
- package/dist/commands/add.js +5 -4
- package/dist/commands/devices.js +1 -0
- package/dist/commands/docs.d.ts +4 -0
- package/dist/commands/docs.js +17 -0
- package/dist/commands/doctor.d.ts +9 -1
- package/dist/commands/doctor.js +17 -3
- package/dist/commands/init.js +7 -160
- package/dist/commands/install.js +5 -0
- package/dist/commands/license.js +1 -0
- package/dist/commands/run.d.ts +2 -0
- package/dist/commands/run.js +22 -0
- package/dist/commands/test.d.ts +13 -0
- package/dist/commands/test.js +115 -21
- package/dist/commands/upgrade.d.ts +12 -0
- package/dist/commands/upgrade.js +197 -0
- package/dist/config/schema.d.ts +53 -0
- package/dist/config/schema.js +2 -0
- package/dist/generator/__tests__/tsconfig-isolation.test.js +2 -1
- package/dist/generator/__tests__/type-generator.test.js +38 -0
- package/dist/generator/architecture-doc-generator.d.ts +14 -0
- package/dist/generator/architecture-doc-generator.js +80 -0
- package/dist/generator/index.d.ts +1 -0
- package/dist/generator/index.js +1 -0
- package/dist/generator/tsconfig-generator.js +1 -1
- package/dist/generator/type-generator.d.ts +5 -2
- package/dist/generator/type-generator.js +14 -17
- package/dist/index.js +56 -26
- package/dist/linter/__tests__/component-test-imports.test.js +51 -51
- package/dist/linter/__tests__/shared-lib-boundary.test.js +15 -15
- package/dist/linter/__tests__/spec-schema.test.js +167 -167
- package/dist/linter/discovery.d.ts +3 -3
- package/dist/linter/discovery.js +7 -7
- package/dist/linter/schemas/spec.schema.d.ts +8 -8
- package/dist/linter/schemas/suite.schema.d.ts +4 -4
- package/dist/runner/bridge.d.ts +1 -1
- package/dist/runner/bridge.js +101 -11
- package/dist/runner/reporter.d.ts +1 -0
- package/dist/runner/reporter.js +12 -6
- package/dist/utils/__tests__/dev-server-manager.test.d.ts +1 -0
- package/dist/utils/__tests__/dev-server-manager.test.js +72 -0
- package/dist/utils/background-update-check.d.ts +1 -0
- package/dist/utils/background-update-check.js +43 -0
- package/dist/utils/dependency-updates.d.ts +15 -0
- package/dist/utils/dependency-updates.js +107 -0
- package/dist/utils/dev-server-manager.d.ts +40 -0
- package/dist/utils/dev-server-manager.js +257 -0
- package/dist/utils/update-notifier.d.ts +2 -0
- package/dist/utils/update-notifier.js +67 -0
- package/package.json +36 -30
- package/templates/default/CLAUDE.md +16 -16
- package/templates/default/global-hooks/after/mobile.hook.ts +3 -3
- package/templates/default/global-hooks/after/web.hook.ts +3 -3
- package/templates/default/global-hooks/before/mobile.hook.ts +3 -3
- package/templates/default/global-hooks/before/web.hook.ts +3 -3
- package/templates/default/package.json +2 -2
- package/templates/default/page-objects/AuthPage/mobile.ts +5 -5
- package/templates/default/page-objects/AuthPage/web.ts +10 -10
- package/templates/default/page-objects/MatchersPage/mobile.ts +70 -70
- package/templates/default/page-objects/MatchersPage/web.ts +43 -43
- package/templates/default/page-objects/NavigationPage/mobile.ts +14 -14
- package/templates/default/page-objects/NavigationPage/web.ts +8 -8
- package/templates/default/page-objects/PlaygroundPage/mobile.ts +42 -42
- package/templates/default/page-objects/PlaygroundPage/web.ts +31 -31
- package/templates/default/specs/ApiInterception/TC-0008-fetch-mocking/mobile.test.ts +53 -53
- package/templates/default/specs/ApiInterception/TC-0008-fetch-mocking/spec.md +19 -19
- package/templates/default/specs/ApiInterception/TC-0008-fetch-mocking/web.test.ts +31 -31
- package/templates/default/specs/ApiInterception/TC-0009-post-mocking/android.test.ts +3 -3
- package/templates/default/specs/ApiInterception/TC-0009-post-mocking/common.test.ts +3 -3
- package/templates/default/specs/ApiInterception/TC-0009-post-mocking/mobile.test.ts +27 -27
- package/templates/default/specs/ApiInterception/TC-0009-post-mocking/spec.md +19 -19
- package/templates/default/specs/ApiInterception/TC-0009-post-mocking/web.test.ts +26 -26
- package/templates/default/specs/ApiInterception/TC-0012-direct-and-late-response/common.test.ts +30 -30
- package/templates/default/specs/ApiInterception/TC-0012-direct-and-late-response/spec.md +22 -22
- package/templates/default/specs/ApiInterception/TC-0013-real-network-call-recorded/common.test.ts +27 -27
- package/templates/default/specs/ApiInterception/TC-0013-real-network-call-recorded/spec.md +20 -20
- package/templates/default/specs/ApiInterception/TC-0015-mock-server-sent-events/spec.md +24 -24
- package/templates/default/specs/ApiInterception/TC-0015-mock-server-sent-events/web.test.ts +26 -26
- package/templates/default/specs/ApiInterception/TC-0016-bypass-websocket-with-app-level-mock/spec.md +37 -37
- package/templates/default/specs/ApiInterception/TC-0016-bypass-websocket-with-app-level-mock/web.test.ts +21 -21
- package/templates/default/specs/ApiInterception/TC-0017-bypass-captcha-with-test-mode-flag/spec.md +29 -29
- package/templates/default/specs/ApiInterception/TC-0017-bypass-captcha-with-test-mode-flag/web.test.ts +16 -16
- package/templates/default/specs/ApiInterception/suite.md +10 -10
- package/templates/default/specs/ApiSeeding/TC-0014-seed-and-cleanup-via-hooks/common.test.ts +30 -30
- package/templates/default/specs/ApiSeeding/TC-0014-seed-and-cleanup-via-hooks/spec.md +23 -23
- package/templates/default/specs/ApiSeeding/hooks/after/common.hook.ts +16 -16
- package/templates/default/specs/ApiSeeding/hooks/before/common.hook.ts +28 -28
- package/templates/default/specs/ApiSeeding/suite.md +9 -9
- package/templates/default/specs/Authentication/TC-0021-seed-authenticated-session/mobile.test.ts +7 -7
- package/templates/default/specs/Authentication/TC-0021-seed-authenticated-session/spec.md +19 -19
- package/templates/default/specs/Authentication/TC-0021-seed-authenticated-session/web.test.ts +9 -9
- package/templates/default/specs/Authentication/suite.md +9 -9
- package/templates/default/specs/BrowserContext/TC-0007-title-and-navigation/mobile.test.ts +9 -9
- package/templates/default/specs/BrowserContext/TC-0007-title-and-navigation/spec.md +17 -17
- package/templates/default/specs/BrowserContext/TC-0007-title-and-navigation/web.test.ts +19 -19
- package/templates/default/specs/BrowserContext/TC-0022-history-navigation/mobile.test.ts +17 -17
- package/templates/default/specs/BrowserContext/TC-0022-history-navigation/spec.md +28 -28
- package/templates/default/specs/BrowserContext/TC-0022-history-navigation/web.test.ts +26 -26
- package/templates/default/specs/ContentMatchers/TC-0005-text-and-values/common.test.ts +26 -26
- package/templates/default/specs/ContentMatchers/TC-0005-text-and-values/spec.md +19 -19
- package/templates/default/specs/ContentMatchers/TC-0006-collections-and-empty/mobile.test.ts +11 -11
- package/templates/default/specs/ContentMatchers/TC-0006-collections-and-empty/spec.md +17 -17
- package/templates/default/specs/ContentMatchers/TC-0006-collections-and-empty/web.test.ts +11 -11
- package/templates/default/specs/ContentMatchers/TC-0020-scoped-element-access/common.test.ts +14 -14
- package/templates/default/specs/ContentMatchers/TC-0020-scoped-element-access/spec.md +21 -21
- package/templates/default/specs/DeepLink/TC-0018-navigate-via-deep-link/mobile.test.ts +28 -28
- package/templates/default/specs/DeepLink/TC-0018-navigate-via-deep-link/spec.md +29 -29
- package/templates/default/specs/DeepLink/suite.md +9 -9
- package/templates/default/specs/ElementMatchers/TC-0003-visibility-and-dom/mobile.test.ts +11 -11
- package/templates/default/specs/ElementMatchers/TC-0003-visibility-and-dom/spec.md +17 -17
- package/templates/default/specs/ElementMatchers/TC-0003-visibility-and-dom/web.test.ts +11 -11
- package/templates/default/specs/ElementMatchers/TC-0004-states-and-attributes/mobile.test.ts +29 -29
- package/templates/default/specs/ElementMatchers/TC-0004-states-and-attributes/spec.md +19 -19
- package/templates/default/specs/ElementMatchers/TC-0004-states-and-attributes/web.test.ts +29 -29
- package/templates/default/specs/ElementMatchers/suite.md +10 -10
- package/templates/default/specs/EnvironmentConfig/TC-0019-read-custom-environment-variable/common.test.ts +5 -5
- package/templates/default/specs/EnvironmentConfig/TC-0019-read-custom-environment-variable/spec.md +16 -16
- package/templates/default/specs/EnvironmentConfig/suite.md +9 -9
- package/templates/default/specs/PermissionRationale/TC-0010-camera-permission-allow/mobile.test.ts +26 -26
- package/templates/default/specs/PermissionRationale/TC-0010-camera-permission-allow/spec.md +22 -22
- package/templates/default/specs/PermissionRationale/TC-0011-camera-permission-deny/mobile.test.ts +13 -13
- package/templates/default/specs/PermissionRationale/TC-0011-camera-permission-deny/spec.md +20 -20
- package/templates/default/specs/PermissionRationale/suite.md +9 -9
- package/templates/default/specs/Playground/TC-0001-form-controls/mobile.test.ts +6 -6
- package/templates/default/specs/Playground/TC-0001-form-controls/spec.md +18 -18
- package/templates/default/specs/Playground/TC-0001-form-controls/web.test.ts +6 -6
- package/templates/default/specs/Playground/TC-0002-toggle-elements/mobile.test.ts +6 -6
- package/templates/default/specs/Playground/TC-0002-toggle-elements/spec.md +18 -18
- package/templates/default/specs/Playground/TC-0002-toggle-elements/web.test.ts +6 -6
- package/templates/default/spectra.config.ts +52 -52
- package/templates/default/support/actions/fillCredentials/mobile.action.ts +4 -4
- package/templates/default/support/actions/fillCredentials/web.action.ts +4 -4
- package/templates/default/support/actions/seedSession/mobile.action.ts +9 -9
- package/templates/default/support/actions/seedSession/web.action.ts +13 -13
- package/templates/default/support/steps/togglePlaygroundStates/mobile.step.ts +5 -5
- package/templates/default/support/steps/togglePlaygroundStates/web.step.ts +5 -5
- package/templates/default/support/steps/verifyPlaygroundState/mobile.step.ts +6 -6
- package/templates/default/support/steps/verifyPlaygroundState/web.step.ts +6 -6
- package/templates/docs/ARCHITECTURE.default.md +26 -0
- package/templates/docs/ARCHITECTURE.nx.md +119 -0
- package/templates/nx/.nx/workspace-data/{59842386-c7c4-44ca-b2c2-20e1700bd13d.db-shm → 70094CFD-E89B-57A1-9619-2FC5F4963C54.db-shm} +0 -0
- package/templates/nx/.nx/workspace-data/70094CFD-E89B-57A1-9619-2FC5F4963C54.db-wal +0 -0
- package/templates/nx/.nx/workspace-data/d/daemon.log +6343 -1612
- package/templates/nx/.nx/workspace-data/d/server-process.json +1 -1
- package/templates/nx/.nx/workspace-data/file-map.json +116 -130
- package/templates/nx/.nx/workspace-data/lockfile.hash +1 -1
- package/templates/nx/.nx/workspace-data/nx_files.nxt +0 -0
- package/templates/nx/.nx/workspace-data/parsed-lock-file.json +504 -504
- package/templates/nx/.nx/workspace-data/project-graph.json +560 -559
- package/templates/nx/.nx/workspace-data/source-maps.json +336 -0
- package/templates/nx/CLAUDE.md +10 -10
- package/templates/nx/package.json +3 -3
- package/templates/nx/packages/matchers/e2e/project.json +2 -2
- package/templates/nx/packages/matchers/e2e/specs/ApiInterception/TC-0008-fetch-mocking/mobile.test.ts +27 -27
- package/templates/nx/packages/matchers/e2e/specs/ApiInterception/TC-0008-fetch-mocking/web.test.ts +27 -27
- package/templates/nx/packages/matchers/e2e/specs/ApiInterception/TC-0009-post-mocking/mobile.test.ts +24 -24
- package/templates/nx/packages/matchers/e2e/specs/ApiInterception/TC-0009-post-mocking/web.test.ts +24 -24
- package/templates/nx/packages/matchers/e2e/specs/BrowserContext/TC-0007-title-and-navigation/mobile.test.ts +3 -3
- package/templates/nx/packages/matchers/e2e/specs/BrowserContext/TC-0007-title-and-navigation/web.test.ts +19 -19
- package/templates/nx/packages/matchers/e2e/specs/ContentMatchers/TC-0005-text-and-values/mobile.test.ts +3 -3
- package/templates/nx/packages/matchers/e2e/specs/ContentMatchers/TC-0005-text-and-values/web.test.ts +17 -17
- package/templates/nx/packages/matchers/e2e/specs/ContentMatchers/TC-0006-collections-and-empty/mobile.test.ts +3 -3
- package/templates/nx/packages/matchers/e2e/specs/ContentMatchers/TC-0006-collections-and-empty/web.test.ts +11 -11
- package/templates/nx/packages/matchers/e2e/specs/ElementMatchers/TC-0003-visibility-and-dom/mobile.test.ts +3 -3
- package/templates/nx/packages/matchers/e2e/specs/ElementMatchers/TC-0003-visibility-and-dom/web.test.ts +11 -11
- package/templates/nx/packages/matchers/e2e/specs/ElementMatchers/TC-0004-states-and-attributes/mobile.test.ts +3 -3
- package/templates/nx/packages/matchers/e2e/specs/ElementMatchers/TC-0004-states-and-attributes/web.test.ts +29 -29
- package/templates/nx/packages/matchers/e2e/specs/EnvironmentConfig/TC-0019-read-custom-environment-variable/common.test.ts +5 -5
- package/templates/nx/packages/matchers/e2e/specs/EnvironmentConfig/TC-0019-read-custom-environment-variable/spec.md +16 -16
- package/templates/nx/packages/matchers/e2e/specs/EnvironmentConfig/suite.md +9 -9
- package/templates/nx/packages/playground/e2e/project.json +2 -2
- package/templates/nx/packages/playground/e2e/specs/Playground/TC-0001-form-controls/mobile.test.ts +3 -3
- package/templates/nx/packages/playground/e2e/specs/Playground/TC-0001-form-controls/web.test.ts +6 -6
- package/templates/nx/packages/playground/e2e/specs/Playground/TC-0002-toggle-elements/mobile.test.ts +3 -3
- package/templates/nx/packages/playground/e2e/specs/Playground/TC-0002-toggle-elements/web.test.ts +6 -6
- package/templates/nx/pnpm-lock.yaml +6663 -6663
- package/templates/nx/pnpm-workspace.yaml +9 -9
- package/templates/nx/shared/testing/page-objects/MatchersPage/mobile.ts +33 -33
- package/templates/nx/shared/testing/page-objects/MatchersPage/web.ts +91 -91
- package/templates/nx/shared/testing/page-objects/NavigationPage/mobile.ts +5 -5
- package/templates/nx/shared/testing/page-objects/NavigationPage/web.ts +8 -8
- package/templates/nx/shared/testing/page-objects/PlaygroundPage/mobile.ts +26 -26
- package/templates/nx/shared/testing/page-objects/PlaygroundPage/web.ts +31 -31
- package/templates/nx/shared/testing/project.json +18 -19
- package/templates/nx/shared/testing/support/actions/fillCredentials/mobile.action.ts +4 -4
- package/templates/nx/shared/testing/support/actions/fillCredentials/web.action.ts +4 -4
- package/templates/nx/shared/testing/support/steps/togglePlaygroundStates/mobile.step.ts +3 -3
- package/templates/nx/shared/testing/support/steps/togglePlaygroundStates/web.step.ts +5 -5
- package/templates/nx/shared/testing/support/steps/verifyPlaygroundState/mobile.step.ts +4 -4
- package/templates/nx/shared/testing/support/steps/verifyPlaygroundState/web.step.ts +6 -6
- package/templates/nx/spectra.config.ts +65 -52
- package/templates/react-component/.cursorrules +17 -17
- package/templates/react-component/.vscode/extensions.json +5 -5
- package/templates/react-component/CLAUDE.md +14 -14
- package/templates/react-component/README.md +69 -69
- package/templates/react-component/fixtures/component-mock.json +12 -12
- package/templates/react-component/global-hooks/after/web.hook.ts +3 -3
- package/templates/react-component/global-hooks/before/web.hook.ts +3 -3
- package/templates/react-component/package.json +27 -27
- package/templates/react-component/page-objects/BadgeComponent/web.ts +23 -23
- package/templates/react-component/page-objects/ButtonComponent/web.ts +23 -23
- package/templates/react-component/page-objects/InputComponent/web.ts +13 -13
- package/templates/react-component/specs/BadgeComponent/TC-0002-badge-severities-and-dot/spec.md +18 -18
- package/templates/react-component/specs/BadgeComponent/TC-0002-badge-severities-and-dot/web.test.tsx +11 -11
- package/templates/react-component/specs/BadgeComponent/TC-0006-badge-success-with-dot/spec.md +18 -18
- package/templates/react-component/specs/BadgeComponent/TC-0006-badge-success-with-dot/web.test.tsx +10 -10
- package/templates/react-component/specs/BadgeComponent/TC-0007-badge-by-severity-lookup/spec.md +18 -18
- package/templates/react-component/specs/BadgeComponent/TC-0007-badge-by-severity-lookup/web.test.tsx +16 -16
- package/templates/react-component/specs/BadgeComponent/suite.md +12 -12
- package/templates/react-component/specs/ButtonComponent/TC-0001-button-rendering-and-click/spec.md +19 -19
- package/templates/react-component/specs/ButtonComponent/TC-0001-button-rendering-and-click/web.test.tsx +25 -28
- package/templates/react-component/specs/ButtonComponent/TC-0004-disabled-button-not-clickable/spec.md +19 -19
- package/templates/react-component/specs/ButtonComponent/TC-0004-disabled-button-not-clickable/web.test.tsx +13 -22
- package/templates/react-component/specs/ButtonComponent/TC-0005-button-renders-icon/spec.md +18 -18
- package/templates/react-component/specs/ButtonComponent/TC-0005-button-renders-icon/web.test.tsx +8 -8
- package/templates/react-component/specs/ButtonComponent/suite.md +12 -12
- package/templates/react-component/specs/InputComponent/TC-0003-input-typing-and-clear/spec.md +20 -20
- package/templates/react-component/specs/InputComponent/TC-0003-input-typing-and-clear/web.test.tsx +24 -28
- package/templates/react-component/specs/InputComponent/TC-0008-disabled-input-not-editable/spec.md +18 -18
- package/templates/react-component/specs/InputComponent/TC-0008-disabled-input-not-editable/web.test.tsx +9 -9
- package/templates/react-component/specs/InputComponent/suite.md +12 -12
- package/templates/react-component/spectra.config.ts +17 -27
- package/templates/react-component/src/components/Badge/Badge.tsx +60 -60
- package/templates/react-component/src/components/Button/Button.tsx +59 -57
- package/templates/react-component/src/components/Input/Input.tsx +40 -41
- package/templates/react-component/src/test-utils.tsx +23 -23
- package/templates/react-component/support/actions/fillInputField/web.action.ts +9 -9
- package/templates/react-component/support/steps/verifyButtonState/web.step.ts +12 -12
- package/bin/.testspectra-runner.hash +0 -1
- package/bin/testspectra-runner.exe +0 -0
- package/templates/nx/.nx/workspace-data/59842386-c7c4-44ca-b2c2-20e1700bd13d.db-wal +0 -0
- /package/templates/nx/.nx/workspace-data/{59842386-c7c4-44ca-b2c2-20e1700bd13d.db → 70094CFD-E89B-57A1-9619-2FC5F4963C54.db} +0 -0
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
it("Mock and assert GET API requests using browser.intercept", async () => {
|
|
2
|
-
// Navigate to API Fetch section
|
|
3
|
-
await MatchersPage.open("api-fetch");
|
|
4
|
-
|
|
5
|
-
// The app fetches the demo server's own self-hosted endpoint (/api/posts) — served by the
|
|
6
|
-
// built-in demo app (started with `--demo`), so no external network is involved. Clear any mock
|
|
7
|
-
// left registered by an earlier test in this same continuous session before adding this one,
|
|
8
|
-
// since rules aren't scoped per-test and the first matching rule wins.
|
|
9
|
-
Spectra.clearMocks();
|
|
10
|
-
const mock = await Spectra.intercept(
|
|
11
|
-
"api/posts",
|
|
12
|
-
"GET",
|
|
13
|
-
Fixture.apiData.mockPosts
|
|
14
|
-
);
|
|
15
|
-
|
|
16
|
-
// Trigger fetch button
|
|
17
|
-
await MatchersPage.fetchApiButton.click();
|
|
18
|
-
|
|
19
|
-
// Assert status and mocked elements
|
|
20
|
-
await MatchersPage.fetchStatusBadge.shouldHaveText("200 OK");
|
|
21
|
-
await MatchersPage.fetchedItems.shouldHaveLength(Fixture.apiData.mockPosts.length);
|
|
22
|
-
await MatchersPage.fetchedItems.first().shouldContainText(Fixture.apiData.mockPosts[0].title);
|
|
23
|
-
|
|
24
|
-
// Dynamically update fixture response
|
|
25
|
-
await mock.respondWith([
|
|
26
|
-
{ id: 99, title: "Dynamic Updated Mock Title", body: "Updated on the fly" }
|
|
27
|
-
]);
|
|
28
|
-
await MatchersPage.fetchApiButton.click();
|
|
29
|
-
await MatchersPage.fetchedItems.shouldHaveLength(1);
|
|
30
|
-
await MatchersPage.fetchedItems.first().shouldContainText("Dynamic Updated Mock Title");
|
|
31
|
-
});
|
|
1
|
+
it("Mock and assert GET API requests using browser.intercept", async () => {
|
|
2
|
+
// Navigate to API Fetch section
|
|
3
|
+
await MatchersPage.open("api-fetch");
|
|
4
|
+
|
|
5
|
+
// The app fetches the demo server's own self-hosted endpoint (/api/posts) — served by the
|
|
6
|
+
// built-in demo app (started with `--demo`), so no external network is involved. Clear any mock
|
|
7
|
+
// left registered by an earlier test in this same continuous session before adding this one,
|
|
8
|
+
// since rules aren't scoped per-test and the first matching rule wins.
|
|
9
|
+
Spectra.clearMocks();
|
|
10
|
+
const mock = await Spectra.intercept(
|
|
11
|
+
"api/posts",
|
|
12
|
+
"GET",
|
|
13
|
+
Fixture.apiData.mockPosts
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
// Trigger fetch button
|
|
17
|
+
await MatchersPage.fetchApiButton.click();
|
|
18
|
+
|
|
19
|
+
// Assert status and mocked elements
|
|
20
|
+
await MatchersPage.fetchStatusBadge.shouldHaveText("200 OK");
|
|
21
|
+
await MatchersPage.fetchedItems.shouldHaveLength(Fixture.apiData.mockPosts.length);
|
|
22
|
+
await MatchersPage.fetchedItems.first().shouldContainText(Fixture.apiData.mockPosts[0].title);
|
|
23
|
+
|
|
24
|
+
// Dynamically update fixture response
|
|
25
|
+
await mock.respondWith([
|
|
26
|
+
{ id: 99, title: "Dynamic Updated Mock Title", body: "Updated on the fly" }
|
|
27
|
+
]);
|
|
28
|
+
await MatchersPage.fetchApiButton.click();
|
|
29
|
+
await MatchersPage.fetchedItems.shouldHaveLength(1);
|
|
30
|
+
await MatchersPage.fetchedItems.first().shouldContainText("Dynamic Updated Mock Title");
|
|
31
|
+
});
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
it('Mock and assert POST API requests using browser.intercept', async () => {
|
|
2
|
-
// TODO: Implement test steps and assertions
|
|
3
|
-
});
|
|
1
|
+
it('Mock and assert POST API requests using browser.intercept', async () => {
|
|
2
|
+
// TODO: Implement test steps and assertions
|
|
3
|
+
});
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
it('Mock and assert POST API requests using browser.intercept', async () => {
|
|
2
|
-
// TODO: Implement test steps and assertions
|
|
3
|
-
});
|
|
1
|
+
it('Mock and assert POST API requests using browser.intercept', async () => {
|
|
2
|
+
// TODO: Implement test steps and assertions
|
|
3
|
+
});
|
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
it("Mock and assert POST API requests using browser.intercept", async () => {
|
|
2
|
-
// Navigate to API POST section
|
|
3
|
-
await MatchersPage.open("api-post");
|
|
4
|
-
|
|
5
|
-
// Setup POST API interception with status 201 — the app posts to the host demo server's
|
|
6
|
-
// self-hosted endpoint (http://localhost:5200/api/posts), transparently routed through the
|
|
7
|
-
// worker's mock proxy via the device's global HTTP proxy set up at bootstrap.
|
|
8
|
-
Spectra.clearMocks();
|
|
9
|
-
await Spectra.intercept(
|
|
10
|
-
"api/posts",
|
|
11
|
-
"POST",
|
|
12
|
-
Fixture.apiData.mockPostResponse,
|
|
13
|
-
{ statusCode: 201 }
|
|
14
|
-
);
|
|
15
|
-
|
|
16
|
-
// Fill in form fields from Fixture
|
|
17
|
-
await MatchersPage.postTitleInput.type(Fixture.apiData.mockNewPost.title);
|
|
18
|
-
await MatchersPage.postBodyInput.type(Fixture.apiData.mockNewPost.body);
|
|
19
|
-
|
|
20
|
-
// Submit POST form
|
|
21
|
-
await MatchersPage.submitPostButton.click();
|
|
22
|
-
|
|
23
|
-
// Assert response elements and status
|
|
24
|
-
await MatchersPage.postStatusBadge.shouldHaveText("201 Created");
|
|
25
|
-
await MatchersPage.postSuccessBanner.shouldBeVisible();
|
|
26
|
-
await MatchersPage.postResponseJson.shouldContainText(Fixture.apiData.mockNewPost.title);
|
|
27
|
-
});
|
|
1
|
+
it("Mock and assert POST API requests using browser.intercept", async () => {
|
|
2
|
+
// Navigate to API POST section
|
|
3
|
+
await MatchersPage.open("api-post");
|
|
4
|
+
|
|
5
|
+
// Setup POST API interception with status 201 — the app posts to the host demo server's
|
|
6
|
+
// self-hosted endpoint (http://localhost:5200/api/posts), transparently routed through the
|
|
7
|
+
// worker's mock proxy via the device's global HTTP proxy set up at bootstrap.
|
|
8
|
+
Spectra.clearMocks();
|
|
9
|
+
await Spectra.intercept(
|
|
10
|
+
"api/posts",
|
|
11
|
+
"POST",
|
|
12
|
+
Fixture.apiData.mockPostResponse,
|
|
13
|
+
{ statusCode: 201 }
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
// Fill in form fields from Fixture
|
|
17
|
+
await MatchersPage.postTitleInput.type(Fixture.apiData.mockNewPost.title);
|
|
18
|
+
await MatchersPage.postBodyInput.type(Fixture.apiData.mockNewPost.body);
|
|
19
|
+
|
|
20
|
+
// Submit POST form
|
|
21
|
+
await MatchersPage.submitPostButton.click();
|
|
22
|
+
|
|
23
|
+
// Assert response elements and status
|
|
24
|
+
await MatchersPage.postStatusBadge.shouldHaveText("201 Created");
|
|
25
|
+
await MatchersPage.postSuccessBanner.shouldBeVisible();
|
|
26
|
+
await MatchersPage.postResponseJson.shouldContainText(Fixture.apiData.mockNewPost.title);
|
|
27
|
+
});
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
---
|
|
2
|
-
id: TC-0009-post-mocking
|
|
3
|
-
title: Mock and assert POST API requests using browser.intercept
|
|
4
|
-
priority: High
|
|
5
|
-
caseType: Positive
|
|
6
|
-
status: ready-for-automation
|
|
7
|
-
coverage:
|
|
8
|
-
web: automated
|
|
9
|
-
mobile: automated
|
|
10
|
-
---
|
|
11
|
-
|
|
12
|
-
# Mock and assert POST API requests using browser.intercept
|
|
13
|
-
|
|
14
|
-
## Test Steps
|
|
15
|
-
1. Open API POST section in matchers page
|
|
16
|
-
2. Intercept POST /api/posts with mock response returning 201 status
|
|
17
|
-
3. Fill post title and post body inputs from fixture
|
|
18
|
-
4. Click submit POST button
|
|
19
|
-
5. Assert status badge displays 201 Created and response JSON contains new title
|
|
1
|
+
---
|
|
2
|
+
id: TC-0009-post-mocking
|
|
3
|
+
title: Mock and assert POST API requests using browser.intercept
|
|
4
|
+
priority: High
|
|
5
|
+
caseType: Positive
|
|
6
|
+
status: ready-for-automation
|
|
7
|
+
coverage:
|
|
8
|
+
web: automated
|
|
9
|
+
mobile: automated
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
# Mock and assert POST API requests using browser.intercept
|
|
13
|
+
|
|
14
|
+
## Test Steps
|
|
15
|
+
1. Open API POST section in matchers page
|
|
16
|
+
2. Intercept POST /api/posts with mock response returning 201 status
|
|
17
|
+
3. Fill post title and post body inputs from fixture
|
|
18
|
+
4. Click submit POST button
|
|
19
|
+
5. Assert status badge displays 201 Created and response JSON contains new title
|
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
it("Mock and assert POST API requests using browser.intercept", async () => {
|
|
2
|
-
// Navigate to API POST section
|
|
3
|
-
await MatchersPage.open("api-post");
|
|
4
|
-
|
|
5
|
-
// Setup POST API interception with status 201 — the app posts to the demo server's own
|
|
6
|
-
// self-hosted endpoint (/api/posts), no external network involved.
|
|
7
|
-
Spectra.clearMocks();
|
|
8
|
-
await Spectra.intercept(
|
|
9
|
-
"api/posts",
|
|
10
|
-
"POST",
|
|
11
|
-
Fixture.apiData.mockPostResponse,
|
|
12
|
-
{ statusCode: 201 }
|
|
13
|
-
);
|
|
14
|
-
|
|
15
|
-
// Fill in form fields from Fixture
|
|
16
|
-
await MatchersPage.postTitleInput.type(Fixture.apiData.mockNewPost.title);
|
|
17
|
-
await MatchersPage.postBodyInput.type(Fixture.apiData.mockNewPost.body);
|
|
18
|
-
|
|
19
|
-
// Submit POST form
|
|
20
|
-
await MatchersPage.submitPostButton.click();
|
|
21
|
-
|
|
22
|
-
// Assert response elements and status
|
|
23
|
-
await MatchersPage.postStatusBadge.shouldHaveText("201 Created");
|
|
24
|
-
await MatchersPage.postSuccessBanner.shouldBeVisible();
|
|
25
|
-
await MatchersPage.postResponseJson.shouldContainText(Fixture.apiData.mockNewPost.title);
|
|
26
|
-
});
|
|
1
|
+
it("Mock and assert POST API requests using browser.intercept", async () => {
|
|
2
|
+
// Navigate to API POST section
|
|
3
|
+
await MatchersPage.open("api-post");
|
|
4
|
+
|
|
5
|
+
// Setup POST API interception with status 201 — the app posts to the demo server's own
|
|
6
|
+
// self-hosted endpoint (/api/posts), no external network involved.
|
|
7
|
+
Spectra.clearMocks();
|
|
8
|
+
await Spectra.intercept(
|
|
9
|
+
"api/posts",
|
|
10
|
+
"POST",
|
|
11
|
+
Fixture.apiData.mockPostResponse,
|
|
12
|
+
{ statusCode: 201 }
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
// Fill in form fields from Fixture
|
|
16
|
+
await MatchersPage.postTitleInput.type(Fixture.apiData.mockNewPost.title);
|
|
17
|
+
await MatchersPage.postBodyInput.type(Fixture.apiData.mockNewPost.body);
|
|
18
|
+
|
|
19
|
+
// Submit POST form
|
|
20
|
+
await MatchersPage.submitPostButton.click();
|
|
21
|
+
|
|
22
|
+
// Assert response elements and status
|
|
23
|
+
await MatchersPage.postStatusBadge.shouldHaveText("201 Created");
|
|
24
|
+
await MatchersPage.postSuccessBanner.shouldBeVisible();
|
|
25
|
+
await MatchersPage.postResponseJson.shouldContainText(Fixture.apiData.mockNewPost.title);
|
|
26
|
+
});
|
package/templates/default/specs/ApiInterception/TC-0012-direct-and-late-response/common.test.ts
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
it("Intercept a direct (immediate) response and a late (delayed) response using Fixture data", async () => {
|
|
2
|
-
await MatchersPage.open("api-fetch");
|
|
3
|
-
|
|
4
|
-
// The app fetches the self-hosted demo endpoint (/api/posts on web, the same path served by
|
|
5
|
-
// the demo server and reached through the device proxy on mobile) — no external network, so
|
|
6
|
-
// there's no upstream latency leaking into the "immediate" assertion below. On web, CDP's
|
|
7
|
-
// Fetch domain intercepts it; on Android, the device's global HTTP proxy routes it through the
|
|
8
|
-
// same worker-side mock engine. Neither platform needs the app, or this test, to know anything
|
|
9
|
-
// special about being under test.
|
|
10
|
-
Spectra.clearMocks();
|
|
11
|
-
|
|
12
|
-
// Direct (immediate) response — Fixture data returned with no artificial latency.
|
|
13
|
-
const mock = await Spectra.intercept("api/posts", "GET", Fixture.apiData.mockPosts);
|
|
14
|
-
await MatchersPage.fetchApiButton.click();
|
|
15
|
-
await MatchersPage.fetchStatusBadge.shouldHaveText("200 OK");
|
|
16
|
-
await MatchersPage.fetchedItems.shouldHaveLength(Fixture.apiData.mockPosts.length);
|
|
17
|
-
await MatchersPage.fetchedItems.first().shouldContainText(Fixture.apiData.mockPosts[0].title);
|
|
18
|
-
|
|
19
|
-
// Late (delayed) response — same mock rule, switched to hold the response back via `delayMs`.
|
|
20
|
-
// The loading indicator must still be visible right after the click, proving this is real
|
|
21
|
-
// network-level latency (the request genuinely stays pending) rather than a client-side-only
|
|
22
|
-
// spinner timer. The delay is set past the default assertion timeout on purpose, to demonstrate
|
|
23
|
-
// the per-assertion `{ timeoutMs }` override below — without it, these assertions would fail-fast
|
|
24
|
-
// before the delayed response ever arrives.
|
|
25
|
-
await mock.respondWith(Fixture.apiData.mockPosts, { delayMs: 2500 });
|
|
26
|
-
await MatchersPage.fetchApiButton.click();
|
|
27
|
-
await MatchersPage.fetchLoadingIndicator.shouldBeVisible();
|
|
28
|
-
await MatchersPage.fetchStatusBadge.shouldHaveText("200 OK", { timeoutMs: 3500 });
|
|
29
|
-
await MatchersPage.fetchedItems.shouldHaveLength(Fixture.apiData.mockPosts.length, { timeoutMs: 3500 });
|
|
30
|
-
});
|
|
1
|
+
it("Intercept a direct (immediate) response and a late (delayed) response using Fixture data", async () => {
|
|
2
|
+
await MatchersPage.open("api-fetch");
|
|
3
|
+
|
|
4
|
+
// The app fetches the self-hosted demo endpoint (/api/posts on web, the same path served by
|
|
5
|
+
// the demo server and reached through the device proxy on mobile) — no external network, so
|
|
6
|
+
// there's no upstream latency leaking into the "immediate" assertion below. On web, CDP's
|
|
7
|
+
// Fetch domain intercepts it; on Android, the device's global HTTP proxy routes it through the
|
|
8
|
+
// same worker-side mock engine. Neither platform needs the app, or this test, to know anything
|
|
9
|
+
// special about being under test.
|
|
10
|
+
Spectra.clearMocks();
|
|
11
|
+
|
|
12
|
+
// Direct (immediate) response — Fixture data returned with no artificial latency.
|
|
13
|
+
const mock = await Spectra.intercept("api/posts", "GET", Fixture.apiData.mockPosts);
|
|
14
|
+
await MatchersPage.fetchApiButton.click();
|
|
15
|
+
await MatchersPage.fetchStatusBadge.shouldHaveText("200 OK");
|
|
16
|
+
await MatchersPage.fetchedItems.shouldHaveLength(Fixture.apiData.mockPosts.length);
|
|
17
|
+
await MatchersPage.fetchedItems.first().shouldContainText(Fixture.apiData.mockPosts[0].title);
|
|
18
|
+
|
|
19
|
+
// Late (delayed) response — same mock rule, switched to hold the response back via `delayMs`.
|
|
20
|
+
// The loading indicator must still be visible right after the click, proving this is real
|
|
21
|
+
// network-level latency (the request genuinely stays pending) rather than a client-side-only
|
|
22
|
+
// spinner timer. The delay is set past the default assertion timeout on purpose, to demonstrate
|
|
23
|
+
// the per-assertion `{ timeoutMs }` override below — without it, these assertions would fail-fast
|
|
24
|
+
// before the delayed response ever arrives.
|
|
25
|
+
await mock.respondWith(Fixture.apiData.mockPosts, { delayMs: 2500 });
|
|
26
|
+
await MatchersPage.fetchApiButton.click();
|
|
27
|
+
await MatchersPage.fetchLoadingIndicator.shouldBeVisible();
|
|
28
|
+
await MatchersPage.fetchStatusBadge.shouldHaveText("200 OK", { timeoutMs: 3500 });
|
|
29
|
+
await MatchersPage.fetchedItems.shouldHaveLength(Fixture.apiData.mockPosts.length, { timeoutMs: 3500 });
|
|
30
|
+
});
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
---
|
|
2
|
-
id: TC-0012-direct-and-late-response
|
|
3
|
-
title: Intercept a direct (immediate) response and a late (delayed) response using Fixture data
|
|
4
|
-
priority: High
|
|
5
|
-
caseType: Positive
|
|
6
|
-
status: ready-for-automation
|
|
7
|
-
coverage:
|
|
8
|
-
web: automated
|
|
9
|
-
mobile: automated
|
|
10
|
-
---
|
|
11
|
-
|
|
12
|
-
# Intercept a direct (immediate) response and a late (delayed) response using Fixture data
|
|
13
|
-
|
|
14
|
-
## Test Steps
|
|
15
|
-
1. Open the API fetch section in the matchers page
|
|
16
|
-
2. Intercept GET /api/posts with mock posts fixture data
|
|
17
|
-
3. Click the fetch API button
|
|
18
|
-
4. Assert the status badge displays 200 OK and the immediate fixture items render
|
|
19
|
-
5. Update the mock response with an artificial 50ms delay
|
|
20
|
-
6. Click the fetch API button
|
|
21
|
-
7. Assert the loading indicator is visible while the request is held
|
|
22
|
-
8. Assert the status badge displays 200 OK and the delayed fixture items render
|
|
1
|
+
---
|
|
2
|
+
id: TC-0012-direct-and-late-response
|
|
3
|
+
title: Intercept a direct (immediate) response and a late (delayed) response using Fixture data
|
|
4
|
+
priority: High
|
|
5
|
+
caseType: Positive
|
|
6
|
+
status: ready-for-automation
|
|
7
|
+
coverage:
|
|
8
|
+
web: automated
|
|
9
|
+
mobile: automated
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
# Intercept a direct (immediate) response and a late (delayed) response using Fixture data
|
|
13
|
+
|
|
14
|
+
## Test Steps
|
|
15
|
+
1. Open the API fetch section in the matchers page
|
|
16
|
+
2. Intercept GET /api/posts with mock posts fixture data
|
|
17
|
+
3. Click the fetch API button
|
|
18
|
+
4. Assert the status badge displays 200 OK and the immediate fixture items render
|
|
19
|
+
5. Update the mock response with an artificial 50ms delay
|
|
20
|
+
6. Click the fetch API button
|
|
21
|
+
7. Assert the loading indicator is visible while the request is held
|
|
22
|
+
8. Assert the status badge displays 200 OK and the delayed fixture items render
|
package/templates/default/specs/ApiInterception/TC-0013-real-network-call-recorded/common.test.ts
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
it("Make a genuine (non-intercepted) network call and verify it is recorded", async () => {
|
|
2
|
-
await MatchersPage.open("api-fetch");
|
|
3
|
-
|
|
4
|
-
// Deliberately no Spectra.intercept() call — this is a genuine request that actually leaves
|
|
5
|
-
// the app and hits a real server, not a mock. It targets the demo server's own self-hosted
|
|
6
|
-
// endpoint (started with `--demo`) instead of an external public API, so it's deterministic
|
|
7
|
-
// and fast everywhere. On web the browser reaches localhost directly; on Android it's
|
|
8
|
-
// transparently routed through the device's global HTTP proxy with no matching mock rule, so
|
|
9
|
-
// the worker's proxy just forwards it for real. Clear any mock a previous test in this suite
|
|
10
|
-
// left registered (e.g. against /api/posts) so it can't accidentally catch this request too —
|
|
11
|
-
// this test uses a different resource (/api/todos/1) specifically to avoid that collision,
|
|
12
|
-
// plus a cache-busting query param so a repeat run doesn't get a 304 Not Modified from the
|
|
13
|
-
// device/browser's own HTTP cache.
|
|
14
|
-
Spectra.clearMocks();
|
|
15
|
-
const cacheBuster = Date.now();
|
|
16
|
-
await MatchersPage.fetchCustomUrlInput.type(`http://localhost:5200/api/todos/1?cb=${cacheBuster}`);
|
|
17
|
-
await MatchersPage.fetchApiButton.click();
|
|
18
|
-
await MatchersPage.fetchStatusBadge.shouldHaveText("200 OK");
|
|
19
|
-
|
|
20
|
-
const entry = Spectra.browser.recordedNetwork.find((e) => e.url.includes(`todos/1?cb=${cacheBuster}`));
|
|
21
|
-
if (!entry) {
|
|
22
|
-
throw new Error("Expected a recorded network entry for the real demo-server call, found none");
|
|
23
|
-
}
|
|
24
|
-
if (entry.status !== 200) {
|
|
25
|
-
throw new Error(`Expected recorded entry status 200, got ${entry.status}`);
|
|
26
|
-
}
|
|
27
|
-
});
|
|
1
|
+
it("Make a genuine (non-intercepted) network call and verify it is recorded", async () => {
|
|
2
|
+
await MatchersPage.open("api-fetch");
|
|
3
|
+
|
|
4
|
+
// Deliberately no Spectra.intercept() call — this is a genuine request that actually leaves
|
|
5
|
+
// the app and hits a real server, not a mock. It targets the demo server's own self-hosted
|
|
6
|
+
// endpoint (started with `--demo`) instead of an external public API, so it's deterministic
|
|
7
|
+
// and fast everywhere. On web the browser reaches localhost directly; on Android it's
|
|
8
|
+
// transparently routed through the device's global HTTP proxy with no matching mock rule, so
|
|
9
|
+
// the worker's proxy just forwards it for real. Clear any mock a previous test in this suite
|
|
10
|
+
// left registered (e.g. against /api/posts) so it can't accidentally catch this request too —
|
|
11
|
+
// this test uses a different resource (/api/todos/1) specifically to avoid that collision,
|
|
12
|
+
// plus a cache-busting query param so a repeat run doesn't get a 304 Not Modified from the
|
|
13
|
+
// device/browser's own HTTP cache.
|
|
14
|
+
Spectra.clearMocks();
|
|
15
|
+
const cacheBuster = Date.now();
|
|
16
|
+
await MatchersPage.fetchCustomUrlInput.type(`http://localhost:5200/api/todos/1?cb=${cacheBuster}`);
|
|
17
|
+
await MatchersPage.fetchApiButton.click();
|
|
18
|
+
await MatchersPage.fetchStatusBadge.shouldHaveText("200 OK");
|
|
19
|
+
|
|
20
|
+
const entry = Spectra.browser.recordedNetwork.find((e) => e.url.includes(`todos/1?cb=${cacheBuster}`));
|
|
21
|
+
if (!entry) {
|
|
22
|
+
throw new Error("Expected a recorded network entry for the real demo-server call, found none");
|
|
23
|
+
}
|
|
24
|
+
if (entry.status !== 200) {
|
|
25
|
+
throw new Error(`Expected recorded entry status 200, got ${entry.status}`);
|
|
26
|
+
}
|
|
27
|
+
});
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
---
|
|
2
|
-
id: TC-0013-real-network-call-recorded
|
|
3
|
-
title: Make a genuine (non-intercepted) network call and verify it is recorded
|
|
4
|
-
priority: High
|
|
5
|
-
caseType: Positive
|
|
6
|
-
status: ready-for-automation
|
|
7
|
-
coverage:
|
|
8
|
-
web: automated
|
|
9
|
-
mobile: automated
|
|
10
|
-
---
|
|
11
|
-
|
|
12
|
-
# Make a genuine (non-intercepted) network call and verify it is recorded
|
|
13
|
-
|
|
14
|
-
## Test Steps
|
|
15
|
-
1. Open the API fetch section in the matchers page
|
|
16
|
-
2. Clear any active mocks left by a previous test
|
|
17
|
-
3. Enter a real (non-intercepted) demo-server todo endpoint URL with a cache-busting query param
|
|
18
|
-
4. Click the fetch API button
|
|
19
|
-
5. Assert the status badge displays 200 OK
|
|
20
|
-
6. Assert the network report records the genuine call with status 200
|
|
1
|
+
---
|
|
2
|
+
id: TC-0013-real-network-call-recorded
|
|
3
|
+
title: Make a genuine (non-intercepted) network call and verify it is recorded
|
|
4
|
+
priority: High
|
|
5
|
+
caseType: Positive
|
|
6
|
+
status: ready-for-automation
|
|
7
|
+
coverage:
|
|
8
|
+
web: automated
|
|
9
|
+
mobile: automated
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
# Make a genuine (non-intercepted) network call and verify it is recorded
|
|
13
|
+
|
|
14
|
+
## Test Steps
|
|
15
|
+
1. Open the API fetch section in the matchers page
|
|
16
|
+
2. Clear any active mocks left by a previous test
|
|
17
|
+
3. Enter a real (non-intercepted) demo-server todo endpoint URL with a cache-busting query param
|
|
18
|
+
4. Click the fetch API button
|
|
19
|
+
5. Assert the status badge displays 200 OK
|
|
20
|
+
6. Assert the network report records the genuine call with status 200
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
---
|
|
2
|
-
id: TC-0015-mock-server-sent-events
|
|
3
|
-
title: Mock a Server-Sent Events (EventSource) stream via the existing network-intercept engine
|
|
4
|
-
priority: Medium
|
|
5
|
-
caseType: Positive
|
|
6
|
-
status: ready-for-automation
|
|
7
|
-
coverage:
|
|
8
|
-
web: automated
|
|
9
|
-
mobile: unsupported
|
|
10
|
-
---
|
|
11
|
-
|
|
12
|
-
# Mock a Server-Sent Events (EventSource) stream via the existing network-intercept engine
|
|
13
|
-
|
|
14
|
-
Mobile coverage is `unsupported`: React Native has no built-in `EventSource` — a real project
|
|
15
|
-
targeting mobile would add a userland SSE client library, at which point whether/how it's
|
|
16
|
-
mockable depends entirely on that library's own networking implementation, not something
|
|
17
|
-
TestSpectra's driver can generalize over.
|
|
18
|
-
|
|
19
|
-
## Test Steps
|
|
20
|
-
1. Open the SSE matcher section
|
|
21
|
-
2. Intercept GET /api/sse-feed with a text/event-stream mock body
|
|
22
|
-
3. Click the connect button
|
|
23
|
-
4. Assert two SSE messages render
|
|
24
|
-
5. Assert the first message contains "hello from mock SSE" and the last contains "second event"
|
|
1
|
+
---
|
|
2
|
+
id: TC-0015-mock-server-sent-events
|
|
3
|
+
title: Mock a Server-Sent Events (EventSource) stream via the existing network-intercept engine
|
|
4
|
+
priority: Medium
|
|
5
|
+
caseType: Positive
|
|
6
|
+
status: ready-for-automation
|
|
7
|
+
coverage:
|
|
8
|
+
web: automated
|
|
9
|
+
mobile: unsupported
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
# Mock a Server-Sent Events (EventSource) stream via the existing network-intercept engine
|
|
13
|
+
|
|
14
|
+
Mobile coverage is `unsupported`: React Native has no built-in `EventSource` — a real project
|
|
15
|
+
targeting mobile would add a userland SSE client library, at which point whether/how it's
|
|
16
|
+
mockable depends entirely on that library's own networking implementation, not something
|
|
17
|
+
TestSpectra's driver can generalize over.
|
|
18
|
+
|
|
19
|
+
## Test Steps
|
|
20
|
+
1. Open the SSE matcher section
|
|
21
|
+
2. Intercept GET /api/sse-feed with a text/event-stream mock body
|
|
22
|
+
3. Click the connect button
|
|
23
|
+
4. Assert two SSE messages render
|
|
24
|
+
5. Assert the first message contains "hello from mock SSE" and the last contains "second event"
|
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
it("Mock a Server-Sent Events (EventSource) stream via the existing network-intercept engine", async () => {
|
|
2
|
-
await MatchersPage.open("sse");
|
|
3
|
-
|
|
4
|
-
// EventSource's initial request is a plain HTTP GET under the hood — CDP's Fetch domain
|
|
5
|
-
// intercepts it exactly like any other fetch()/XHR request. Fulfilling it with a
|
|
6
|
-
// text/event-stream body delivers every "data: ...\n\n" block at once; the browser's own
|
|
7
|
-
// EventSource parser still splits that into individual "message" events and dispatches them
|
|
8
|
-
// just as it would for a real stream, which is the part this demo actually cares about.
|
|
9
|
-
//
|
|
10
|
-
// What this can't fake: `Fetch.fulfillRequest` delivers a complete, connection-closing
|
|
11
|
-
// response (there's no way to keep it open indefinitely the way a real SSE endpoint would), so
|
|
12
|
-
// the browser's EventSource treats that closure as a connection error shortly after — the
|
|
13
|
-
// events still arrive and get processed first, but the app's own "CONNECTED" status flips back
|
|
14
|
-
// to disconnected right after, same as it would after a real server unexpectedly closed the
|
|
15
|
-
// connection. So this test verifies the events were received, not that the connection stayed
|
|
16
|
-
// open — genuinely-persistent SSE isn't something a request/response-shaped mock can simulate.
|
|
17
|
-
await Spectra.intercept("/api/sse-feed", "GET", {
|
|
18
|
-
body: 'data: {"text":"hello from mock SSE"}\n\ndata: {"text":"second event"}\n\n',
|
|
19
|
-
headers: { "Content-Type": "text/event-stream" },
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
await Spectra.get("#sse-connect-btn").click();
|
|
23
|
-
await Spectra.getAll(".sse-message-item").shouldHaveLength(2);
|
|
24
|
-
await Spectra.getAll(".sse-message-item").first().shouldContainText("hello from mock SSE");
|
|
25
|
-
await Spectra.getAll(".sse-message-item").last().shouldContainText("second event");
|
|
26
|
-
});
|
|
1
|
+
it("Mock a Server-Sent Events (EventSource) stream via the existing network-intercept engine", async () => {
|
|
2
|
+
await MatchersPage.open("sse");
|
|
3
|
+
|
|
4
|
+
// EventSource's initial request is a plain HTTP GET under the hood — CDP's Fetch domain
|
|
5
|
+
// intercepts it exactly like any other fetch()/XHR request. Fulfilling it with a
|
|
6
|
+
// text/event-stream body delivers every "data: ...\n\n" block at once; the browser's own
|
|
7
|
+
// EventSource parser still splits that into individual "message" events and dispatches them
|
|
8
|
+
// just as it would for a real stream, which is the part this demo actually cares about.
|
|
9
|
+
//
|
|
10
|
+
// What this can't fake: `Fetch.fulfillRequest` delivers a complete, connection-closing
|
|
11
|
+
// response (there's no way to keep it open indefinitely the way a real SSE endpoint would), so
|
|
12
|
+
// the browser's EventSource treats that closure as a connection error shortly after — the
|
|
13
|
+
// events still arrive and get processed first, but the app's own "CONNECTED" status flips back
|
|
14
|
+
// to disconnected right after, same as it would after a real server unexpectedly closed the
|
|
15
|
+
// connection. So this test verifies the events were received, not that the connection stayed
|
|
16
|
+
// open — genuinely-persistent SSE isn't something a request/response-shaped mock can simulate.
|
|
17
|
+
await Spectra.intercept("/api/sse-feed", "GET", {
|
|
18
|
+
body: 'data: {"text":"hello from mock SSE"}\n\ndata: {"text":"second event"}\n\n',
|
|
19
|
+
headers: { "Content-Type": "text/event-stream" },
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
await Spectra.get("#sse-connect-btn").click();
|
|
23
|
+
await Spectra.getAll(".sse-message-item").shouldHaveLength(2);
|
|
24
|
+
await Spectra.getAll(".sse-message-item").first().shouldContainText("hello from mock SSE");
|
|
25
|
+
await Spectra.getAll(".sse-message-item").last().shouldContainText("second event");
|
|
26
|
+
});
|
package/templates/default/specs/ApiInterception/TC-0016-bypass-websocket-with-app-level-mock/spec.md
CHANGED
|
@@ -1,37 +1,37 @@
|
|
|
1
|
-
---
|
|
2
|
-
id: TC-0016-bypass-websocket-with-app-level-mock
|
|
3
|
-
title: Bypass a real WebSocket connection via an app-level test-only mock flag
|
|
4
|
-
priority: Medium
|
|
5
|
-
caseType: Positive
|
|
6
|
-
status: ready-for-automation
|
|
7
|
-
coverage:
|
|
8
|
-
web: automated
|
|
9
|
-
mobile: unsupported
|
|
10
|
-
---
|
|
11
|
-
|
|
12
|
-
# Bypass a real WebSocket connection via an app-level test-only mock flag
|
|
13
|
-
|
|
14
|
-
**Why this isn't network-level interception like `Spectra.intercept()`:** a WebSocket connection
|
|
15
|
-
starts as an HTTP `Upgrade` handshake and then becomes a raw bidirectional frame stream — it's
|
|
16
|
-
never a single request/response CDP's `Fetch` domain can fulfill the way it fulfills a normal
|
|
17
|
-
`fetch()`/`XHR`/`EventSource` request. Chrome DevTools Protocol's WebSocket-related events
|
|
18
|
-
(`Network.webSocketCreated`, `webSocketFrameSent`/`webSocketFrameReceived`, etc.) are
|
|
19
|
-
observation-only — CDP has no command that mocks or rewrites a WS frame in flight. This is a
|
|
20
|
-
genuine protocol-level limitation, not a gap in this driver.
|
|
21
|
-
|
|
22
|
-
The practical workaround, and what this demo shows: the app itself checks for a test-only global
|
|
23
|
-
flag (`window.__mockWebSocketMessages`) and swaps in an in-memory fake socket when present,
|
|
24
|
-
instead of opening a real connection. `Spectra.browser.evaluate()` sets that flag before the app
|
|
25
|
-
connects. This is the same pattern used by Cypress/Playwright test suites for the same reason.
|
|
26
|
-
|
|
27
|
-
Mobile coverage is `unsupported`: React Native's WebSocket implementation is a native module,
|
|
28
|
-
not a page-context global reachable via a browser-style `evaluate()` call — a mobile equivalent
|
|
29
|
-
would need the RN app's own WebSocket client wrapper to support a comparable test-only bypass.
|
|
30
|
-
|
|
31
|
-
## Test Steps
|
|
32
|
-
1. Open the WebSocket matcher section
|
|
33
|
-
2. Set the app-level mock flag via browser.evaluate before the app connects
|
|
34
|
-
3. Click the connect button
|
|
35
|
-
4. Assert the connection status displays CONNECTED and two mocked frames render
|
|
36
|
-
5. Click the disconnect button
|
|
37
|
-
6. Assert the connection status displays DISCONNECTED
|
|
1
|
+
---
|
|
2
|
+
id: TC-0016-bypass-websocket-with-app-level-mock
|
|
3
|
+
title: Bypass a real WebSocket connection via an app-level test-only mock flag
|
|
4
|
+
priority: Medium
|
|
5
|
+
caseType: Positive
|
|
6
|
+
status: ready-for-automation
|
|
7
|
+
coverage:
|
|
8
|
+
web: automated
|
|
9
|
+
mobile: unsupported
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
# Bypass a real WebSocket connection via an app-level test-only mock flag
|
|
13
|
+
|
|
14
|
+
**Why this isn't network-level interception like `Spectra.intercept()`:** a WebSocket connection
|
|
15
|
+
starts as an HTTP `Upgrade` handshake and then becomes a raw bidirectional frame stream — it's
|
|
16
|
+
never a single request/response CDP's `Fetch` domain can fulfill the way it fulfills a normal
|
|
17
|
+
`fetch()`/`XHR`/`EventSource` request. Chrome DevTools Protocol's WebSocket-related events
|
|
18
|
+
(`Network.webSocketCreated`, `webSocketFrameSent`/`webSocketFrameReceived`, etc.) are
|
|
19
|
+
observation-only — CDP has no command that mocks or rewrites a WS frame in flight. This is a
|
|
20
|
+
genuine protocol-level limitation, not a gap in this driver.
|
|
21
|
+
|
|
22
|
+
The practical workaround, and what this demo shows: the app itself checks for a test-only global
|
|
23
|
+
flag (`window.__mockWebSocketMessages`) and swaps in an in-memory fake socket when present,
|
|
24
|
+
instead of opening a real connection. `Spectra.browser.evaluate()` sets that flag before the app
|
|
25
|
+
connects. This is the same pattern used by Cypress/Playwright test suites for the same reason.
|
|
26
|
+
|
|
27
|
+
Mobile coverage is `unsupported`: React Native's WebSocket implementation is a native module,
|
|
28
|
+
not a page-context global reachable via a browser-style `evaluate()` call — a mobile equivalent
|
|
29
|
+
would need the RN app's own WebSocket client wrapper to support a comparable test-only bypass.
|
|
30
|
+
|
|
31
|
+
## Test Steps
|
|
32
|
+
1. Open the WebSocket matcher section
|
|
33
|
+
2. Set the app-level mock flag via browser.evaluate before the app connects
|
|
34
|
+
3. Click the connect button
|
|
35
|
+
4. Assert the connection status displays CONNECTED and two mocked frames render
|
|
36
|
+
5. Click the disconnect button
|
|
37
|
+
6. Assert the connection status displays DISCONNECTED
|