|
1 | 1 | /// <reference lib="dom" /> |
2 | 2 |
|
3 | 3 | // Import only for type-checking purposes |
4 | | -import PuppeteerHar from "puppeteer-har"; |
| 4 | +import { Frame, Page } from "puppeteer"; |
| 5 | +import { PuppeteerHar, PuppeteerHarOptions } from "puppeteer-har"; |
5 | 6 |
|
6 | 7 | // Define a mock Page interface just for type-checking |
7 | | -interface MockPage { |
8 | | - goto(url: string): Promise<void>; |
9 | | -} |
10 | 8 |
|
11 | 9 | // Create a mock Page object for type-checking |
12 | | -const mockPage: MockPage = { |
| 10 | +const mockPage: any = { |
13 | 11 | goto: async (url: string) => { |
14 | 12 | // Mock implementation |
15 | 13 | }, |
16 | 14 | }; |
17 | 15 |
|
18 | 16 | // Check if the PuppeteerHar class is correctly typed |
19 | | -const page: MockPage = mockPage as any; // Type assertion to use MockPage |
20 | | -const har = new PuppeteerHar(page); |
| 17 | +const page: Page = mockPage as any; // Type assertion to use Page |
| 18 | + |
| 19 | +const har = new PuppeteerHar(page, { |
| 20 | + path: "", |
| 21 | + saveResponse: true, |
| 22 | + captureMimeTypes: true, |
| 23 | +} as PuppeteerHarOptions); |
21 | 24 |
|
22 | 25 | // Type-check the methods of PuppeteerHar |
23 | 26 | const startPromise: Promise<void> = har.start(); |
24 | | -const stopPromise: Promise<void> = har.stop(); |
25 | | -const savePromise: Promise<void> = har.save({ path: "example.har" }); |
| 27 | +const stopPromise: Promise<PuppeteerHar | undefined> = har.stop(); |
| 28 | +const cleanupPromise: Promise<void> = har.cleanUp(); |
26 | 29 |
|
27 | 30 | // Verify that the PuppeteerHar instance is correctly typed |
28 | 31 | const harInstance: PuppeteerHar = har; |
29 | 32 |
|
| 33 | +const memberInProgress: boolean = har.inProgress; |
| 34 | +const memberPage: Page = har.page; |
| 35 | +const memberMainFrame: Frame = har.mainFrame; |
| 36 | + |
30 | 37 | // Ensure that the methods return the correct types |
31 | 38 | startPromise.then(() => console.log("Start method passed type check")); |
32 | 39 | stopPromise.then(() => console.log("Stop method passed type check")); |
33 | | -savePromise.then(() => console.log("Save method passed type check")); |
| 40 | +cleanupPromise.then(() => console.log("Cleanup method passed type check")); |
0 commit comments