From 38d3a0eae89814412d3fde6624ff6095336077c0 Mon Sep 17 00:00:00 2001 From: Congcong Cai Date: Tue, 30 Sep 2025 14:34:33 +0800 Subject: [PATCH 1/5] feat: introduce isolated execution currently, as-test use isolated execution. it is quietly slow in large projects. this PR introduces `isolated` options to disable isolated execution. after that, as-test can compile all test files to one wasm module and execute once. it can speed up test execution a lot --- bin/cli.js | 36 ++++++++++- docs/api-documents/options.md | 33 +++++++--- docs/release-note.md | 6 ++ src/core/compile.ts | 71 +++++++++++++++------- src/index.ts | 2 +- src/interface.ts | 2 + tests/e2e/isolated-cli/as-test.config.js | 13 ++++ tests/e2e/isolated-cli/env.ts | 5 ++ tests/e2e/isolated-cli/stdout.txt | 6 ++ tests/e2e/isolated-cli/succeed_0.test.ts | 12 ++++ tests/e2e/isolated-cli/succeed_1.test.ts | 12 ++++ tests/e2e/isolated-cli/tsconfig.json | 4 ++ tests/e2e/isolated-false/as-test.config.js | 14 +++++ tests/e2e/isolated-false/env.ts | 5 ++ tests/e2e/isolated-false/stdout.txt | 6 ++ tests/e2e/isolated-false/succeed_0.test.ts | 12 ++++ tests/e2e/isolated-false/succeed_1.test.ts | 12 ++++ tests/e2e/isolated-false/tsconfig.json | 4 ++ tests/e2e/isolated-true/as-test.config.js | 14 +++++ tests/e2e/isolated-true/env.ts | 5 ++ tests/e2e/isolated-true/stdout.txt | 6 ++ tests/e2e/isolated-true/succeed_0.test.ts | 12 ++++ tests/e2e/isolated-true/succeed_1.test.ts | 12 ++++ tests/e2e/isolated-true/tsconfig.json | 4 ++ tests/e2e/run.js | 4 ++ 25 files changed, 279 insertions(+), 33 deletions(-) create mode 100644 tests/e2e/isolated-cli/as-test.config.js create mode 100644 tests/e2e/isolated-cli/env.ts create mode 100644 tests/e2e/isolated-cli/stdout.txt create mode 100644 tests/e2e/isolated-cli/succeed_0.test.ts create mode 100644 tests/e2e/isolated-cli/succeed_1.test.ts create mode 100644 tests/e2e/isolated-cli/tsconfig.json create mode 100644 tests/e2e/isolated-false/as-test.config.js create mode 100644 tests/e2e/isolated-false/env.ts create mode 100644 tests/e2e/isolated-false/stdout.txt create mode 100644 tests/e2e/isolated-false/succeed_0.test.ts create mode 100644 tests/e2e/isolated-false/succeed_1.test.ts create mode 100644 tests/e2e/isolated-false/tsconfig.json create mode 100644 tests/e2e/isolated-true/as-test.config.js create mode 100644 tests/e2e/isolated-true/env.ts create mode 100644 tests/e2e/isolated-true/stdout.txt create mode 100644 tests/e2e/isolated-true/succeed_0.test.ts create mode 100644 tests/e2e/isolated-true/succeed_1.test.ts create mode 100644 tests/e2e/isolated-true/tsconfig.json diff --git a/bin/cli.js b/bin/cli.js index c8ca9d0..7bfc9fb 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -23,7 +23,12 @@ program .option("--testcase ", "run only specified test cases deprecated, use --testFiles instead") .option("--testFiles ", "run only specified test files") .option("--testNamePattern ", "run only tests with a name that matches the regex pattern") - .option("--onlyFailures", "Run tests that failed in the previous"); + .option("--onlyFailures", "Run tests that failed in the previous") + .option("--isolated ", "Run tests in isolated mode") + .addHelpText( + "beforeAll", + "submit feature requests or issues: https://github.com/wasm-ecosystem/assemblyscript-unittest-framework/issues" + ); program.parse(process.argv); const options = program.opts(); @@ -61,6 +66,33 @@ const collectCoverage = config.collectCoverage || (testFiles === undefined && options.testNamePattern === undefined && !onlyFailures); +const getBoolean = (optionValue, configValue) => { + if (optionValue !== undefined) { + if (optionValue == "true") { + return true; + } else if (optionValue == "false") { + return false; + } + } + if (configValue !== undefined) { + return Boolean(configValue); + } + return undefined; +}; +const isolatedInConfig = getBoolean(options.isolated, config.isolated); +if (isolatedInConfig === undefined) { + console.warn( + chalk.yellowBright( + "Warning: In the next version, the default value of isolated will change. Please specify isolated in config" + ) + ); +} +// TODO: switch to false default in 2.x +const isolated = isolatedInConfig ?? true; + +/** + * @type {import("../dist/interface.d.ts").TestOption} + */ const testOption = { includes, excludes, @@ -77,6 +109,8 @@ const testOption = { mode: options.mode || config.mode || "table", warnLimit: Number(options.coverageLimit?.at(1)), errorLimit: Number(options.coverageLimit?.at(0)), + + isolated, }; start_unit_test(testOption) diff --git a/docs/api-documents/options.md b/docs/api-documents/options.md index 4d855b8..77c08ef 100644 --- a/docs/api-documents/options.md +++ b/docs/api-documents/options.md @@ -1,6 +1,8 @@ +[[toc]] + ## Options -### Define Config +### Config File ``` --config path of config file (default: "as-test.config.js") @@ -8,13 +10,7 @@ ### Override Config File -There are command line options which can override the configuration in `as-test.config.js`. - -``` - --temp test template file folder - --output coverage report output folder - --mode test result output format -``` +Command line options have higher priority then config file, so that it can override the configuration in `as-test.config.js`. ### Warning Behavior @@ -108,3 +104,24 @@ Provides `--onlyFailures` command line option to run the test cases that failed The framework collects coverage and generates reports by default, but it will be disablea while running partial test cases by `--testFiles` or `--testNamePattern`. You can control the coverage collection manually with `--collectCoverage` option. + +### Isolated Execution + +Isolated test execution helps isolate error propagation between different test scenarios and reduces the burden of restoring context, which is very helpful for rapid technical verification. + +However, as the project scales, isolated test execution will compile the source code multiple times, slowing down overall test performance. In this case, restoring the context in code and disabling the `isolated` option after testing can help reduce test time. + +- disable by config: + + ```js + { + // ... + isolated: false + } + ``` + +- disable by cli + + ```bash + npx as-test ... --isolated false + ``` diff --git a/docs/release-note.md b/docs/release-note.md index cacfcfc..a700962 100644 --- a/docs/release-note.md +++ b/docs/release-note.md @@ -1,5 +1,11 @@ # Release Note +## latest + +🚀 Highlight Features + +- improved the performances + ## 1.3.1 🚀 Highlight Features diff --git a/src/core/compile.ts b/src/core/compile.ts index 7a9c878..ff06816 100644 --- a/src/core/compile.ts +++ b/src/core/compile.ts @@ -1,41 +1,66 @@ import { join, relative } from "node:path"; import { findRoot } from "../utils/pathResolver.js"; import { ascMain } from "../utils/ascWrapper.js"; +import { TestOption } from "../interface.js"; -export async function compile(testCodePaths: string[], outputFolder: string, compileFlags: string): Promise { +export async function compile(testCodePaths: string[], option: TestOption): Promise { + const { isolated } = option; + if (!isolated) { + return [await unifiedCompile(testCodePaths, option)]; + } else { + return separatedCompile(testCodePaths, option); + } +} + +function getNewPath(newFolder: string, oldFolder: string, srcPath: string): string { + return join(newFolder, relative(oldFolder, srcPath)).replaceAll(/\\/g, "/"); +} + +function getAscArgs(sources: string[], outputWasm: string, outputWat: string, flags: string): string[] { + let ascArgv = [ + ...sources, + "--outFile", + outputWasm, + "--textFile", + outputWat, + "--exportStart", + "_start", + "--sourceMap", + "--debug", + "-O0", + ]; + if (flags.length > 0) { + const argv = flags.split(" "); + ascArgv = ascArgv.concat(argv); + } + return ascArgv; +} + +async function unifiedCompile(testCodePaths: string[], option: TestOption): Promise { + const { outputFolder, flags } = option; + const outputWasm = join(outputFolder, "test.wasm"); + const outputWat = join(outputFolder, "test.wat"); + const ascArgv = getAscArgs(testCodePaths, outputWasm, outputWat, flags); + await ascMain(ascArgv, false); + return outputWasm; +} + +async function separatedCompile(testCodePaths: string[], option: TestOption): Promise { + const { outputFolder, flags } = option; const wasm: string[] = []; const root = findRoot(testCodePaths); - const compile = async (testCodePath: string) => { + const compileOneFile = async (testCodePath: string) => { const outputWasm = getNewPath(outputFolder, root, testCodePath).slice(0, -2).concat("wasm"); wasm.push(outputWasm); const outputWat = getNewPath(outputFolder, root, testCodePath).slice(0, -2).concat("wat"); - let ascArgv = [ - testCodePath, - "--outFile", - outputWasm, - "--textFile", - outputWat, - "--exportStart", - "_start", - "--sourceMap", - "--debug", - "-O0", - ]; - if (compileFlags) { - const argv = compileFlags.split(" "); - ascArgv = ascArgv.concat(argv); - } + const ascArgv = getAscArgs([testCodePath], outputWasm, outputWat, flags); await ascMain(ascArgv, false); }; // Here, for-await is more efficient and less memory cost than Promise.all() for (const codePath of testCodePaths) { - await compile(codePath); + await compileOneFile(codePath); } return wasm; } - -function getNewPath(newFolder: string, oldFolder: string, srcPath: string): string { - return join(newFolder, relative(oldFolder, srcPath)).replaceAll(/\\/g, "/"); -} diff --git a/src/index.ts b/src/index.ts index 93d0ba5..9fba3d5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -59,7 +59,7 @@ async function startUniTestImpl(options: TestOption): Promise { ); console.log(chalk.blueBright("code analysis: ") + chalk.bold.greenBright("OK")); - const wasmPaths = await compile(unittestPackage.testCodePaths, options.tempFolder, options.flags); + const wasmPaths = await compile(unittestPackage.testCodePaths, options); console.log(chalk.blueBright("compile test files: ") + chalk.bold.greenBright("OK")); const sourcePaths = unittestPackage.sourceFunctions ? Array.from(unittestPackage.sourceFunctions.keys()) : []; diff --git a/src/interface.ts b/src/interface.ts index 85691ee..da44f0e 100644 --- a/src/interface.ts +++ b/src/interface.ts @@ -213,6 +213,8 @@ export interface TestOption { mode: OutputMode | OutputMode[]; warnLimit?: number; errorLimit?: number; + + isolated: boolean; } export type OutputMode = "html" | "json" | "table"; diff --git a/tests/e2e/isolated-cli/as-test.config.js b/tests/e2e/isolated-cli/as-test.config.js new file mode 100644 index 0000000..e741d9a --- /dev/null +++ b/tests/e2e/isolated-cli/as-test.config.js @@ -0,0 +1,13 @@ +import path from "node:path"; + +const __dirname = path.dirname(new URL(import.meta.url).pathname); + +/** + * @type {import("../../../dist/interface.d.ts").TestOption} + */ +export default { + include: [__dirname], + temp: path.join(__dirname, "tmp"), + output: path.join(__dirname, "tmp"), + mode: [], +}; diff --git a/tests/e2e/isolated-cli/env.ts b/tests/e2e/isolated-cli/env.ts new file mode 100644 index 0000000..b6f0a54 --- /dev/null +++ b/tests/e2e/isolated-cli/env.ts @@ -0,0 +1,5 @@ +class Fn { + raw: (() => void) | null = null; +} + +export let fn = new Fn(); diff --git a/tests/e2e/isolated-cli/stdout.txt b/tests/e2e/isolated-cli/stdout.txt new file mode 100644 index 0000000..c459142 --- /dev/null +++ b/tests/e2e/isolated-cli/stdout.txt @@ -0,0 +1,6 @@ +code analysis: OK +compile test files: OK +instrument: OK +execute test files: OK + +test case: 1/1 (success/total) diff --git a/tests/e2e/isolated-cli/succeed_0.test.ts b/tests/e2e/isolated-cli/succeed_0.test.ts new file mode 100644 index 0000000..576472d --- /dev/null +++ b/tests/e2e/isolated-cli/succeed_0.test.ts @@ -0,0 +1,12 @@ +import { test, expect } from "../../../assembly"; +import { fn } from "./env"; + +test("succeed 0", () => { + if (fn.raw == null) { + fn.raw = () => { + expect(true).equal(true); + }; + } else { + fn.raw(); + } +}); diff --git a/tests/e2e/isolated-cli/succeed_1.test.ts b/tests/e2e/isolated-cli/succeed_1.test.ts new file mode 100644 index 0000000..64bee64 --- /dev/null +++ b/tests/e2e/isolated-cli/succeed_1.test.ts @@ -0,0 +1,12 @@ +import { test, expect } from "../../../assembly"; +import { fn } from "./env"; + +test("succeed_1", () => { + if (fn.raw == null) { + fn.raw = () => { + expect(true).equal(true); + }; + } else { + fn.raw(); + } +}); diff --git a/tests/e2e/isolated-cli/tsconfig.json b/tests/e2e/isolated-cli/tsconfig.json new file mode 100644 index 0000000..798b474 --- /dev/null +++ b/tests/e2e/isolated-cli/tsconfig.json @@ -0,0 +1,4 @@ +{ + "extends": "assemblyscript/std/assembly.json", + "include": ["./**/*.ts"] +} diff --git a/tests/e2e/isolated-false/as-test.config.js b/tests/e2e/isolated-false/as-test.config.js new file mode 100644 index 0000000..595299a --- /dev/null +++ b/tests/e2e/isolated-false/as-test.config.js @@ -0,0 +1,14 @@ +import path from "node:path"; + +const __dirname = path.dirname(new URL(import.meta.url).pathname); + +/** + * @type {import("../../../dist/interface.d.ts").TestOption} + */ +export default { + include: [__dirname], + temp: path.join(__dirname, "tmp"), + output: path.join(__dirname, "tmp"), + mode: [], + isolated: false, +}; diff --git a/tests/e2e/isolated-false/env.ts b/tests/e2e/isolated-false/env.ts new file mode 100644 index 0000000..b6f0a54 --- /dev/null +++ b/tests/e2e/isolated-false/env.ts @@ -0,0 +1,5 @@ +class Fn { + raw: (() => void) | null = null; +} + +export let fn = new Fn(); diff --git a/tests/e2e/isolated-false/stdout.txt b/tests/e2e/isolated-false/stdout.txt new file mode 100644 index 0000000..c459142 --- /dev/null +++ b/tests/e2e/isolated-false/stdout.txt @@ -0,0 +1,6 @@ +code analysis: OK +compile test files: OK +instrument: OK +execute test files: OK + +test case: 1/1 (success/total) diff --git a/tests/e2e/isolated-false/succeed_0.test.ts b/tests/e2e/isolated-false/succeed_0.test.ts new file mode 100644 index 0000000..576472d --- /dev/null +++ b/tests/e2e/isolated-false/succeed_0.test.ts @@ -0,0 +1,12 @@ +import { test, expect } from "../../../assembly"; +import { fn } from "./env"; + +test("succeed 0", () => { + if (fn.raw == null) { + fn.raw = () => { + expect(true).equal(true); + }; + } else { + fn.raw(); + } +}); diff --git a/tests/e2e/isolated-false/succeed_1.test.ts b/tests/e2e/isolated-false/succeed_1.test.ts new file mode 100644 index 0000000..64bee64 --- /dev/null +++ b/tests/e2e/isolated-false/succeed_1.test.ts @@ -0,0 +1,12 @@ +import { test, expect } from "../../../assembly"; +import { fn } from "./env"; + +test("succeed_1", () => { + if (fn.raw == null) { + fn.raw = () => { + expect(true).equal(true); + }; + } else { + fn.raw(); + } +}); diff --git a/tests/e2e/isolated-false/tsconfig.json b/tests/e2e/isolated-false/tsconfig.json new file mode 100644 index 0000000..798b474 --- /dev/null +++ b/tests/e2e/isolated-false/tsconfig.json @@ -0,0 +1,4 @@ +{ + "extends": "assemblyscript/std/assembly.json", + "include": ["./**/*.ts"] +} diff --git a/tests/e2e/isolated-true/as-test.config.js b/tests/e2e/isolated-true/as-test.config.js new file mode 100644 index 0000000..7d0cc93 --- /dev/null +++ b/tests/e2e/isolated-true/as-test.config.js @@ -0,0 +1,14 @@ +import path from "node:path"; + +const __dirname = path.dirname(new URL(import.meta.url).pathname); + +/** + * @type {import("../../../dist/interface.d.ts").TestOption} + */ +export default { + include: [__dirname], + temp: path.join(__dirname, "tmp"), + output: path.join(__dirname, "tmp"), + mode: [], + isolated: true, +}; diff --git a/tests/e2e/isolated-true/env.ts b/tests/e2e/isolated-true/env.ts new file mode 100644 index 0000000..b6f0a54 --- /dev/null +++ b/tests/e2e/isolated-true/env.ts @@ -0,0 +1,5 @@ +class Fn { + raw: (() => void) | null = null; +} + +export let fn = new Fn(); diff --git a/tests/e2e/isolated-true/stdout.txt b/tests/e2e/isolated-true/stdout.txt new file mode 100644 index 0000000..0292b1e --- /dev/null +++ b/tests/e2e/isolated-true/stdout.txt @@ -0,0 +1,6 @@ +code analysis: OK +compile test files: OK +instrument: OK +execute test files: OK + +test case: 0/0 (success/total) diff --git a/tests/e2e/isolated-true/succeed_0.test.ts b/tests/e2e/isolated-true/succeed_0.test.ts new file mode 100644 index 0000000..576472d --- /dev/null +++ b/tests/e2e/isolated-true/succeed_0.test.ts @@ -0,0 +1,12 @@ +import { test, expect } from "../../../assembly"; +import { fn } from "./env"; + +test("succeed 0", () => { + if (fn.raw == null) { + fn.raw = () => { + expect(true).equal(true); + }; + } else { + fn.raw(); + } +}); diff --git a/tests/e2e/isolated-true/succeed_1.test.ts b/tests/e2e/isolated-true/succeed_1.test.ts new file mode 100644 index 0000000..64bee64 --- /dev/null +++ b/tests/e2e/isolated-true/succeed_1.test.ts @@ -0,0 +1,12 @@ +import { test, expect } from "../../../assembly"; +import { fn } from "./env"; + +test("succeed_1", () => { + if (fn.raw == null) { + fn.raw = () => { + expect(true).equal(true); + }; + } else { + fn.raw(); + } +}); diff --git a/tests/e2e/isolated-true/tsconfig.json b/tests/e2e/isolated-true/tsconfig.json new file mode 100644 index 0000000..798b474 --- /dev/null +++ b/tests/e2e/isolated-true/tsconfig.json @@ -0,0 +1,4 @@ +{ + "extends": "assemblyscript/std/assembly.json", + "include": ["./**/*.ts"] +} diff --git a/tests/e2e/run.js b/tests/e2e/run.js index 2065490..015c28f 100644 --- a/tests/e2e/run.js +++ b/tests/e2e/run.js @@ -59,6 +59,10 @@ runEndToEndTest("printLogInFailedInfo", "", (error, stdout, stderr) => { assert(error.code === 1); }); +runEndToEndTest("isolated-true", "", (error, stdout, stderr) => {}); +runEndToEndTest("isolated-false", "", (error, stdout, stderr) => {}); +runEndToEndTest("isolated-cli", "--isolated false", (error, stdout, stderr) => {}); + runEndToEndTest( "testFiles", "--testFiles tests/e2e/testFiles/succeed_0.test.ts tests/e2e/testFiles/succeed_1.test.ts", From 63b860d32cfdf3ce29373ffbca6aeb0e3cacdf5e Mon Sep 17 00:00:00 2001 From: Congcong Cai Date: Tue, 30 Sep 2025 15:19:13 +0800 Subject: [PATCH 2/5] fix --- as-test.config.js | 2 ++ src/core/compile.ts | 14 ++++++-------- tests/as/mock.test.ts | 1 - tests/ts/test/core/instrument.test.ts | 2 +- tests/ts/test/core/throwError.test.ts | 2 +- 5 files changed, 10 insertions(+), 11 deletions(-) diff --git a/as-test.config.js b/as-test.config.js index 7cc4f00..cd16a9e 100644 --- a/as-test.config.js +++ b/as-test.config.js @@ -25,4 +25,6 @@ export default { /** optional: test result output format, default "table" */ mode: ["html", "json", "table"], + + isolated: false, }; diff --git a/src/core/compile.ts b/src/core/compile.ts index ff06816..f7b367f 100644 --- a/src/core/compile.ts +++ b/src/core/compile.ts @@ -3,13 +3,11 @@ import { findRoot } from "../utils/pathResolver.js"; import { ascMain } from "../utils/ascWrapper.js"; import { TestOption } from "../interface.js"; -export async function compile(testCodePaths: string[], option: TestOption): Promise { +export type CompileOption = Pick; + +export async function compile(testCodePaths: string[], option: CompileOption): Promise { const { isolated } = option; - if (!isolated) { - return [await unifiedCompile(testCodePaths, option)]; - } else { - return separatedCompile(testCodePaths, option); - } + return isolated ? await separatedCompile(testCodePaths, option) : [await unifiedCompile(testCodePaths, option)]; } function getNewPath(newFolder: string, oldFolder: string, srcPath: string): string { @@ -36,7 +34,7 @@ function getAscArgs(sources: string[], outputWasm: string, outputWat: string, fl return ascArgv; } -async function unifiedCompile(testCodePaths: string[], option: TestOption): Promise { +async function unifiedCompile(testCodePaths: string[], option: CompileOption): Promise { const { outputFolder, flags } = option; const outputWasm = join(outputFolder, "test.wasm"); const outputWat = join(outputFolder, "test.wat"); @@ -45,7 +43,7 @@ async function unifiedCompile(testCodePaths: string[], option: TestOption): Prom return outputWasm; } -async function separatedCompile(testCodePaths: string[], option: TestOption): Promise { +async function separatedCompile(testCodePaths: string[], option: CompileOption): Promise { const { outputFolder, flags } = option; const wasm: string[] = []; const root = findRoot(testCodePaths); diff --git a/tests/as/mock.test.ts b/tests/as/mock.test.ts index c1992c7..b2aa24e 100644 --- a/tests/as/mock.test.ts +++ b/tests/as/mock.test.ts @@ -18,7 +18,6 @@ describe("mock test", () => { }); test("function with functionRef, but not mocked", () => { - expect(add.index).equal(2); expect(add(1, 1)).equal(2); }); diff --git a/tests/ts/test/core/instrument.test.ts b/tests/ts/test/core/instrument.test.ts index b8e1ae9..922030d 100644 --- a/tests/ts/test/core/instrument.test.ts +++ b/tests/ts/test/core/instrument.test.ts @@ -9,7 +9,7 @@ const fixturePath = join(fileURLToPath(new URL(".", import.meta.url)), "..", ".. const outputDir = relative(process.cwd(), join(tmpdir(), "assemblyscript-unittest-framework")); test("Instrument", async () => { - await compile([fixturePath], outputDir, "--memoryBase 16 --exportTable"); + await compile([fixturePath], { outputFolder: outputDir, flags: "--memoryBase 16 --exportTable", isolated: false }); const base = join(outputDir, "constructor"); const wasmPath = join(outputDir, "constructor.wasm"); const sourceCodePath = "tests/ts/fixture/constructor.ts"; diff --git a/tests/ts/test/core/throwError.test.ts b/tests/ts/test/core/throwError.test.ts index eaf1c93..c533e9a 100644 --- a/tests/ts/test/core/throwError.test.ts +++ b/tests/ts/test/core/throwError.test.ts @@ -22,6 +22,6 @@ test("transform error", async () => { test("compile error", async () => { await expect(async () => { - await compile(["non-exist.ts"], "mockFolder", ""); + await compile(["non-exist.ts"], { outputFolder: "mockFolder", flags: "", isolated: false }); }).rejects.toThrow("mock asc.main() error"); }); From f5033a3e02b24dbeb55e6801ce6d1172d36d48c5 Mon Sep 17 00:00:00 2001 From: Congcong Cai Date: Tue, 30 Sep 2025 15:23:36 +0800 Subject: [PATCH 3/5] rl --- docs/release-note.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/release-note.md b/docs/release-note.md index a700962..c1d4330 100644 --- a/docs/release-note.md +++ b/docs/release-note.md @@ -4,7 +4,8 @@ 🚀 Highlight Features -- improved the performances +- Improved the as-test performances. +- Introduce new features `isolated: false` to significantly reduce test execution time in large projects. ([#73](https://github.com/wasm-ecosystem/assemblyscript-unittest-framework/pull/73)) ## 1.3.1 From a0fdc4754d314a907cdd3e74c5f53725f912481d Mon Sep 17 00:00:00 2001 From: Congcong Cai Date: Tue, 30 Sep 2025 15:39:23 +0800 Subject: [PATCH 4/5] fix --- tests/ts/test/core/instrument.test.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/tests/ts/test/core/instrument.test.ts b/tests/ts/test/core/instrument.test.ts index 922030d..18f98a3 100644 --- a/tests/ts/test/core/instrument.test.ts +++ b/tests/ts/test/core/instrument.test.ts @@ -1,4 +1,5 @@ -import fs from "fs-extra"; +import { existsSync, readFileSync, rmdirSync } from "node:fs"; +import { ensureDir } from "fs-extra"; import { join, relative } from "node:path"; import { tmpdir } from "node:os"; import { fileURLToPath, URL } from "node:url"; @@ -9,7 +10,9 @@ const fixturePath = join(fileURLToPath(new URL(".", import.meta.url)), "..", ".. const outputDir = relative(process.cwd(), join(tmpdir(), "assemblyscript-unittest-framework")); test("Instrument", async () => { - await compile([fixturePath], { outputFolder: outputDir, flags: "--memoryBase 16 --exportTable", isolated: false }); + rmdirSync(outputDir, { recursive: true }); + await ensureDir(outputDir); + await compile([fixturePath], { outputFolder: outputDir, flags: "--memoryBase 16 --exportTable", isolated: true }); const base = join(outputDir, "constructor"); const wasmPath = join(outputDir, "constructor.wasm"); const sourceCodePath = "tests/ts/fixture/constructor.ts"; @@ -24,9 +27,9 @@ test("Instrument", async () => { expect(result.instrumentedWasm).toEqual(instrumentedWasm); expect(result.debugInfo).toEqual(debugInfo); expect(result.expectInfo).toEqual(expectInfo); - expect(fs.existsSync(instrumentedWasm)).toEqual(true); - expect(fs.existsSync(debugInfo)).toEqual(true); - expect(fs.existsSync(expectInfo)).toEqual(true); - const debugInfoContent = fs.readFileSync(debugInfo, { encoding: "utf8" }); + expect(existsSync(instrumentedWasm)).toEqual(true); + expect(existsSync(debugInfo)).toEqual(true); + expect(existsSync(expectInfo)).toEqual(true); + const debugInfoContent = readFileSync(debugInfo, { encoding: "utf8" }); expect(debugInfoContent).toMatchSnapshot(); }); From b5ac40c14dd1ed643799fa3f27aa7b9f6b3254cc Mon Sep 17 00:00:00 2001 From: Congcong Cai Date: Tue, 30 Sep 2025 15:54:23 +0800 Subject: [PATCH 5/5] fix --- tests/ts/test/core/instrument.test.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/tests/ts/test/core/instrument.test.ts b/tests/ts/test/core/instrument.test.ts index 18f98a3..6989ef4 100644 --- a/tests/ts/test/core/instrument.test.ts +++ b/tests/ts/test/core/instrument.test.ts @@ -1,5 +1,4 @@ -import { existsSync, readFileSync, rmdirSync } from "node:fs"; -import { ensureDir } from "fs-extra"; +import { existsSync, mkdirSync, readFileSync, rmdirSync } from "node:fs"; import { join, relative } from "node:path"; import { tmpdir } from "node:os"; import { fileURLToPath, URL } from "node:url"; @@ -9,9 +8,13 @@ import { instrument } from "../../../../src/core/instrument.js"; const fixturePath = join(fileURLToPath(new URL(".", import.meta.url)), "..", "..", "fixture", "constructor.ts"); const outputDir = relative(process.cwd(), join(tmpdir(), "assemblyscript-unittest-framework")); +function cleanDirSync(path: string) { + if (existsSync(path)) rmdirSync(path, { recursive: true }); + mkdirSync(path); +} + test("Instrument", async () => { - rmdirSync(outputDir, { recursive: true }); - await ensureDir(outputDir); + cleanDirSync(outputDir); await compile([fixturePath], { outputFolder: outputDir, flags: "--memoryBase 16 --exportTable", isolated: true }); const base = join(outputDir, "constructor"); const wasmPath = join(outputDir, "constructor.wasm");