从 `jest --watch` 执行 tsc

发布于 2025-01-09 22:10:32 字数 1708 浏览 1 评论 0原文

在我的 monorepo 中,我使用 esbuild 使用 npx jest --watch 快速运行测试,但是当我向运行的测试集添加 tsc 命令时,监视控制台挂起并变得无响应。

我想并行运行 tsc ,以便最终在测试结果快速报告后几秒钟收到编译器错误的通知(esbuild 跳过打字稿类型并只运行JavaScript)。

我并行生成 tsc 的方法可以在没有 watch 的情况下工作,但我无法让它与 --watch 一起运行。它会导致与 jest --watch 相关的交互式终端挂起,可能与 stdio:"inherit" 有关。但是,如果没有 stdio 选项,我看不到输出。

我缺少什么?

我的顶级 jest.config.js 目前看起来像这样,它针对 monorepo 中的三个不同的测试套件。它与 --watch 配合良好。我可以使用交互式控制台以这种方式运行和重新运行测试...

module.exports = {
  projects: [
    "<rootDir>/modules/task-editor-logic",
    "<rootDir>/modules/express-vault",
    "<rootDir>/modules/vault-memory",
    // {
    //   globalTeardown: "./check.js",
    // },
  ],
  reporters: ["default", "jest-summary-reporter"],
};

check 脚本在 package.json 中声明为简单的 "check": "tsc"。我可以取消注释上面的代码来运行globalTeardown` 任务,这会导致每次运行测试套件时都运行检查。

拆解任务的来源如下。如果代码编译成功,则正确成功,否则失败。

手动运行它作为 node check.js 成功从控制台运行 check npm 脚本。通过 npx jest 手动运行它也可以(它将 globalTeardown 作为测试项目运行)。笑话运行完成并返回,如您所期望的那样。

但是,通过 npx jest --watch 运行它会导致挂起,并且交互式运行器的控制台变得无响应,需要 CTRL+C 来终止它。

有没有某种方法可以调用 pnpm run check shell 命令,该命令与 jest --watch 线束和 tty 配合得更好?

// check.js
const util = require("util");
const promiseExecSync = util.promisify(require("child_process").execSync);

async function runCheck() {
  return promiseExecSync("pnpm run check", { stdio: "inherit" });
}

module.exports = runCheck;

if (require.main === module) {
  runCheck();
}

In my monorepo, I am using esbuild to run tests rapidly using npx jest --watch but when I add a tsc command to the set of tests that runs, the watch console hangs and becomes non-responsive.

I would like to run tsc in parallel so that I do, eventually, get notified that there is a compiler error, a few seconds after the test results have reported rapidly (esbuild skips the typescript types and just runs the javascript).

My approach to spawn tsc in parallel works without watch but I can't get it to function with --watch. It causes a hang of the interactive terminal associated with jest --watch, maybe to do with the stdio:"inherit". However without the stdio option, I can't see the output.

What am I missing?

My top-level jest.config.js currently looks like this which targets three distinct test suites within the monorepo. It works well with --watch. I can run and re-run tests this way using the interactive console ...

module.exports = {
  projects: [
    "<rootDir>/modules/task-editor-logic",
    "<rootDir>/modules/express-vault",
    "<rootDir>/modules/vault-memory",
    // {
    //   globalTeardown: "./check.js",
    // },
  ],
  reporters: ["default", "jest-summary-reporter"],
};

A check script is declared in package.json as simply "check": "tsc". I can uncomment the code above to run theglobalTeardown` task which causes check to be run for each run of the test suite.

The source of the teardown task is as below. It correctly succeeds if the code compiles and fails otherwise.

Running it manually as node check.js runs the check npm script from the console successfully. Running it manually via npx jest also works (it runs the globalTeardown as a test project). The jest run completes and returns as you would expect.

However, running it via npx jest --watch causes a hang and the console of the interactive runner becomes non-responsive requiring a CTRL+C to kill it.

Is there some way to invoke the pnpm run check shell command that plays nicer with the jest --watch harness and tty?

// check.js
const util = require("util");
const promiseExecSync = util.promisify(require("child_process").execSync);

async function runCheck() {
  return promiseExecSync("pnpm run check", { stdio: "inherit" });
}

module.exports = runCheck;

if (require.main === module) {
  runCheck();
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文