Cannot resolve path in Mocha

前端 未结 7 1246
被撕碎了的回忆
被撕碎了的回忆 2020-12-30 21:45

I am currently using Nitrous, which shouldn\'t matter, but I needed to install mocha so I typed in:

npm install - g mocha.

Everything insta

相关标签:
7条回答
  • 2020-12-30 22:23

    If you run npm test it will execute the *.js files only in test directory not in sub directories.

    If you also want to execute the *.js test files inside sub directories of test folder.

    Follow the following steps :

    1. Create a mocha.opts file in test directory
    2. Add following line in mocha.opts file --recursive
    0 讨论(0)
  • 2020-12-30 22:38

    By default, mocha includes ./test/*.js. So if that is where your tests live, just running mocha is all you need.

    If you have your tests in test/unit, you might want to run mocha ./test/unit/*.js.

    0 讨论(0)
  • 2020-12-30 22:38

    For anyone who gets this error when trying to run:

    > npm test 
    

    Make sure that your package.json file includes a test script in the format of:

    <project-root>/<custom-path-to-test>/*.js

    For example:

    {
      "name": "Project Name",
       ...
      "scripts": {
        "test": "mocha ./node/test/*.js"
      }
       ...
    }
    
    0 讨论(0)
  • 2020-12-30 22:38

    For those having mocha installed and have makefile like this:

    test:
        @./node_modules/.bin/mocha -u tdd
    .PHONY: test
    

    but getting this error:

    Error: cannot resolve path (or pattern) 'test'
    

    you need to add folder "test" in the project folder. And your test files in that test folder

    E.G.
     /home/you/nodejs/chapter3
      ├── lib
      ├── makefile
      ├── node_modules
      ├── package.json
      └── test
           ├── db.test.js

    0 讨论(0)
  • 2020-12-30 22:38
    npm install -g mocha
    npm install mocha --save-dev  
    

    write your test : test.js add below script in your package json file

    "scripts": {
        "api:test": "node_modules/.bin/mocha --timeout 10000 --recursive test/"
    },
    

    go to your test directory : npm run api:test

    https://github.com/shahing/Mocha-RestAPI-Tests

    0 讨论(0)
  • 2020-12-30 22:47

    Just move all the tests to the test folder, If you dont have create one.

    and in the package.json file just enter 'mocha'

    "scripts":{
        "test": "mocha"
      },
    

    and run

    npm test
    

    in the terminal.

    0 讨论(0)
提交回复
热议问题