[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
[email protected] /Users/tansaku/tmp/node_tests_rep2
├─┬ [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ └── [email protected]
└─┬ [email protected]
├── [email protected]
├─┬ [email protected]
│ └── [email protected]
├─┬ [email protected]
│ └── [email protected]
├── [email protected]
├── [email protected]
├─┬ [email protected]
│ ├── [email protected]
│ ├─┬ [email protected]
│ │ └── [email protected]
│ ├── [email protected]
│ ├─┬ [email protected]
│ │ └─┬ [email protected]
│ │ ├── [email protected]
│ │ └── [email protected]
│ ├── [email protected]
│ └── [email protected]
├── [email protected]
├── [email protected]
├─┬ [email protected]
│ ├─┬ [email protected]
│ │ ├── [email protected]
│ │ └─┬ [email protected]
│ │ ├── [email protected]
│ │ ├── [email protected]
│ │ └── [email protected]
│ ├── [email protected]
│ └── [email protected]
├─┬ [email protected]
│ └── [email protected]
└─┬ [email protected]
└── [email protected]
npm WARN [email protected] No description
npm WARN [email protected] 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
> [email protected] 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
> [email protected] 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;