Skip to content

Commit b53f4ff

Browse files
nguterresnNuno NogueiraHerrCai0907
authored
Added flags option to the precompile step (#27)
Co-authored-by: Nuno Nogueira <[email protected]> Co-authored-by: Congcong Cai <[email protected]>
1 parent 72c3400 commit b53f4ff

File tree

4 files changed

+12
-13
lines changed

4 files changed

+12
-13
lines changed

src/core/precompile.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export async function precompile(
1414
includes: string[],
1515
excludes: string[],
1616
testcases: string[] | undefined,
17+
flags: string,
1718
transformFunction = join(projectRoot, "transform", "listFunctions.mjs")
1819
): Promise<UnittestPackage> {
1920
// if specify testcases, use testcases for unittest
@@ -23,7 +24,7 @@ export async function precompile(
2324
const sourceCodePaths = getRelatedFiles(includes, excludes, (path: string) => !path.endsWith(".test.ts"));
2425
const sourceCodeTransforms: Promise<void>[] = [];
2526
for (const sourceCodePath of sourceCodePaths.values()) {
26-
sourceCodeTransforms.push(transform(sourceCodePath, transformFunction));
27+
sourceCodeTransforms.push(transform(sourceCodePath, transformFunction, flags));
2728
}
2829
await Promise.all(sourceCodeTransforms);
2930

@@ -55,15 +56,13 @@ export function getRelatedFiles(includes: string[], excludes: string[], filter:
5556
return result;
5657
}
5758

58-
async function transform(sourceCodePath: string, transformFunction: string) {
59-
const { error, stderr } = await main([
60-
sourceCodePath,
61-
"--noEmit",
62-
"--disableWarning",
63-
"--transform",
64-
transformFunction,
65-
"-O0",
66-
]);
59+
async function transform(sourceCodePath: string, transformFunction: string, flags: string) {
60+
let ascArgv = [sourceCodePath, "--noEmit", "--disableWarning", "--transform", transformFunction, "-O0"];
61+
if (flags) {
62+
const argv = flags.split(" ");
63+
ascArgv = ascArgv.concat(argv);
64+
}
65+
const { error, stderr } = await main(ascArgv);
6766
if (error) {
6867
// eslint-disable-next-line @typescript-eslint/no-base-to-string
6968
console.error(stderr.toString());

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export type OutputMode = "html" | "json" | "table";
7575
export async function start_unit_test(fo: FileOption, to: TestOption, oo: OutputOption): Promise<boolean> {
7676
emptydirSync(oo.outputFolder);
7777
emptydirSync(oo.tempFolder);
78-
const unittestPackage = await precompile(fo.includes, fo.excludes, fo.testcases);
78+
const unittestPackage = await precompile(fo.includes, fo.excludes, fo.testcases, to.flags);
7979
console.log(chalk.blueBright("code analysis: ") + chalk.bold.greenBright("OK"));
8080
const wasmPaths = await compile(unittestPackage.testCodePaths, oo.tempFolder, to.flags);
8181
console.log(chalk.blueBright("compile testcases: ") + chalk.bold.greenBright("OK"));

tests/ts/test/core/precompile.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { projectRoot } from "../../../../src/utils/projectRoot.js";
44

55
test("listFunction transform", async () => {
66
const transformFunction = join(projectRoot, "transform", "listFunctions.mjs");
7-
const unittestPackages = await precompile(["tests/ts/fixture/transformFunction.ts"], [], [], transformFunction);
7+
const unittestPackages = await precompile(["tests/ts/fixture/transformFunction.ts"], [], [], "", transformFunction);
88
expect(unittestPackages.testCodePaths).toEqual([]);
99
expect(unittestPackages.sourceFunctions).toMatchSnapshot();
1010
});

tests/ts/test/core/throwError.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ test("transform error", async () => {
2020
const transformFunction = join(projectRoot, "transform", "listFunctions.mjs");
2121
expect(jest.isMockFunction(main)).toBeTruthy();
2222
await expect(async () => {
23-
await precompile(["tests/ts/fixture/transformFunction.ts"], [], [], transformFunction);
23+
await precompile(["tests/ts/fixture/transformFunction.ts"], [], [], "", transformFunction);
2424
}).rejects.toThrow("mock asc.main() error");
2525
});
2626

0 commit comments

Comments
 (0)