Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: webpack test hot cases for new incremental #7738

Merged
merged 3 commits into from
Sep 2, 2024
Merged
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
8 changes: 7 additions & 1 deletion packages/rspack-test-tools/etc/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ export function createHookCase(name: string, src: string, dist: string, source:
export function createHotCase(name: string, src: string, dist: string, target: TCompilerOptions<ECompilerType.Rspack>["target"]): void;

// @public (undocumented)
export function createHotNewIncrementalCase(name: string, src: string, dist: string, target: TCompilerOptions<ECompilerType.Rspack>["target"]): void;
export function createHotNewIncrementalCase(name: string, src: string, dist: string, target: TCompilerOptions<ECompilerType.Rspack>["target"], documentType: EDocumentType): void;

// @public (undocumented)
export function createHotStepCase(name: string, src: string, dist: string, target: TCompilerOptions<ECompilerType.Rspack>["target"]): void;
Expand Down Expand Up @@ -463,9 +463,13 @@ export class HookTaskProcessor<T extends ECompilerType> extends SnapshotProcesso
export class HotNewIncrementalProcessor<T extends ECompilerType> extends HotProcessor<T> {
constructor(_hotOptions: IHotNewIncrementalProcessorOptions<T>);
// (undocumented)
afterAll(context: ITestContext): Promise<void>;
// (undocumented)
static defaultOptions<T extends ECompilerType>(this: HotNewIncrementalProcessor<T>, context: ITestContext): TCompilerOptions<T>;
// (undocumented)
protected _hotOptions: IHotNewIncrementalProcessorOptions<T>;
// (undocumented)
run(env: ITestEnv, context: ITestContext): Promise<void>;
}

// @public (undocumented)
Expand Down Expand Up @@ -750,6 +754,8 @@ export interface IHookProcessorOptions<T extends ECompilerType> extends ISnapsho

// @public (undocumented)
export interface IHotNewIncrementalProcessorOptions<T extends ECompilerType> extends Omit<IBasicProcessorOptions<T>, "runable"> {
// (undocumented)
documentType?: EDocumentType;
// (undocumented)
target: TCompilerOptions<T>["target"];
}
Expand Down
25 changes: 16 additions & 9 deletions packages/rspack-test-tools/src/case/new-incremental.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,24 @@ import { HotNewIncrementalProcessor } from "../processor/hot-new-incremental";
import { WatchProcessor, WatchStepProcessor } from "../processor/watch";
import { HotRunnerFactory, WatchRunnerFactory } from "../runner";
import { BasicCaseCreator } from "../test/creator";
import { ECompilerType, type TCompilerOptions } from "../type";
import {
ECompilerType,
type EDocumentType,
type TCompilerOptions
} from "../type";

type TTarget = TCompilerOptions<ECompilerType.Rspack>["target"];

const hotCreators: Map<
TTarget,
string,
BasicCaseCreator<ECompilerType.Rspack>
> = new Map();

function getHotCreator(target: TTarget) {
if (!hotCreators.has(target)) {
function getHotCreator(target: TTarget, documentType: EDocumentType) {
const key = JSON.stringify({ target, documentType });
if (!hotCreators.has(key)) {
hotCreators.set(
target,
key,
new BasicCaseCreator({
clean: true,
describe: true,
Expand All @@ -27,23 +32,25 @@ function getHotCreator(target: TTarget) {
name,
target: target as TTarget,
compilerType: ECompilerType.Rspack,
configFiles: ["rspack.config.js", "webpack.config.js"]
configFiles: ["rspack.config.js", "webpack.config.js"],
documentType
})
],
runner: HotRunnerFactory
})
);
}
return hotCreators.get(target)!;
return hotCreators.get(key)!;
}

export function createHotNewIncrementalCase(
name: string,
src: string,
dist: string,
target: TCompilerOptions<ECompilerType.Rspack>["target"]
target: TCompilerOptions<ECompilerType.Rspack>["target"],
documentType: EDocumentType
) {
const creator = getHotCreator(target);
const creator = getHotCreator(target, documentType);
creator.create(name, src, dist);
}

Expand Down
24 changes: 24 additions & 0 deletions packages/rspack-test-tools/src/processor/hot-new-incremental.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import {
ECompilerType,
EDocumentType,
type ITestContext,
type ITestEnv,
type TCompilerOptions
} from "../type";
import type { IBasicProcessorOptions } from "./basic";
Expand All @@ -9,6 +11,7 @@ import { HotProcessor } from "./hot";
export interface IHotNewIncrementalProcessorOptions<T extends ECompilerType>
extends Omit<IBasicProcessorOptions<T>, "runable"> {
target: TCompilerOptions<T>["target"];
documentType?: EDocumentType;
}

export class HotNewIncrementalProcessor<
Expand All @@ -18,6 +21,27 @@ export class HotNewIncrementalProcessor<
super(_hotOptions);
}

async run(env: ITestEnv, context: ITestContext) {
context.setValue(
this._options.name,
"documentType",
this._hotOptions.documentType
);
await super.run(env, context);
}

async afterAll(context: ITestContext) {
try {
await super.afterAll(context);
} catch (e: any) {
const isFake =
context.getValue(this._options.name, "documentType") ===
EDocumentType.Fake;
if (isFake && /Should run all hot steps/.test(e.message)) return;
throw e;
}
}

static defaultOptions<T extends ECompilerType>(
this: HotNewIncrementalProcessor<T>,
context: ITestContext
Expand Down
93 changes: 70 additions & 23 deletions packages/rspack-test-tools/tests/NewIncremental.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,41 @@ process.env.RSPACK_CONFIG_VALIDATE = 'loose-silent';
const path = require("path");
const { describeByWalk, createHotNewIncrementalCase, createWatchNewIncrementalCase } = require("../dist");

function postfixName(name) {
return `${name} (newIncremental)`
function v(name) {
return path.join(__dirname, `new-incremental ${name}`)
}

describeByWalk(__filename, (name, src, dist) => {
createHotNewIncrementalCase(postfixName(name), src, dist, "async-node");
// Run tests rspack-test-tools/tests/hotCases in target async-node
describeByWalk(v("hot async-node"), (name, src, dist) => {
createHotNewIncrementalCase(name, src, dist, "async-node", "jsdom");
}, {
source: path.resolve(__dirname, "./hotCases"),
dist: path.resolve(__dirname, `./js/new-incremental/hot-node`),
dist: path.resolve(__dirname, `./js/new-incremental/hot-async-node`),
exclude: [/^css$/]
});

describeByWalk(__filename, (name, src, dist) => {
createHotNewIncrementalCase(postfixName(name), src, dist, "web");
// Run tests rspack-test-tools/tests/hotCases in target web
describeByWalk(v("hot web"), (name, src, dist) => {
createHotNewIncrementalCase(name, src, dist, "web", "jsdom");
}, {
source: path.resolve(__dirname, "./hotCases"),
dist: path.resolve(__dirname, `./js/new-incremental/hot-web`)
});

describeByWalk(__filename, (name, src, dist) => {
createHotNewIncrementalCase(postfixName(name), src, dist, "webworker");
// Run tests rspack-test-tools/tests/hotCases in target webworker
describeByWalk(v("hot webworker"), (name, src, dist) => {
createHotNewIncrementalCase(name, src, dist, "webworker", "jsdom");
}, {
source: path.resolve(__dirname, "./hotCases"),
dist: path.resolve(__dirname, `./js/new-incremental/hot-worker`),
exclude: [/^css$/]
});

// Run tests in rspack-test-tools/tests/watchCases
describeByWalk(__filename, (name, src, dist) => {
// Run tests rspack-test-tools/tests/watchCases
describeByWalk(v("watch"), (name, src, dist) => {
const tempDir = path.resolve(__dirname, `./js/new-incremental/temp`);
createWatchNewIncrementalCase(
postfixName(name),
name,
src,
dist,
path.join(tempDir, name),
Expand All @@ -45,23 +48,67 @@ describeByWalk(__filename, (name, src, dist) => {
dist: path.resolve(__dirname, `./js/new-incremental/watch`),
});

// Run tests in webpack-test/watchCases
describeByWalk(__filename, (name, src, dist) => {
const tempDir = path.resolve(__dirname, `./js/new-incremental/temp`);
// Run tests webpack-test/hotCases in target async-node
describeByWalk(v("hot async-node (webpack-test)"), (name, src, dist) => {
createHotNewIncrementalCase(name, src, dist, "async-node", "fake");
}, {
source: path.resolve(__dirname, "../../../tests/webpack-test/hotCases"),
dist: path.resolve(__dirname, `./js/new-incremental/webpack-test/hot-async-node`),
exclude: [
/move-between-runtime/,
]
});

// Run tests webpack-test/hotCases in target node
describeByWalk(v("hot node (webpack-test)"), (name, src, dist) => {
createHotNewIncrementalCase(name, src, dist, "node", "fake");
}, {
source: path.resolve(__dirname, "../../../tests/webpack-test/hotCases"),
dist: path.resolve(__dirname, `./js/new-incremental/webpack-test/hot-node`),
exclude: [
/move-between-runtime/,
]
});

// Run tests webpack-test/hotCases in target web
describeByWalk(v("hot web (webpack-test)"), (name, src, dist) => {
createHotNewIncrementalCase(name, src, dist, "web", "fake");
}, {
source: path.resolve(__dirname, "../../../tests/webpack-test/hotCases"),
dist: path.resolve(__dirname, `./js/new-incremental/webpack-test/hot-web`),
exclude: [
/move-between-runtime/,
]
});

// Run tests webpack-test/hotCases in target webworker
describeByWalk(v("hot webworker (webpack-test)"), (name, src, dist) => {
createHotNewIncrementalCase(name, src, dist, "webworker", "fake");
}, {
source: path.resolve(__dirname, "../../../tests/webpack-test/hotCases"),
dist: path.resolve(__dirname, `./js/new-incremental/webpack-test/hot-webworker`),
exclude: [
/move-between-runtime/,
]
});

// Run tests webpack-test/watchCases
describeByWalk(v("watch (webpack-test)"), (name, src, dist) => {
const tempDir = path.resolve(__dirname, `./js/new-incremental/webpack-test/temp`);
createWatchNewIncrementalCase(
postfixName(name),
name,
src,
dist,
path.join(tempDir, name),
);
}, {
source: path.resolve(__dirname, "../../../tests/webpack-test/watchCases"),
dist: path.resolve(__dirname, `./js/new-incremental/webpack-test/watch`),
exclude: [
/module-concatenation-plugin/,
/missing-module/,
/caching-inner-source/,
/production/,
/warnings-contribute-to-hash/,
]
exclude: [
/module-concatenation-plugin/,
/missing-module/,
/caching-inner-source/,
/production/,
/warnings-contribute-to-hash/,
]
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const {
SingleEntryPlugin,
EntryPlugin: SingleEntryPlugin,
node: { NodeTemplatePlugin }
} = require("@rspack/core");

Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

3 changes: 0 additions & 3 deletions tests/webpack-test/hotCases/errors/decline/test.filter.js

This file was deleted.

3 changes: 0 additions & 3 deletions tests/webpack-test/hotCases/errors/events/test.filter.js

This file was deleted.

This file was deleted.

This file was deleted.

3 changes: 0 additions & 3 deletions tests/webpack-test/hotCases/errors/unaccepted/test.filter.js

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading