From e403e3fca6f5622cf1bb03516cf0b2fda8b83019 Mon Sep 17 00:00:00 2001 From: harpsealjs Date: Fri, 26 Apr 2024 17:19:55 +0800 Subject: [PATCH] chore: jsdom windows (#6379) * 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 --- packages/rspack-test-tools/src/runner/hot-step.ts | 2 +- .../rspack-test-tools/src/runner/runner/web/jsdom.ts | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/rspack-test-tools/src/runner/hot-step.ts b/packages/rspack-test-tools/src/runner/hot-step.ts index 70449b75808..984bed5f973 100644 --- a/packages/rspack-test-tools/src/runner/hot-step.ts +++ b/packages/rspack-test-tools/src/runner/hot-step.ts @@ -69,7 +69,7 @@ export class HotStepRunnerFactory< }; const runner = new WebRunner({ - dom: process.platform === "win32" ? "fake" : "jsdom", + dom: "jsdom", env, stats, name: this.name, diff --git a/packages/rspack-test-tools/src/runner/runner/web/jsdom.ts b/packages/rspack-test-tools/src/runner/runner/web/jsdom.ts index c55e5091c50..de71ae569d7 100644 --- a/packages/rspack-test-tools/src/runner/runner/web/jsdom.ts +++ b/packages/rspack-test-tools/src/runner/runner/web/jsdom.ts @@ -34,6 +34,7 @@ export class JSDOMWebRunner< } ); + this.dom.window.console = console; // compat with FakeDocument this.dom.window.eval(` Object.defineProperty(document.head, "_children", { @@ -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}"]`) @@ -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); @@ -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);