Skip to content

Commit f294c61

Browse files
committed
update config format
1 parent c65401a commit f294c61

File tree

10 files changed

+464
-229
lines changed

10 files changed

+464
-229
lines changed

as-test.config.json

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,12 @@
22
"input": ["./assembly/__tests__/*.spec.ts"],
33
"outDir": "./build",
44
"config": "./asconfig.json",
5-
"suites": [],
6-
"coverage": {
7-
"enabled": true,
8-
"show": false
5+
"plugins": {
6+
"coverage": true
97
},
108
"buildOptions": {
119
"args": ["--transform json-as/transform"],
12-
"wasi": true,
13-
"parallel": true,
14-
"verbose": true
10+
"target": "wasi"
1511
},
1612
"runOptions": {
1713
"runtime": {

asconfig.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,5 @@
2525
"noAssert": false
2626
}
2727
},
28-
"options": {
29-
"bindings": "esm"
30-
}
28+
"options": {}
3129
}

assembly/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Expectation } from "./src/expectation";
44
import { stringify } from "as-console/stringify";
55
import { __COVER, __HASHES, __POINTS } from "as-test/assembly/coverage";
66
import { JSON } from "json-as";
7-
import { Report, SuiteReport, TestReport } from "./reporters/report";
7+
import { Report, SuiteReport, TestReport } from "../reporters/report";
88

99
/**
1010
* Enumeration representing the verdict of a test case.

assembly/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"extends": "assemblyscript/std/assembly.json",
3-
"include": ["./**/*.ts"],
3+
"include": ["./**/*.ts", "../reporters/report.ts"],
44
"compilerOptions": {
55
/* Visit https://aka.ms/tsconfig to read more about this file */
66
/* Projects */

cli/about.ts

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
import chalk from "chalk";
2+
3+
export function about(): void {
4+
5+
console.log(
6+
chalk.bold.blueBright("as-test") +
7+
" is a testing framework for AssemblyScript. " +
8+
chalk.dim("(v" + version + ")") +
9+
"\n",
10+
);
11+
12+
console.log(
13+
chalk.bold("Usage: as-test") +
14+
" " +
15+
chalk.dim("<command>") +
16+
" " +
17+
chalk.bold.blueBright("[...flags]") +
18+
" " +
19+
chalk.bold("[...args]") +
20+
" " +
21+
chalk.dim("(alias: ast)") +
22+
"\n",
23+
);
24+
25+
console.log(chalk.bold("Commands:"));
26+
console.log(
27+
" " +
28+
chalk.bold.blueBright("run") +
29+
" " +
30+
chalk.dim("<my-test.spec.ts>") +
31+
" " +
32+
"Run unit tests with selected runtime",
33+
);
34+
console.log(
35+
" " +
36+
chalk.bold.blueBright("build") +
37+
" " +
38+
chalk.dim("<my-test.spec.ts>") +
39+
" " +
40+
"Build unit tests and compile",
41+
);
42+
console.log(
43+
" " +
44+
chalk.bold.blueBright("test") +
45+
" " +
46+
chalk.dim("<my-test.spec.ts>") +
47+
" " +
48+
"Build and run unit tests with selected runtime" +
49+
"\n",
50+
);
51+
52+
console.log(
53+
" " +
54+
chalk.bold.magentaBright("init") +
55+
" " +
56+
chalk.strikethrough.dim("") +
57+
" " +
58+
"Initialize an empty testing template",
59+
);
60+
console.log(
61+
" " +
62+
chalk.strikethrough.bold.magentaBright("config") +
63+
" " +
64+
chalk.strikethrough.dim("as-test.config.json") +
65+
" " +
66+
"Specify the configuration file",
67+
);
68+
console.log(
69+
" " +
70+
chalk.strikethrough.bold.magentaBright("reporter") +
71+
" " +
72+
chalk.strikethrough.dim("<tap>") +
73+
" " +
74+
"Specify the test reporter to use",
75+
);
76+
console.log(
77+
" " +
78+
chalk.strikethrough.bold.magentaBright("use") +
79+
" " +
80+
chalk.strikethrough.dim("wasmtime") +
81+
" " +
82+
"Specify the runtime to use" +
83+
"\n",
84+
);
85+
86+
console.log(chalk.bold("Flags:"));
87+
88+
console.log(
89+
" " +
90+
chalk.strikethrough.dim("run") +
91+
" " +
92+
chalk.strikethrough.bold.blue("--coverage") +
93+
" " +
94+
"Use code coverage",
95+
);
96+
console.log(
97+
" " +
98+
chalk.strikethrough.dim("run") +
99+
" " +
100+
chalk.strikethrough.bold.blue("--snapshot") +
101+
" " +
102+
"Take a snapshot of the tests",
103+
);
104+
console.log(
105+
" " +
106+
chalk.strikethrough.dim("use") +
107+
" " +
108+
chalk.strikethrough.bold.blue("--list") +
109+
" " +
110+
"List supported runtimes",
111+
);
112+
console.log(
113+
" " +
114+
chalk.strikethrough.dim("reporter") +
115+
" " +
116+
chalk.strikethrough.bold.blue("--list") +
117+
" " +
118+
"List supported reporters",
119+
);
120+
console.log(
121+
" " +
122+
chalk.strikethrough.dim("<command>") +
123+
" " +
124+
chalk.strikethrough.bold.blue("--help") +
125+
" " +
126+
"Print info about command" +
127+
"\n",
128+
);
129+
130+
console.log(
131+
chalk.dim(
132+
"If your using this, consider dropping a star, it would help a lot!",
133+
) + "\n",
134+
);
135+
136+
console.log(
137+
"View the repo: " +
138+
chalk.magenta("https://github.com/JairusSW/as-test"),
139+
);
140+
console.log(
141+
"View the docs: " +
142+
chalk.strikethrough.blue("https://docs.jairus.dev/as-test"),
143+
);
144+
}

cli/build.ts

Lines changed: 61 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,11 @@ import { exec } from "child_process";
66
import { formatTime } from "./util.js";
77
import * as path from "path";
88

9+
const CONFIG_PATH = path.join(process.cwd(), "./as-test.config.json");
10+
const PKG_PATH = path.join(process.cwd(), "./package.json");
911
export async function build(args: string[]) {
10-
const CONFIG_PATH = path.join(process.cwd(), "./as-test.config.json");
11-
let config: Config;
12-
if (!existsSync(CONFIG_PATH)) {
13-
console.log(
14-
chalk.bgMagentaBright(" WARN ") +
15-
chalk.dim(":") +
16-
" Could not locate config file in the current directory! Continuing with default config." +
17-
"\n",
18-
);
19-
config = new Config();
20-
} else {
21-
config = Object.assign(
22-
new Config(),
23-
JSON.parse(readFileSync(CONFIG_PATH).toString()),
24-
) as Config;
25-
console.log(chalk.dim("Loading config from: " + CONFIG_PATH) + "\n");
26-
}
12+
let config = loadConfig();
13+
2714
const ASCONFIG_PATH = path.join(process.cwd(), config.config);
2815
if (!existsSync(ASCONFIG_PATH)) {
2916
console.log(
@@ -33,41 +20,8 @@ export async function build(args: string[]) {
3320
"\n",
3421
);
3522
}
36-
const pkg = JSON.parse(readFileSync("./package.json").toString()) as {
37-
dependencies: string[] | null;
38-
devDependencies: string[] | null;
39-
peerDependencies: string[] | null;
40-
};
41-
let buildCommands: string[] = [];
4223

43-
if (config.buildOptions.wasi) {
44-
if (!existsSync("./node_modules/@assemblyscript/wasi-shim/asconfig.json")) {
45-
console.log(
46-
chalk.bgRed(" ERROR ") +
47-
chalk.dim(":") +
48-
" " +
49-
"could not find @assemblyscript/wasi-shim! Add it to your dependencies to run with WASI!",
50-
);
51-
process.exit(1);
52-
}
53-
if (
54-
pkg.dependencies &&
55-
!Object.keys(pkg.dependencies).includes("@assemblyscript/wasi-shim") &&
56-
pkg.devDependencies &&
57-
!Object.keys(pkg.devDependencies).includes("@assemblyscript/wasi-shim") &&
58-
pkg.peerDependencies &&
59-
!Object.keys(pkg.peerDependencies).includes(
60-
"@assemblyscript/wasi-shim",
61-
) &&
62-
existsSync("./node_modules/@assemblyscript/wasi-shim/asconfig.json")
63-
) {
64-
console.log(
65-
chalk.bold.bgMagentaBright(" WARN ") +
66-
chalk.dim(": @assemblyscript/wasi-shim") +
67-
" is not included in project dependencies!",
68-
);
69-
}
70-
}
24+
verifyPackagesInstalled(config);
7125

7226
let packageManagerCommand = "npx";
7327
if (
@@ -154,3 +108,59 @@ export async function build(args: string[]) {
154108
);
155109
}
156110
}
111+
112+
function verifyPackagesInstalled(config: Config): void {
113+
const pkg = JSON.parse(readFileSync(PKG_PATH).toString()) as {
114+
dependencies: string[] | null;
115+
devDependencies: string[] | null;
116+
peerDependencies: string[] | null;
117+
};
118+
119+
if (config.buildOptions.wasi) {
120+
if (!existsSync("./node_modules/@assemblyscript/wasi-shim/asconfig.json")) {
121+
console.log(
122+
chalk.bgRed(" ERROR ") +
123+
chalk.dim(":") +
124+
" " +
125+
"could not find @assemblyscript/wasi-shim! Add it to your dependencies to run with WASI!",
126+
);
127+
process.exit(1);
128+
}
129+
if (
130+
pkg.dependencies &&
131+
!Object.keys(pkg.dependencies).includes("@assemblyscript/wasi-shim") &&
132+
pkg.devDependencies &&
133+
!Object.keys(pkg.devDependencies).includes("@assemblyscript/wasi-shim") &&
134+
pkg.peerDependencies &&
135+
!Object.keys(pkg.peerDependencies).includes(
136+
"@assemblyscript/wasi-shim",
137+
) &&
138+
existsSync("./node_modules/@assemblyscript/wasi-shim/asconfig.json")
139+
) {
140+
console.log(
141+
chalk.bold.bgMagentaBright(" WARN ") +
142+
chalk.dim(": @assemblyscript/wasi-shim") +
143+
" is not included in project dependencies!",
144+
);
145+
}
146+
}
147+
}
148+
149+
function loadConfig(): Config {
150+
if (!existsSync(CONFIG_PATH)) {
151+
console.log(
152+
chalk.bgMagentaBright(" WARN ") +
153+
chalk.dim(":") +
154+
" Could not locate config file in the current directory! Continuing with default config." +
155+
"\n",
156+
);
157+
console.log(chalk.dim("Using default configuration") + "\n");
158+
return new Config();
159+
} else {
160+
console.log(chalk.dim("Loading config from: " + CONFIG_PATH) + "\n");
161+
return Object.assign(
162+
new Config(),
163+
JSON.parse(readFileSync(CONFIG_PATH).toString()),
164+
) as Config;
165+
}
166+
}

0 commit comments

Comments
 (0)