【问题标题】:Issue running node with typescript compilation and Jest使用 typescript 编译和 Jest 发出运行节点
【发布时间】:2021-07-16 16:22:54
【问题描述】:

我在使用 typescript 编译时遇到问题。我正在尝试在 docker 容器中运行它,但即使在本地运行也会产生相同的错误,所以我认为我搞砸了参数。我需要使用节点运行。

我正在尝试运行

 node --nolazy -r ./node_modules/tsconfig-paths/register.js -r ./node_modules/ts-node/register ./node_modules/jest/bin/jest.js

哪个输出

TypeError: Cannot read property 'alias' of undefined
    at /home/user/Workspace/project/node_modules/jest-validate/build/validateCLIOptions.js:97:58
    at Array.reduce (<anonymous>)
    at validateCLIOptions (/home/user/Workspace/project/node_modules/jest-validate/build/validateCLIOptions.js:96:47)
    at buildArgv (/home/user/Workspace/project/node_modules/jest/node_modules/jest-cli/build/cli/index.js:192:42)
    at Object.run (/home/user/Workspace/project/node_modules/jest/node_modules/jest-cli/build/cli/index.js:155:18)
    at Object.<anonymous> (/home/user/Workspace/project/node_modules/jest/node_modules/jest-cli/bin/jest.js:16:27)
    at Module._compile (node:internal/modules/cjs/loader:1092:14)
    at node:internal/modules/cjs/loader:1121:10
    at Object..js (/home/user/Workspace/project/node_modules/ts-node/src/index.ts:1045:43)
    at Module.load (node:internal/modules/cjs/loader:972:32)

如果我尝试使用我的 Jest 配置,我会得到一个不同的错误

node --nolazy -r ./node_modules/tsconfig-paths/register.js -r ./node_modules/ts-node/register ./node_modules/jest/bin/jest.js --config=./jest-config.json

哪个输出

Usage: jest.js [--config=<pathToConfigFile>] [TestPathPattern]
Options:
   ...[Jest help output]...
(0 , _jestConfig(...).isJSONString) is not a function

似乎tsconfig-paths 导致了这个问题,因为当我删除它时测试开始运行,但它们当然会失败,因为节点需要的是 javascript 而不是 typescript

【问题讨论】:

    标签: node.js typescript jestjs


    【解决方案1】:

    不知道为什么,但开玩笑标志--runInBand 是必需的。我认为this blog 可能是因为否则会产生子进程?

    --runInBand 导致所有测试在父进程而不是子进程中运行。

    编辑:如果有人好奇,this is how 我设法在 Docker 中启动的 Jest 测试中进行远程调试

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-09-25
      • 1970-01-01
      • 2020-01-19
      • 2021-04-12
      • 1970-01-01
      • 2015-07-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多