@as-pect/cli

中文文档
9.0.0发布于 2026/06/18MITTypeScriptES Module近 30 天下载 1.3万

Write AssemblyScript tests at blazing fast speeds

原始使用文档
文档目录8 节
  1. Documentation
  2. Test session vocabulary
  3. CLI filters
  4. Reporter output formats
  5. Code coverage
  6. AssemblyScript compiler options
  7. Contributors
  8. Special Thanks

jtenner/as-pect - @as-pect/cli

Test Coverage Status Changesets

Write your module in AssemblyScript and get blazing fast bootstrapped tests with WebAssembly speeds!

Documentation

To view the documentation, it's located here on the gitbook. If there are any issues with the docs, please feel free to file an issue!

Test session vocabulary

The CLI drives each Test session from configuration to report output. as-pect.config.js defines the Test session entry plan, JavaScript-side Wasm host imports through instantiate(...), reporters, WASI options, coverage globs, and output behavior. as-pect.asconfig.json remains the AssemblyScript compiler configuration used to produce compiler output for each planned entry.

Snapshot file paths and write modes are part of the Test session snapshot plan. Snapshot pass/fail and update decisions come from the Snapshot lifecycle in @as-pect/snapshots before the CLI writes files.

CLI filters

Use asp --test <regex> or asp -t <regex> to run tests whose names match a regular expression. Use asp --group <regex> or asp -g <regex> to run groups whose names match a regular expression. These options consume the following argument as the filter pattern; remaining positional arguments are still treated as Test session entry globs.

Reporter output formats

Use asp --junit to write JUnit XML files next to test entries for CI systems that ingest JUnit-style unit test reports. You can also install/select the package explicitly with asp --reporter @as-pect/junit-reporter. The reporter maps Suite report facts to common testsuite, testcase, failure, error, skipped, and system-out elements.

Use asp --ctrf to write CTRF JSON files next to test entries for tools that ingest the Common Test Report Format. You can also install/select the package explicitly with asp --reporter @as-pect/ctrf-reporter. CTRF output uses .ctrf.json files, includes reportFormat, specVersion, results.tool, results.summary, and results.tests, and nests as-pect-only facts under extra.asPect.

Use asp --json for the existing as-pect legacy JSON v1 array format. It remains separate from CTRF so existing JSON consumers keep their current contract. See ../json-reporter/readme.md for the full field shape.

@as-pect/csv-reporter writes the as-pect CSV v1 tabular export for spreadsheet-style workflows. It preserves the column order Group, Name, Ran, Negated, Pass, Runtime, Message, Actual, Expected and does not claim CSV as a cross-tool test-result standard. See ../csv-reporter/readme.md for the full column and value contract.

Code coverage

as-pect uses as-covers for AssemblyScript line and branch coverage. The asp --init template already creates an as-pect.asconfig.json with two compiler targets:

  • noCoverage, which runs only the @as-pect/transform transform.
  • coverage, which adds the @as-covers/assembly support library and the @as-covers/transform transform before @as-pect/transform.

Enable coverage by uncommenting or adding the coverage glob list in as-pect.config.js:

export default {
  // ...the rest of your as-pect config
  coverage: ["assembly/**/*.ts"],
};

When coverage is non-empty, asp compiles tests with the coverage target, installs the as-covers imports, registers each test module with as-covers, and prints a coverage report after the run.

If you maintain a custom as-pect.asconfig.json, make sure it includes the coverage target shape from the init template:

{
  "targets": {
    "coverage": {
      "lib": ["./node_modules/@as-covers/assembly/index.ts"],
      "transform": ["@as-covers/transform", "@as-pect/transform"]
    },
    "noCoverage": {
      "transform": ["@as-pect/transform"]
    }
  }
}

AssemblyScript compiler options

as-pect.config.js configures the Test session entry plan, Wasm host imports, reporters, WASI, coverage globs, and output behavior. It is not an asc compiler configuration file.

Put AssemblyScript compiler options, including the asc --lib option, in as-pect.asconfig.json. asp invokes the compiler with that file and selects either the noCoverage target or the coverage target, so target-specific options must be present on the target that will run.

For example, add custom library components to tests like this:

{
  "targets": {
    "coverage": {
      "lib": ["./assembly/test-lib", "./node_modules/@as-covers/assembly/index.ts"],
      "transform": ["@as-covers/transform", "@as-pect/transform"]
    },
    "noCoverage": {
      "lib": ["./assembly/test-lib"],
      "transform": ["@as-pect/transform"]
    }
  },
  "options": {
    "exportMemory": true,
    "outFile": "output.wasm",
    "textFile": "output.wat",
    "bindings": "raw",
    "exportStart": "_start",
    "exportRuntime": true,
    "use": ["RTRACE=1"],
    "debug": true,
    "exportTable": true
  },
  "extends": "./asconfig.json",
  "entries": ["./node_modules/@as-pect/assembly/assembly/index.ts"]
}

Keep using as-pect.config.js for JavaScript-side WebAssembly imports through instantiate(...). Use as-pect.asconfig.json for AssemblyScript-side compile-time inputs such as lib, path, transform, and use.

Contributors

To contribute please see CONTRIBUTING.md.

Thanks to @willemneal and @MaxGraey for all their support in making as-pect the best software it can be.

Other Contributors:

Special Thanks

Special thanks to the AssemblyScript team for creating AssemblyScript itself.

版本与发布记录

@as-pect/cli 共发布 61 个版本,首次发布于 2019/07/15;过去 12 个月发布了 1 个版本。

版本发布日期距今
9.0.0latest2026/06/184 个月前
8.1.02023/04/193 年前
8.0.12022/12/133 年前
8.0.02022/11/153 年前
7.0.82022/09/144 年前
7.0.72022/09/024 年前

关于 @as-pect/cli 的常见问题

@as-pect/cli 是什么?

Write AssemblyScript tests at blazing fast speeds

如何安装 @as-pect/cli?

在项目目录运行 npm install @as-pect/cli,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:assemblyscript(^0.28.19)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。它还提供命令行工具 asp、aspect,可以用 npx asp 直接运行。

@as-pect/cli 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@as-pect/cli 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@as-pect/cli 可以商用吗?

@as-pect/cli 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@as-pect/cli 的下载量有多少?

根据 npm 官方下载统计,@as-pect/cli 在 2026/10/07 – 2026/11/05 这 30 天内被下载 13,128 次,日均约 438 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@as-pect/cli 还在维护吗?

最新版本 9.0.0 发布于 2026/06/18(4 个月前);至今共发布 61 个版本,其中过去 12 个月发布了 1 个;首次发布于 2019/07/15。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。