@@ -4,9 +4,29 @@ module.exports = ({ outputDirectory }) =>
44 class Worker {
55 constructor ( url , options = { } ) {
66 expect ( url ) . toBeInstanceOf ( URL ) ;
7- expect ( url . origin ) . toBe ( "https://test.cases" ) ;
8- expect ( url . pathname . startsWith ( "/path/" ) ) . toBe ( true ) ;
9- const file = url . pathname . slice ( 6 ) ;
7+ let file ;
8+ if ( url . protocol === "data:" ) {
9+ const protocolPrefix = "application/javascript," ;
10+ const importScriptsPrefix = 'importScripts("https://test.cases/path/' ;
11+ expect ( url . pathname . startsWith ( protocolPrefix ) ) . toBe ( true ) ;
12+ const decodedData = decodeURIComponent (
13+ url . pathname . slice ( protocolPrefix . length )
14+ ) ;
15+ expect ( decodedData . includes ( importScriptsPrefix ) ) . toBe ( true ) ;
16+ file = decodedData . slice (
17+ decodedData . indexOf ( importScriptsPrefix ) + importScriptsPrefix . length ,
18+ decodedData . indexOf (
19+ '"' ,
20+ decodedData . indexOf ( importScriptsPrefix ) +
21+ importScriptsPrefix . length
22+ )
23+ ) ;
24+ } else {
25+ expect ( url . origin ) . toBe ( "https://test.cases" ) ;
26+ expect ( url . pathname . startsWith ( "/path/" ) ) . toBe ( true ) ;
27+ file = url . pathname . slice ( 6 ) ;
28+ }
29+
1030 const workerBootstrap = `
1131const { parentPort } = require("worker_threads");
1232const { URL } = require("url");
@@ -15,6 +35,8 @@ const fs = require("fs");
1535global.self = global;
1636self.URL = URL;
1737self.location = new URL(${ JSON . stringify ( url . toString ( ) ) } );
38+ __webpack_public_path__ = '/path/';
39+ __webpack_base_uri__ = 'https://test.cases/';
1840const urlToPath = url => {
1941 if(url.startsWith("https://test.cases/path/")) url = url.slice(24);
2042 return path.resolve(${ JSON . stringify ( outputDirectory ) } , \`./\${url}\`);
0 commit comments