【发布时间】:2022-04-10 04:42:41
【问题描述】:
我不熟悉 node.js,因为我还在学习前端,但是我已经开始通过 exercism.com 练习前端,这需要您使用 npm 和 jest 通过他们的测试套件运行测试。所以我实在是太无能了,没有人可以问,希望能得到一些答案。
我正在尝试在 Windows 10 的 git bash 中运行命令“npm test”。当我运行前几个测试时,它运行良好,因为其他测试被阻止,所以它运行良好。当我在所有条件下运行测试时,它开始出现这个问题。我用谷歌搜索了很多,这是我尝试过的:
- 更新节点
- 更新笑话
- 运行 -i
- 正在运行--runInBand
- 运行 -i 和 --runInBand
它只是挂起。最后一行如下所示:
开玩笑 --no-cache ./*
真正的关键在这里:我可以在我之前的任何练习上运行 npm test,它运行得很好。我真的很想了解这里的问题。我不知道需要分享哪些信息,所以这似乎是相关的:
$节点-v v11.13.0
$ 笑话 -v 25.5.4
package.json 文件:
{
"name": "exercism-javascript",
"description": "Exercism exercises in Javascript.",
"author": "Katrina Owen",
"private": true,
"repository": {
"type": "git",
"url": "https://github.com/exercism/javascript"
},
"devDependencies": {
"@babel/cli": "^7.8.4",
"@babel/core": "^7.9.6",
"@babel/plugin-syntax-bigint": "^7.8.3",
"@babel/preset-env": "^7.9.6",
"@types/jest": "^25.2.1",
"@types/node": "^13.13.4",
"babel-eslint": "^10.1.0",
"babel-jest": "^25.5.1",
"eslint": "^6.8.0",
"eslint-plugin-import": "^2.20.2",
"jest": "^25.5.4"
},
"jest": {
"modulePathIgnorePatterns": [
"package.json"
]
},
"scripts": {
"test": "jest --no-cache ./*",
"watch": "jest --no-cache --watch ./*",
"lint": "eslint .",
"lint-test": "eslint . && jest --no-cache ./* "
},
"license": "MIT",
"dependencies": {}
}
这是测试文件,显示测试前面没有“x”:
import { steps } from './collatz-conjecture';
describe('steps()', () => {
test('zero steps for one', () => {
expect(steps(1)).toEqual(0);
});
test('divide if even', () => {
expect(steps(16)).toEqual(4);
});
test('even and odd steps', () => {
expect(steps(12)).toEqual(9);
});
test('Large number of even and odd steps', () => {
expect(steps(1000000)).toEqual(152);
});
test('zero is an error', () => {
expect(() => {
steps(0);
}).toThrow(new Error('Only positive numbers are allowed'));
});
test('negative value is an error', () => {
expect(() => {
steps(-15);
}).toThrow(new Error('Only positive numbers are allowed'));
});
});
谢谢!
【问题讨论】:
-
如果其他程序损坏了,我还能在其他程序上运行 jest 吗?我确实全局安装了它,但是当我尝试测试其他程序时它运行良好,这让我认为它没有损坏,但我真的不知道
-
如果您运行
npm test,您可能会运行本地 Jest,因此您是否拥有全局 Jest 并不重要。尝试为初学者删除并重新安装 node_modules。running --runInBand- 你说你跑了npm test,那么这到底是怎么做到的?node -v v11.13.0听起来不像updating node,它不是太旧,但如果它不能与某些嵌套依赖项一起正常工作,这并不重要。 -
同样,问题中不需要 eslintrc 但 package.json 是。如果您在单独的文件中有 Jest 配置,则也需要它。该问题很可能是您的项目所特有的,这包括可能会以某种方式搞砸并停止 Jest 的测试文件。
-
我也有同样的问题,所有测试在 linux 上运行良好。但是在 Windows 上时,除了 1 个文件之外的所有测试都运行。它只是挂起。