Skip to content

Commit 31a2722

Browse files
committed
chore: change to snapshot testing
1 parent a99cc35 commit 31a2722

2 files changed

Lines changed: 29 additions & 30 deletions

File tree

tests/tools/pages.test.js.snapshot

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
exports[`pages > list_pages > list pages for extension pages with --category-extensions 1`] = `
2+
# list_pages response
3+
## Pages
4+
1: about:blank [selected]
5+
## Extension Pages
6+
2: chrome-extension://<extension-id>/popup.html
7+
`;

tests/tools/pages.test.ts

Lines changed: 22 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@ import type {Dialog} from 'puppeteer-core';
1212
import sinon from 'sinon';
1313

1414
import type {ParsedArguments} from '../../src/cli.js';
15-
import {
16-
installExtension,
17-
triggerExtensionAction,
18-
} from '../../src/tools/extensions.js';
1915
import {
2016
listPages,
2117
newPage,
@@ -26,12 +22,16 @@ import {
2622
handleDialog,
2723
getTabId,
2824
} from '../../src/tools/pages.js';
29-
import {extractExtensionId, html, withMcpContext} from '../utils.js';
25+
import {html, withMcpContext} from '../utils.js';
3026

31-
const EXTENSION_PATH = path.join(
27+
const EXTENSION_SW_PATH = path.join(
3228
import.meta.dirname,
3329
'../../../tests/tools/fixtures/extension-sw',
3430
);
31+
const EXTENSION_PATH = path.join(
32+
import.meta.dirname,
33+
'../../../tests/tools/fixtures/extension',
34+
);
3535

3636
describe('pages', () => {
3737
afterEach(() => {
@@ -49,29 +49,20 @@ describe('pages', () => {
4949
assert.ok(response.includePages);
5050
});
5151
});
52-
it(`list pages for extension pages with --category-extensions`, async () => {
52+
it(`list pages for extension pages with --category-extensions`, async t => {
5353
await withMcpContext(
5454
async (response, context) => {
55-
await installExtension.handler(
56-
{params: {path: EXTENSION_PATH}},
57-
response,
58-
context,
59-
);
55+
const extensionId = await context.installExtension(EXTENSION_PATH);
6056

61-
const extensionId = extractExtensionId(response);
6257
assert.ok(extensionId);
6358

64-
await triggerExtensionAction.handler(
65-
{params: {id: extensionId}},
66-
response,
67-
context,
68-
);
69-
const popupTarget = await context.browser.waitForTarget(
59+
await context.triggerExtensionAction(extensionId);
60+
61+
const _popupTarget = await context.browser.waitForTarget(
7062
t => t.type() === 'page' && t.url().includes('chrome-extension://'),
7163
);
7264

7365
response.resetResponseLineForTesting();
74-
7566
const listPageDef = listPages({
7667
categoryExtensions: true,
7768
} as ParsedArguments);
@@ -88,7 +79,11 @@ describe('pages', () => {
8879
};
8980
assert.ok(textContent);
9081

91-
assert.ok(textContent.text.includes(popupTarget.url()));
82+
const text = textContent.text.replaceAll(
83+
extensionId,
84+
'<extension-id>',
85+
);
86+
t.assert.snapshot?.(text);
9287
},
9388
{
9489
executablePath: process.env.CANARY_EXECUTABLE_PATH,
@@ -100,19 +95,16 @@ describe('pages', () => {
10095
});
10196

10297
for (const categoryExtensions of [true, false]) {
103-
it(`list pages for extension service workers ${categoryExtensions ? 'with' : 'without'} --category-extensions`, async () => {
98+
it(`list pages for extension service workers ${categoryExtensions ? 'with' : 'without'} --category-extensions`, async() => {
10499
await withMcpContext(
105100
async (response, context) => {
106-
await installExtension.handler(
107-
{params: {path: EXTENSION_PATH}},
108-
response,
109-
context,
110-
);
101+
const extensionId = await context.installExtension(EXTENSION_SW_PATH);
102+
assert.ok(extensionId);
111103

112104
const swTarget = await context.browser.waitForTarget(
113-
t =>
114-
t.type() === 'service_worker' &&
115-
t.url().includes('chrome-extension://'),
105+
target =>
106+
target.type() === 'service_worker' &&
107+
target.url().includes('chrome-extension://'),
116108
);
117109
const swUrl = swTarget.url();
118110

0 commit comments

Comments
 (0)