Skip to content

Commit

Permalink
test: refresh modified file mtime when run NEXT_START (web-infra-dev#…
Browse files Browse the repository at this point in the history
…8863)

* test: refresh modified file mtime when run NEXT_START

* fix: comment
  • Loading branch information
jerrykingxyz authored Dec 27, 2024
1 parent 675c2cf commit ebb85fe
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { readFile, writeFile } from "fs-extra";

export async function refreshModifyTime(file: string) {
const data = await readFile(file);
await writeFile(file, data);
}
3 changes: 2 additions & 1 deletion packages/rspack-test-tools/src/processor/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ export class CacheProcessor<T extends ECompilerType> extends BasicProcessor<T> {
): TCompilerOptions<T> {
const options = {
context: context.getSource(),
mode: "development",
mode: "production",
cache: true,
devtool: false,
output: {
path: context.getDist(),
Expand Down
13 changes: 13 additions & 0 deletions packages/rspack-test-tools/src/runner/cache.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { StatsCompilation } from "@rspack/core";

import checkArrayExpectation from "../helper/legacy/checkArrayExpectation";
import { refreshModifyTime } from "../helper/util/refreshModifyTime";
import {
type ECompilerType,
EDocumentType,
Expand All @@ -13,6 +14,8 @@ import {
import { BasicRunnerFactory } from "./basic";
import { WebRunner } from "./runner/web";

const MAX_COMPILER_INDEX = 100;

export class CacheRunnerFactory<
T extends ECompilerType
> extends BasicRunnerFactory<T> {
Expand Down Expand Up @@ -105,6 +108,11 @@ export class CacheRunnerFactory<
await compiler.close();
compiler.createCompiler();

await Promise.all(
hotUpdateContext.changedFiles.map(async file => {
await refreshModifyTime(file);
})
);
hotUpdateContext.changedFiles = [];
hotUpdateContext.updateIndex++;
const stats = await compiler.build();
Expand Down Expand Up @@ -138,6 +146,11 @@ export class CacheRunnerFactory<
env.it(
`NEXT_START run with compilerIndex==${compilerIndex + 1}`,
async () => {
if (compilerIndex > MAX_COMPILER_INDEX) {
throw new Error(
"NEXT_START has been called more than the maximum times"
);
}
compilerIndex++;
return getWebRunner().run(file);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,4 @@ it("should store and resume asset parser and generator states", async () => {
if (COMPILER_INDEX == 1) {
expect(value).toBe(3);
}

// expect(value).toBe(1);
// await NEXT_START();
// }
// if (COMPILER_INDEX == 1) {

// expect(value).toBe(2);
// }
});

0 comments on commit ebb85fe

Please sign in to comment.