Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,31 @@ npx nx affected -t test --parallel=3 --exclude='*,!tag:type:pkg'

This command ensures that only relevant tests are executed, saving time and resources.

### Enhanced (packages/enhanced) Test Suites

The enhanced package uses Vitest with a custom runner that compiles webpack config cases and then executes their bundles in an isolated VM context.

- Run all enhanced tests

```sh
nx test enhanced
```

- Run a single enhanced case (by directory name)

```sh
# Example: only run the container/0-container-full case
npx vitest -c packages/enhanced/vitest.config.ts -t "0-container-full should compile"

# Or target a specific test file and group
npx vitest -c packages/enhanced/vitest.config.ts packages/enhanced/test/ConfigTestCases.basictest.vitest.ts -t "0-container-full should compile"
npx vitest -c packages/enhanced/vitest.config.ts packages/enhanced/test/ConfigTestCases.embedruntime.vitest.ts -t "0-container-full should compile"
```

- Notes
- Filters match the top-level test names created by the runner (e.g., `<case-name> should compile`).
- Case-internal exported tests (the `it(...)` inside a case’s `index.js`) are aggregated and executed within that top-level test. Use the `-t` filter on the top-level name to run only that case.


## Submitting Changes

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"commit": "cz",
"docs": "typedoc",
"f": "nx format:write",
"enhanced:jest": "pnpm build && cd packages/enhanced && NODE_OPTIONS=--experimental-vm-modules npx jest test/ConfigTestCases.basictest.js test/unit",
"enhanced:vitest": "NODE_OPTIONS=--experimental-vm-modules npx vitest -c packages/enhanced/vitest.config.ts ",
"enhanced:rstest": "NODE_OPTIONS=--experimental-vm-modules npx rstest -c packages/enhanced/rstest.config.ts ",
"lint": "nx run-many --target=lint",
"test": "nx run-many --target=test",
"build": "NX_TUI=false nx run-many --target=build --parallel=5 --projects=tag:type:pkg",
Expand Down
12 changes: 12 additions & 0 deletions packages/enhanced/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,18 @@
}
},
"test": {
"executor": "nx:run-commands",
"options": {
"parallel": false,
"commands": [
{
"command": "NODE_OPTIONS=--experimental-vm-modules npx vitest -c packages/enhanced/vitest.config.ts",
"forwardAllArgs": true
}
]
}
},
"test:jest": {
"executor": "nx:run-commands",
"options": {
"parallel": false,
Expand Down
9 changes: 9 additions & 0 deletions packages/enhanced/rstest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { defineConfig } from '@rstest/core';
import path from 'path';

export default defineConfig({
testEnvironment: 'node',
globals: true,
include: [path.resolve(__dirname, 'test/ConfigTestCases.*.rstest.ts')],
testTimeout: 60000, // webpack 编译耗时较长
});
21 changes: 21 additions & 0 deletions packages/enhanced/test/ConfigTestCases.basictest.rstest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// 清理残留的 Federation 全局状态,避免跨 case 互相影响
if ((globalThis as any).__FEDERATION__) {
(globalThis as any).__GLOBAL_LOADING_REMOTE_ENTRY__ = {};
//@ts-ignore
(globalThis as any).__FEDERATION__.__INSTANCES__.map((i: any) => {
i.moduleCache.clear();
if ((globalThis as any)[i.name]) {
delete (globalThis as any)[i.name];
}
});
(globalThis as any).__FEDERATION__.__INSTANCES__ = [];
}

import { rs } from '@rstest/core';
import { describeCases } from './ConfigTestCases.rstest';

rs.resetModules();

describeCases({
name: 'ConfigTestCases',
});
21 changes: 21 additions & 0 deletions packages/enhanced/test/ConfigTestCases.basictest.vitest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// 清理残留的 Federation 全局状态,避免跨 case 互相影响
if ((globalThis as any).__FEDERATION__) {
(globalThis as any).__GLOBAL_LOADING_REMOTE_ENTRY__ = {};
//@ts-ignore
(globalThis as any).__FEDERATION__.__INSTANCES__.map((i: any) => {
i.moduleCache.clear();
if ((globalThis as any)[i.name]) {
delete (globalThis as any)[i.name];
}
});
(globalThis as any).__FEDERATION__.__INSTANCES__ = [];
}

import { vi } from 'vitest';
import { describeCases } from './ConfigTestCases.vitest';

vi.resetModules();

describeCases({
name: 'ConfigTestCases',
});
24 changes: 24 additions & 0 deletions packages/enhanced/test/ConfigTestCases.embedruntime.rstest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// 清理残留的 Federation 全局状态,避免跨 case 互相影响
if ((globalThis as any).__FEDERATION__) {
(globalThis as any).__GLOBAL_LOADING_REMOTE_ENTRY__ = {};
//@ts-ignore
(globalThis as any).__FEDERATION__.__INSTANCES__.map((i: any) => {
i.moduleCache.clear();
if ((globalThis as any)[i.name]) {
delete (globalThis as any)[i.name];
}
});
(globalThis as any).__FEDERATION__.__INSTANCES__ = [];
}

import { rs } from '@rstest/core';
import { describeCases } from './ConfigTestCases.rstest';

rs.resetModules();

describeCases({
name: 'ConfigTestCases',
federation: {
asyncStartup: true,
},
});
24 changes: 24 additions & 0 deletions packages/enhanced/test/ConfigTestCases.embedruntime.vitest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// 清理残留的 Federation 全局状态,避免跨 case 互相影响
if ((globalThis as any).__FEDERATION__) {
(globalThis as any).__GLOBAL_LOADING_REMOTE_ENTRY__ = {};
//@ts-ignore
(globalThis as any).__FEDERATION__.__INSTANCES__.map((i: any) => {
i.moduleCache.clear();
if ((globalThis as any)[i.name]) {
delete (globalThis as any)[i.name];
}
});
(globalThis as any).__FEDERATION__.__INSTANCES__ = [];
}

import { vi } from 'vitest';
import { describeCases } from './ConfigTestCases.vitest';

vi.resetModules();

describeCases({
name: 'ConfigTestCases',
federation: {
asyncStartup: true,
},
});
Loading