Skip to content
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
7 changes: 7 additions & 0 deletions .github/workflows/ci-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ jobs:
- run: npm run lint
- run: npm run test

- working-directory: ./example
run: |
set -e
npm ci
npm run test
npm run test:cjs

- name: verify ccache stats
run: |
set -e
Expand Down
29 changes: 29 additions & 0 deletions config.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { Imports } from "./dist/interface.d.ts";

export type OutputMode = "html" | "json" | "table";

export declare class Config {
/** Files to include in testing and coverage statistics */
include: string[];
/** Files to exclude from testing and coverage statistics, has higher priority than include */
exclude?: string[];

/** whether to collect coverage information, default is true */
collectCoverage?: boolean;

/** create an wasm instance for each test files. default is false (will be true in next major version) */
isolated?: boolean;

/** assemblyscript compile flag, default is --exportStart _start --sourceMap --debug -O0 */
flags?: string;
imports?: Imports;

/** template folder path, default "./coverage" */
temp?: string;

/** report folder path, default "./coverage" */
output?: string;

/** output report mode, default is "table" */
mode?: OutputMode | OutputMode[];
}
50 changes: 2 additions & 48 deletions docs/api-documents/configuration.md
Original file line number Diff line number Diff line change
@@ -1,54 +1,8 @@
## Configuration

This is the template of `as-test.config.js`:
The [template](https://github.com/wasm-ecosystem/assemblyscript-unittest-framework/blob/main/example/as-test.config.js) of `as-test.config.js`

```javascript
module.exports = {
// test related code folder
include: ["source", "tests"],
exclude: [],

/** optional: assemblyscript compile flag, default is --exportStart _start -O0 */
flags: "",

/**
* optional: import functions
* @param {ImportsArgument} runtime
* @returns
*/
imports(runtime) {
return {
env: {
logInfo(ptr, len) {
let buf = runtime.exports!.__getArrayBuffer(ptr);
let str = Buffer.from(buf).toString("utf8");
runtime.framework.log(str); // log to unittest framework
console.log(str); // log to console
},
},
console: {
log(ptr) {
runtime.framework.log(runtime.exports!.__getString(msg));
}
}
builtin: {
getU8FromLinkedMemory(a) {
return 1;
},
},
};
},

/** optional: template file path, default "coverage" */
// temp: "coverage",

/** optional: report file path, default "coverage" */
// output: "coverage",

/** optional: test result output format, default "table" */
// mode: ["html", "json", "table"],
};
```
The [type declaration](https://github.com/wasm-ecosystem/assemblyscript-unittest-framework/blob/main/config.d.ts) of config.

### Imports

Expand Down
2 changes: 2 additions & 0 deletions example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/node_modules
/coverage
14 changes: 3 additions & 11 deletions example/as-test.config.cjs
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
/** @type {import("assemblyscript-unittest-framework/config.d.ts").Config} */
module.exports = {
include: ["example"],
exclude: ["assembly/coverageCollector.ts", "assembly/mock.ts"],
include: ["tests"],
exclude: ["lib"],

/** assemblyscript compile flag, default is --exportStart _start --sourceMap --debug -O0 */
flags: "",

/**
* import functions
* @param {ImportsArgument} runtime
* @returns
*/
imports(runtime) {
return {
env: {
Expand All @@ -20,9 +15,6 @@ module.exports = {
};
},

/** template file path, default "coverage" */
temp: "coverage",

/** report file path, default "coverage" */
output: "coverage",
};
16 changes: 5 additions & 11 deletions example/as-test.config.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
/** @type {import("assemblyscript-unittest-framework/config.d.ts").Config} */
export default {
include: ["example"],
exclude: ["assembly/coverageCollector.ts", "assembly/mock.ts"],
include: ["tests"],
exclude: ["lib"],

/** assemblyscript compile flag, default is --exportStart _start --sourceMap --debug -O0 */
flags: "",

/**
* import functions
* @param {ImportsArgument} runtime
* @returns
*/
imports(runtime) {
return {
env: {
Expand All @@ -20,9 +15,8 @@ export default {
};
},

/** template file path, default "coverage" */
temp: "coverage",

/** report file path, default "coverage" */
output: "coverage",

isolated: false,
};
File renamed without changes.
File renamed without changes.
File renamed without changes.
59 changes: 59 additions & 0 deletions example/package-lock.json

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

11 changes: 11 additions & 0 deletions example/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "example",
"type": "module",
"dependencies": {
"assemblyscript-unittest-framework": "file:.."
},
"scripts": {
"test": "! as-test",
"test:cjs": "! as-test --config as-test.config.js"
}
}
6 changes: 3 additions & 3 deletions example/source.test.ts → example/tests/source.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, test, expect, mock } from "../assembly";
import { log } from "./env";
import { add, Test } from "./source";
import { describe, test, expect, mock } from "assemblyscript-unittest-framework/assembly";
import { log } from "../lib/env";
import { add, Test } from "../assembly/source";

describe("example 1", () => {
test("two plus two is four", () => {
Expand Down
6 changes: 3 additions & 3 deletions example/source2.test.ts → example/tests/source2.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describe, test, expect } from "../assembly";
import { quick_sort } from "./source2";
import { describe, test, expect } from "assemblyscript-unittest-framework/assembly";
import { quick_sort } from "../assembly/source2";

describe("quick_sork", () => {
describe("quick_sort", () => {
test("1", () => {
let d = [1, 2, 3];
quick_sort(d);
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
"lint:as": "npx eslint --config ./assembly/eslint.config.mjs assembly --max-warnings=0",
"lint": "npm run lint:ts && prettier -c .",
"lint:fix:ts": "eslint src transform tests/ts/test --fix && prettier --write .",
"example": "node bin/as-test.js --config example/as-test.config.cjs ; node bin/as-test.js --config example/as-test.config.js",
"docs:dev": "vitepress dev docs",
"docs:build": "vitepress build docs"
},
Expand Down Expand Up @@ -79,11 +78,12 @@
"files": [
"assembly/**/*",
"bin/**/*",
"dist/**/*",
"build_wasm/bin/wasm-instrumentation.js",
"config.d.ts",
"dist/**/*",
"docs/**/*",
"transform/**/*",
"resource/**/*",
"transform/**/*",
"LICENSE",
"README.md"
]
Expand Down