@briebug/jest-schematic

中文文档
6.0.0发布于 2022/12/29MITCommonJS近 30 天下载 2.1万

Schematic to add jest to an Angular CLI project

原始使用文档
文档目录12 节
  1. Usage 🚀
  2. Optionally: install globally
  3. Issues 🧐
  4. Jest issues
  5. Learning Resources 📚
  6. Development 🛠
  7. Getting started
  8. Test schematic changes against a sandbox app
  9. Reset sandboxes to their version controlled state
  10. Test schematics against a local project
  11. Update sandboxes
  12. Dev tips

Jest Angular Schematic

This schematic will configure Angular to execute unit tests with Jest for single projects or workspaces.

npm (scoped)

Usage 🚀

ng add @briebug/jest-schematic
  • install Jest, types and a builder
  • add Jest configuration files
  • remove Karma & Jasmine along with their configuration files

Optionally: install globally

npm install -g @briebug/jest-schematic

Then in an Angular CLI project run

ng g @briebug/jest-schematic:add

jest-schematic-demo-500

Issues 🧐

If you're experiencing issues when trying to run your tests with Jest, please view the documentation for the builder which uses jest-preset-angular.

A common issues involves library dependencies. For example if your app depends on NgRx you'll need to tell Jest to compile the sources explicitly by appending it to the transformIgnorePatterns property in the jest.config.js file.

module.exports = {
  transformIgnorePatterns: ['node_modules/(?!(jest-test|@ngrx))'],
};

Jest issues

Issues related to jest, ts-jest, or test execution may be related the installed version of jest and jest-preset-angular. The schematic may install a version of jest other than latest in an attempt to configure package versions that work together correctly. If you experience issues with your tests after running the schematic related to the aforementioned packages, please review the package versions and adjust them as necessary.

Issues with this schematic can be filed here.

Learning Resources 📚

Development 🛠

Getting started

Clone or fork the repo and install the dependencies with Yarn

yarn

Test schematic changes against a sandbox app

When running locally, schematic changes will be applied to a test app in the /sandboxes directory. /sandboxes contain a single app repo and a workspace repo with an application and library.

Run the following when a schematic change is made to test:

// runs against /sandboxes/single-app
yarn test single

// runs against /sandboxes/workspace
yarn test workspace

⚠ Be careful not to check in changes to the sandbox directory unless necessary. ⚠

Reset sandboxes to their version controlled state

This will reset the sandboxes to their HEAD commit and remove un-tracked files.

yarn reset

Test schematics against a local project

  • run yarn build to compile the schematic in watch mode
  • open another shell, cd into the local repo you want to run the schematic against, and run yarn link @briebug/jest-schematic. This assumes you've run yarn link in this repo on your machine.
    • this will symlink the projects so that the Jest schematic command runs from you're local filesystem
  • in the local repo you want to run the schematic against, run ng g @briebug/jest-schematic:add

Update sandboxes

When a new version of Angular is released, update all the sandbox apps and libs to the latest version.

replace 15 with the latest version of Angular

cd sandbox

rm single-app

npx @angular/cli@15 new single-app --routing --style=css --skip-git --package-manager=yarn

rm workspace

npx @angular/cli@15 new workspace --create-application=false --skip-git --package-manager=yarn

cd workspace

ng g app app-one --routing --style=css --skip-git

ng g lib lib-one

Dev tips

For faster developing, find and comment out the following line to avoid npm installing dependencies

context.addTask(new NodePackageInstallTask());

版本与发布记录

@briebug/jest-schematic 共发布 15 个版本,首次发布于 2018/09/16;过去 12 个月发布了 0 个版本。

版本发布日期距今
6.0.0latest2022/12/293 年前
5.0.02022/10/244 年前
4.0.02021/12/144 年前
3.1.02020/10/256 年前
3.0.02020/09/256 年前
3.0.0-0next2020/09/026 年前

关于 @briebug/jest-schematic 的常见问题

@briebug/jest-schematic 是什么?

Schematic to add jest to an Angular CLI project

如何安装 @briebug/jest-schematic?

在项目目录运行 npm install @briebug/jest-schematic,或使用 pnpm add / yarn add / bun add。

@briebug/jest-schematic 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/briebug__jest-schematic 是否存在。

@briebug/jest-schematic 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@briebug/jest-schematic 可以商用吗?

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

@briebug/jest-schematic 的下载量有多少?

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

@briebug/jest-schematic 还在维护吗?

最新版本 6.0.0 发布于 2022/12/29(3 年前);至今共发布 15 个版本,其中过去 12 个月发布了 0 个;首次发布于 2018/09/16。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。