'jest and npm not running test, just hangs

I am not familiar with node.js because I am still learning front end, however I have started practicing front end via exercism.com which requires you to run tests through their test suites with npm and jest. So I am really out of my depth and have no one to ask, hoping to get some answers.

I am trying to run the command "npm test" in git bash in Windows 10. It was running fine when I ran the first few tests that only had one test to run because the others were blocked out. When I went to run the tests on all of the conditions, it started to have this issue. I have googled a lot, and here is what I tried:

  • updating node
  • updating jest
  • running -i
  • running --runInBand
  • running -i and --runInBand

It just hangs. The last line looks like this:

jest --no-cache ./*

The real kicker here: I can run npm test on any of my previous exercises, and it runs just fine. I really want to understand the problem here. i don't know what information is necessary to share, so here is what seems relevant:

$ node -v v11.13.0

$ jest -v 25.5.4

package.json file:

{
  "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": {}
}

Here is the testing file showing that there is no "x" in front of test:

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

Thank you!



Solution 1:[1]

Since I stumbled on a similar problem while going through Exercism exercises before I eventually figured it out. It is very likely that there is an infinite loop or a bug on the code you are testing using "npm test", thus the reason for its hanging. At least that was my issue when I looked into the code.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 FluxedScript