@vitest/browser-playwright 4.1.0 → 4.1.1
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/dist/index.d.ts +1 -0
- package/dist/index.js +21 -19
- package/package.json +5 -5
package/dist/index.d.ts
CHANGED
|
@@ -62,6 +62,7 @@ declare class PlaywrightBrowserProvider implements BrowserProvider {
|
|
|
62
62
|
pendingTraces: Map<string, string>;
|
|
63
63
|
initScripts: string[];
|
|
64
64
|
constructor(project: TestProject, options: PlaywrightProviderOptions);
|
|
65
|
+
private onSIGTERM;
|
|
65
66
|
private openBrowser;
|
|
66
67
|
private createMocker;
|
|
67
68
|
private createContext;
|
package/dist/index.js
CHANGED
|
@@ -838,20 +838,21 @@ class PlaywrightBrowserProvider {
|
|
|
838
838
|
project.browser.registerCommand(name, command);
|
|
839
839
|
}
|
|
840
840
|
// make sure the traces are finished if the test hangs
|
|
841
|
-
process.on("SIGTERM",
|
|
842
|
-
if (!this.browser) {
|
|
843
|
-
return;
|
|
844
|
-
}
|
|
845
|
-
const promises = [];
|
|
846
|
-
for (const [trace, contextId] of this.pendingTraces.entries()) {
|
|
847
|
-
promises.push((() => {
|
|
848
|
-
const context = this.contexts.get(contextId);
|
|
849
|
-
return context?.tracing.stopChunk({ path: trace });
|
|
850
|
-
})());
|
|
851
|
-
}
|
|
852
|
-
return Promise.allSettled(promises);
|
|
853
|
-
});
|
|
841
|
+
process.on("SIGTERM", this.onSIGTERM);
|
|
854
842
|
}
|
|
843
|
+
onSIGTERM = () => {
|
|
844
|
+
if (!this.browser) {
|
|
845
|
+
return;
|
|
846
|
+
}
|
|
847
|
+
const promises = [];
|
|
848
|
+
for (const [trace, contextId] of this.pendingTraces.entries()) {
|
|
849
|
+
promises.push((() => {
|
|
850
|
+
const context = this.contexts.get(contextId);
|
|
851
|
+
return context?.tracing.stopChunk({ path: trace });
|
|
852
|
+
})());
|
|
853
|
+
}
|
|
854
|
+
return Promise.allSettled(promises);
|
|
855
|
+
};
|
|
855
856
|
async openBrowser(openBrowserOptions) {
|
|
856
857
|
await this._throwIfClosing();
|
|
857
858
|
if (this.browserPromise) {
|
|
@@ -933,7 +934,7 @@ class PlaywrightBrowserProvider {
|
|
|
933
934
|
return this.browserPromise;
|
|
934
935
|
}
|
|
935
936
|
createMocker() {
|
|
936
|
-
const
|
|
937
|
+
const idPredicates = new Map();
|
|
937
938
|
const sessionIds = new Map();
|
|
938
939
|
function createPredicate(sessionId, url) {
|
|
939
940
|
const moduleUrl = new URL(url, "http://localhost");
|
|
@@ -963,7 +964,7 @@ class PlaywrightBrowserProvider {
|
|
|
963
964
|
const ids = sessionIds.get(sessionId) || [];
|
|
964
965
|
ids.push(moduleUrl.href);
|
|
965
966
|
sessionIds.set(sessionId, ids);
|
|
966
|
-
|
|
967
|
+
idPredicates.set(predicateKey(sessionId, moduleUrl.href), predicate);
|
|
967
968
|
return predicate;
|
|
968
969
|
}
|
|
969
970
|
function predicateKey(sessionId, url) {
|
|
@@ -1026,9 +1027,9 @@ class PlaywrightBrowserProvider {
|
|
|
1026
1027
|
delete: async (sessionId, id) => {
|
|
1027
1028
|
const page = this.getPage(sessionId);
|
|
1028
1029
|
const key = predicateKey(sessionId, id);
|
|
1029
|
-
const predicate =
|
|
1030
|
+
const predicate = idPredicates.get(key);
|
|
1030
1031
|
if (predicate) {
|
|
1031
|
-
await page.context().unroute(predicate).finally(() =>
|
|
1032
|
+
await page.context().unroute(predicate).finally(() => idPredicates.delete(key));
|
|
1032
1033
|
}
|
|
1033
1034
|
},
|
|
1034
1035
|
clear: async (sessionId) => {
|
|
@@ -1036,9 +1037,9 @@ class PlaywrightBrowserProvider {
|
|
|
1036
1037
|
const ids = sessionIds.get(sessionId) || [];
|
|
1037
1038
|
const promises = ids.map((id) => {
|
|
1038
1039
|
const key = predicateKey(sessionId, id);
|
|
1039
|
-
const predicate =
|
|
1040
|
+
const predicate = idPredicates.get(key);
|
|
1040
1041
|
if (predicate) {
|
|
1041
|
-
return page.context().unroute(predicate).finally(() =>
|
|
1042
|
+
return page.context().unroute(predicate).finally(() => idPredicates.delete(key));
|
|
1042
1043
|
}
|
|
1043
1044
|
return null;
|
|
1044
1045
|
});
|
|
@@ -1171,6 +1172,7 @@ class PlaywrightBrowserProvider {
|
|
|
1171
1172
|
};
|
|
1172
1173
|
}
|
|
1173
1174
|
async close() {
|
|
1175
|
+
process.off("SIGTERM", this.onSIGTERM);
|
|
1174
1176
|
debug?.("[%s] closing provider", this.browserName);
|
|
1175
1177
|
this.closing = true;
|
|
1176
1178
|
if (this.browserPromise) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vitest/browser-playwright",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "4.1.
|
|
4
|
+
"version": "4.1.1",
|
|
5
5
|
"description": "Browser running for Vitest using playwright",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"funding": "https://opencollective.com/vitest",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
],
|
|
43
43
|
"peerDependencies": {
|
|
44
44
|
"playwright": "*",
|
|
45
|
-
"vitest": "4.1.
|
|
45
|
+
"vitest": "4.1.1"
|
|
46
46
|
},
|
|
47
47
|
"peerDependenciesMeta": {
|
|
48
48
|
"playwright": {
|
|
@@ -51,12 +51,12 @@
|
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
53
|
"tinyrainbow": "^3.0.3",
|
|
54
|
-
"@vitest/browser": "4.1.
|
|
55
|
-
"@vitest/mocker": "4.1.
|
|
54
|
+
"@vitest/browser": "4.1.1",
|
|
55
|
+
"@vitest/mocker": "4.1.1"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
58
|
"playwright": "^1.58.2",
|
|
59
|
-
"vitest": "4.1.
|
|
59
|
+
"vitest": "4.1.1"
|
|
60
60
|
},
|
|
61
61
|
"scripts": {
|
|
62
62
|
"build": "premove dist && pnpm rollup -c",
|