@lvce-editor/test-with-playwright-worker 22.39.3 → 22.39.4
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/coverageWorkerMain.js +21 -2
- package/package.json +1 -1
|
@@ -876,9 +876,24 @@ const create = async ({
|
|
|
876
876
|
const WriteJavascriptCoverage = 'WriteJavascriptCoverage';
|
|
877
877
|
|
|
878
878
|
const externalSourceMapCommentRegex = /(?:\/\/[#@]\s*sourceMappingURL=(?!data:).*?$|\/\*[#@]\s*sourceMappingURL=(?!data:).*?\*\/)/gm;
|
|
879
|
+
const externalSourceMapUrlRegex = /(?:\/\/[#@]|\/\*[#@])\s*sourceMappingURL=(?!data:)([^\s*]+)/;
|
|
879
880
|
const temporaryServerRootRegex = /^\/[a-f\d]{7,}(?=\/(?:js|packages)\/)/;
|
|
881
|
+
const windowsDrivePrefixRegex = /^[a-z]:/i;
|
|
882
|
+
const getExternalSourceMap = async (source, url) => {
|
|
883
|
+
const sourceMapUrl = source.match(externalSourceMapUrlRegex)?.[1];
|
|
884
|
+
if (!sourceMapUrl) {
|
|
885
|
+
return undefined;
|
|
886
|
+
}
|
|
887
|
+
const response = await fetch(new URL(sourceMapUrl, url));
|
|
888
|
+
if (!response.ok) {
|
|
889
|
+
throw new Error(`[test-with-playwright] failed to fetch worker source map ${sourceMapUrl}: ${response.status}`);
|
|
890
|
+
}
|
|
891
|
+
return {
|
|
892
|
+
sourcemap: await response.json()
|
|
893
|
+
};
|
|
894
|
+
};
|
|
880
895
|
const normalizeCoveragePath = path => {
|
|
881
|
-
return path.replace(temporaryServerRootRegex, '');
|
|
896
|
+
return path.replaceAll('\\', '/').replace(windowsDrivePrefixRegex, '').replace(temporaryServerRootRegex, '');
|
|
882
897
|
};
|
|
883
898
|
const normalizeCoverageData = coverageData => {
|
|
884
899
|
const normalized = Object.create(null);
|
|
@@ -909,9 +924,13 @@ const addEntryToCoverageMap = async (coverageMap, entry) => {
|
|
|
909
924
|
if (!entry.source || !entry.url || isTestScript(entry.url)) {
|
|
910
925
|
return;
|
|
911
926
|
}
|
|
927
|
+
const sourceMap = await getExternalSourceMap(entry.source, entry.url);
|
|
912
928
|
const source = entry.source.replaceAll(externalSourceMapCommentRegex, '');
|
|
913
929
|
const converter = v8ToIstanbul(getCoveragePath(entry.url), 0, {
|
|
914
|
-
source
|
|
930
|
+
source,
|
|
931
|
+
...(sourceMap && {
|
|
932
|
+
sourceMap
|
|
933
|
+
})
|
|
915
934
|
});
|
|
916
935
|
await converter.load();
|
|
917
936
|
converter.applyCoverage(entry.functions);
|