[tansaku@Samuels-MBP:~/tmp ]$
→ mkdir node_tests_rep2
[tansaku@Samuels-MBP:~/tmp ]$
→ cd node_tests_rep2
[tansaku@Samuels-MBP:~/tmp/node_tests_rep2 ]$
→ npm init
This utility will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sensible defaults.
See `npm help json` for definitive documentation on these fields
and exactly what they do.
Use `npm install <pkg> --save` afterwards to install a package and
save it as a dependency in the package.json file.
Press ^C at any time to quit.
name: (node_tests_rep2)
version: (1.0.0)
description:
entry point: (index.js)
test command: mocha test/**/*.js
git repository:
keywords:
author:
license: (ISC)
About to write to /Users/tansaku/tmp/node_tests_rep2/package.json:
{
"name": "node_tests_rep2",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "mocha test/**/*.js"
},
"author": "",
"license": "ISC"
}
Is this ok? (yes)
[tansaku@Samuels-MBP:~/tmp/node_tests_rep2 ]$
→ npm install mocha chai --save-dev
node_tests_rep2@1.0.0 /Users/tansaku/tmp/node_tests_rep2
├─┬ chai@4.1.2
│ ├── assertion-error@1.0.2
│ ├── check-error@1.0.2
│ ├── deep-eql@3.0.1
│ ├── get-func-name@2.0.0
│ ├── pathval@1.1.0
│ └── type-detect@4.0.3
└─┬ mocha@3.5.0
├── browser-stdout@1.3.0
├─┬ commander@2.9.0
│ └── graceful-readlink@1.0.1
├─┬ debug@2.6.8
│ └── ms@2.0.0
├── diff@3.2.0
├── escape-string-regexp@1.0.5
├─┬ glob@7.1.1
│ ├── fs.realpath@1.0.0
│ ├─┬ inflight@1.0.6
│ │ └── wrappy@1.0.2
│ ├── inherits@2.0.3
│ ├─┬ minimatch@3.0.4
│ │ └─┬ brace-expansion@1.1.8
│ │ ├── balanced-match@1.0.0
│ │ └── concat-map@0.0.1
│ ├── once@1.4.0
│ └── path-is-absolute@1.0.1
├── growl@1.9.2
├── json3@3.3.2
├─┬ lodash.create@3.1.1
│ ├─┬ lodash._baseassign@3.2.0
│ │ ├── lodash._basecopy@3.0.1
│ │ └─┬ lodash.keys@3.1.2
│ │ ├── lodash._getnative@3.9.1
│ │ ├── lodash.isarguments@3.1.0
│ │ └── lodash.isarray@3.0.4
│ ├── lodash._basecreate@3.0.3
│ └── lodash._isiterateecall@3.0.9
├─┬ mkdirp@0.5.1
│ └── minimist@0.0.8
└─┬ supports-color@3.1.2
└── has-flag@1.0.0
npm WARN node_tests_rep2@1.0.0 No description
npm WARN node_tests_rep2@1.0.0 No repository field.
[tansaku@Samuels-MBP:~/tmp/node_tests_rep2 ]$
→ mkdir test lib
[tansaku@Samuels-MBP:~/tmp/node_tests_rep2 ]$
→ touch test/test_spec.js
[tansaku@Samuels-MBP:~/tmp/node_tests_rep2 ]$
→ touch lib/test.js
[tansaku@Samuels-MBP:~/tmp/node_tests_rep2 ]$
→ subl .
[tansaku@Samuels-MBP:~/tmp/node_tests_rep2 ]$
→ npm test
> node_tests_rep2@1.0.0 test /Users/tansaku/tmp/node_tests_rep2
> mocha test/**/*.js
/Users/tansaku/tmp/node_tests_rep2/test/test_spec.js:4
describe('Athletic reps',()={
^^
ReferenceError: Invalid left-hand side in assignment
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Module._compile (module.js:542:28)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at /Users/tansaku/tmp/node_tests_rep2/node_modules/mocha/lib/mocha.js:230:27
at Array.forEach (native)
at Mocha.loadFiles (/Users/tansaku/tmp/node_tests_rep2/node_modules/mocha/lib/mocha.js:227:14)
at Mocha.run (/Users/tansaku/tmp/node_tests_rep2/node_modules/mocha/lib/mocha.js:513:10)
at Object.<anonymous> (/Users/tansaku/tmp/node_tests_rep2/node_modules/mocha/bin/_mocha:480:18)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.runMain (module.js:604:10)
at run (bootstrap_node.js:389:7)
at startup (bootstrap_node.js:149:9)
at bootstrap_node.js:504:3
npm ERR! Test failed. See above for more details.
[tansaku@Samuels-MBP:~/tmp/node_tests_rep2 ]$
→ npm test
> node_tests_rep2@1.0.0 test /Users/tansaku/tmp/node_tests_rep2
> mocha test/**/*.js
Athletic reps
✓ should get less painful
1 passing (9ms)
with test file:
const expect = require('chai').expect;
const pain = require('../lib/test');
describe('Athletic reps',()=>{
it('should get less painful',()=>{
expect(pain).to.equal('less');
});
});
and app file:
var pain = 'less'
module.exports = pain;