首页 > 解决方案 > jest 和 npm 没有运行测试,只是挂起

问题描述

我对 node.js 不熟悉,因为我还在学习前端,但是我已经开始通过 exercism.com 练习前端,这需要您使用 npm 和 jest 通过他们的测试套件运行测试。所以我真的很没面子,没有人可以问,希望能得到一些答案。

我正在尝试在 Windows 10 的 git bash 中运行命令“npm test”。当我运行前几个测试时,它运行良好,只有一个测试要运行,因为其他测试被阻止了。当我在所有条件下运行测试时,它开始出现这个问题。我用谷歌搜索了很多,这是我尝试过的:

它只是挂起。最后一行如下所示:

开玩笑--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'));
  });
});

谢谢!

标签: node.jstestingjestjs

解决方案


推荐阅读