mirror of
https://github.com/bytedance/deer-flow.git
synced 2026-07-26 07:57:57 +00:00
Frontend unit tests run in a plain node environment, so nothing that renders can be covered and no hook can be tested under real React. The workaround that forces is already in the tree: the use-global-shortcuts test mocks out react itself, so its useEffect never re-runs on a dependency change and never goes through React's commit/cleanup ordering -- it pins the stub rather than the hook. Split the suite into two rstest projects: *.test.ts(x) keeps running on node, *.dom.test.ts(x) runs on happy-dom. A global DOM environment was measured first and rejected -- it takes the same 743 tests from 3.3s to 9.5s -- and rstest has no per-file environment docblock, so projects is the only way to charge that cost to the tests that need it. useIsMobile is the first consumer: it had no tests and cannot have any without a document, since it reads window.matchMedia.
41 lines
1.2 KiB
TypeScript
41 lines
1.2 KiB
TypeScript
import { resolve } from "path";
|
|
|
|
import { pluginReact } from "@rsbuild/plugin-react";
|
|
import { defineConfig } from "@rstest/core";
|
|
|
|
// Build wiring is identical across projects; only the environment and which
|
|
// files each one claims differ.
|
|
const shared = {
|
|
plugins: [pluginReact()],
|
|
resolve: {
|
|
alias: {
|
|
"@": resolve(__dirname, "src"),
|
|
},
|
|
},
|
|
output: {
|
|
// Streamdown imports KaTeX CSS as a side effect. Bundle these packages so
|
|
// Rsbuild processes that CSS import instead of Node trying to load it.
|
|
bundleDependencies: ["streamdown", "katex"],
|
|
},
|
|
};
|
|
|
|
export default defineConfig({
|
|
projects: [
|
|
{
|
|
...shared,
|
|
name: "node",
|
|
include: ["tests/unit/**/*.test.ts", "tests/unit/**/*.test.tsx"],
|
|
// A DOM environment costs roughly 3x the runtime of this suite, so the
|
|
// pure-logic tests that make up nearly all of it stay on node and only
|
|
// `*.dom.test.*` pays for a document.
|
|
exclude: { patterns: ["**/*.dom.test.*"], override: false },
|
|
},
|
|
{
|
|
...shared,
|
|
name: "dom",
|
|
testEnvironment: "happy-dom",
|
|
include: ["tests/unit/**/*.dom.test.ts", "tests/unit/**/*.dom.test.tsx"],
|
|
},
|
|
],
|
|
});
|