Skip to content

Commit

Permalink
chore: jsdom windows (#6379)
Browse files Browse the repository at this point in the history
* chore: jsdom runner support windows

* chore: jsdom runner support windows

* chore: migrate remain cases and remove rspack/tests

* chore: migrate remain cases and remove rspack/tests
  • Loading branch information
LingyuCoder authored Apr 26, 2024
1 parent d88c69b commit e403e3f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/rspack-test-tools/src/runner/hot-step.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export class HotStepRunnerFactory<
};

const runner = new WebRunner({
dom: process.platform === "win32" ? "fake" : "jsdom",
dom: "jsdom",
env,
stats,
name: this.name,
Expand Down
9 changes: 5 additions & 4 deletions packages/rspack-test-tools/src/runner/runner/web/jsdom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export class JSDOMWebRunner<
}
);

this.dom.window.console = console;
// compat with FakeDocument
this.dom.window.eval(`
Object.defineProperty(document.head, "_children", {
Expand Down Expand Up @@ -165,7 +166,7 @@ export class JSDOMWebRunner<
this._options.testConfig.moduleScope(currentModuleScope);
}

const scopeKey = file!.path.replace(path.win32.sep, path.posix.sep);
const scopeKey = file!.path.split(path.win32.sep).join(path.posix.sep);
const args = Object.keys(currentModuleScope);
const argValues = args
.map(arg => `window["${scopeKey}"]["${arg}"]`)
Expand All @@ -179,7 +180,7 @@ export class JSDOMWebRunner<
get(target, prop, receiver) {
if (prop === "currentScript") {
var script = target.createElement("script");
script.src = "https://test.cases/path/${file.subPath}index.js";
script.src = "https://test.cases/path/${file.subPath.split(path.win32.sep).join(path.posix.sep)}index.js";
return script;
}
return Reflect.get(target, prop, receiver);
Expand All @@ -189,9 +190,9 @@ export class JSDOMWebRunner<
return Reflect.get(target, prop, receiver);
}
});
(function(window, self, globalThis, ${args.join(", ")}) {
(function(window, self, globalThis, console, ${args.join(", ")}) {
${file.content}
})($$g$$, $$g$$, $$g$$, ${argValues});
})($$g$$, $$g$$, $$g$$, window["console"], ${argValues});
`;

this.preExecute(code, file);
Expand Down

2 comments on commit e403e3f

@rspack-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Ran ecosystem CI: Open

suite result
modernjs, self-hosted, Linux, ci ✅ success
_selftest, ubuntu-latest ✅ success
nx, ubuntu-latest ✅ success
rspress, ubuntu-latest ✅ success
rsbuild, ubuntu-latest ✅ success
compat, ubuntu-latest ✅ success
examples, ubuntu-latest ✅ success

@rspack-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Benchmark detail: Open

Name Base (2024-04-26 0c04972) Current Change
10000_development-mode + exec 2.75 s ± 31 ms 2.77 s ± 29 ms +0.77 %
10000_development-mode_hmr + exec 700 ms ± 3.2 ms 701 ms ± 6.2 ms +0.08 %
10000_production-mode + exec 2.53 s ± 28 ms 2.56 s ± 21 ms +0.90 %
arco-pro_development-mode + exec 2.51 s ± 85 ms 2.47 s ± 42 ms -1.60 %
arco-pro_development-mode_hmr + exec 430 ms ± 1.1 ms 429 ms ± 1.4 ms -0.06 %
arco-pro_development-mode_hmr_intercept-plugin + exec 442 ms ± 2.3 ms 441 ms ± 3.1 ms -0.02 %
arco-pro_development-mode_intercept-plugin + exec 3.25 s ± 76 ms 3.27 s ± 135 ms +0.72 %
arco-pro_production-mode + exec 3.96 s ± 76 ms 3.97 s ± 73 ms +0.23 %
arco-pro_production-mode_intercept-plugin + exec 4.72 s ± 52 ms 4.77 s ± 63 ms +1.19 %
threejs_development-mode_10x + exec 2.05 s ± 20 ms 2.07 s ± 20 ms +0.82 %
threejs_development-mode_10x_hmr + exec 748 ms ± 12 ms 755 ms ± 11 ms +0.98 %
threejs_production-mode_10x + exec 5.23 s ± 19 ms 5.27 s ± 24 ms +0.84 %

Please sign in to comment.