Compare commits

...

1 Commits

Author SHA1 Message Date
Uladzimir Havenchyk
c55dcba842 node native test runner 2025-07-16 14:59:24 +03:00
5 changed files with 44 additions and 0 deletions

View File

@@ -9,6 +9,7 @@
"node": ">=22",
"yarn": "^1.12.3"
},
"type": "module",
"dependencies": {
"@codemirror/autocomplete": "^6.18.3",
"@codemirror/lang-html": "^6.4.9",
@@ -273,6 +274,7 @@
"fork-ts-checker-webpack-plugin": "^9.0.2",
"get-nonce": "^1.0.1",
"glob": "^7.1.1",
"global-jsdom": "^26.0.0",
"html-webpack-plugin": "5.5.0",
"http-server": "^14.1.1",
"husky": "^8.0.2",

1
test/mocks/css.mjs Normal file
View File

@@ -0,0 +1 @@
export default {};

25
test/node-loader.mjs Normal file
View File

@@ -0,0 +1,25 @@
import { extname } from "path";
const mock = new URL("mocks/css.mjs", import.meta.url).href;
/**
*
* This hook intercepts module resolution, allowing us to handle
* CSS/SVG files in a custom way. Instead of actually loading the CSS,
* we short-circuit the resolution and return a mock module.
*
* @type {import('node:module').ResolveHook}
*/
export async function resolve(specifier, ctx, nextResolve) {
const ext = extname(specifier);
if (ext === ".css" || ext.startsWith(".svg")) {
// For CSS/SCSS, return the mock CSS module and skip default resolution.
return {
format: "module",
url: mock,
shortCircuit: true,
};
}
return nextResolve(specifier);
}

11
test/setup.mjs Normal file
View File

@@ -0,0 +1,11 @@
import { register } from "node:module";
import { afterEach } from "node:test";
import { cleanup } from "@testing-library/react";
register("./node-loader.mjs", import.meta.url);
afterEach(cleanup);
global.Event = window.Event;
global.CustomEvent = window.CustomEvent;

View File

@@ -11514,6 +11514,11 @@ global-dirs@^3.0.0:
dependencies:
ini "2.0.0"
global-jsdom@^26.0.0:
version "26.0.0"
resolved "https://registry.yarnpkg.com/global-jsdom/-/global-jsdom-26.0.0.tgz#fcddd40f81ff11531e5ce87e1a377af016018e98"
integrity sha512-BqXpTNZFjP40N+s4k8Bk9HS8GFVPJB/+TKtwcShM84wLv6C5dH9o1dydI3pL6potanhfDiIAVDbaaGj/uSdRSA==
global-modules@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/global-modules/-/global-modules-2.0.0.tgz#997605ad2345f27f51539bea26574421215c7780"