[tansaku@Samuels-MBP:~/Documents/Github ]$
→ cd ~/tmp
[tansaku@Samuels-MBP:~/tmp ]$
→ mkdir node_tests_rep1
[tansaku@Samuels-MBP:~/tmp ]$
→ cd node_tests_rep1/
[tansaku@Samuels-MBP:~/tmp/node_tests_rep1 ]$
→ 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_rep1)
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_rep1/package.json:
{
"name": "node_tests_rep1",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "mocha test/**/*.js"
},
"author": "",
"license": "ISC"
}
Is this ok? (yes) yes
[tansaku@Samuels-MBP:~/tmp/node_tests_rep1 ]$
→ npm install --save-dev
npm WARN [email protected] No description
npm WARN [email protected] No repository field.
[tansaku@Samuels-MBP:~/tmp/node_tests_rep1 ]$
→ npm install --save-dev mocha chai
[email protected] /Users/tansaku/tmp/node_tests_rep1
├─┬ [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_rep1 ]$
→ mkdir test
[tansaku@Samuels-MBP:~/tmp/node_tests_rep1 ]$
→ touch test/test_spec.js
[tansaku@Samuels-MBP:~/tmp/node_tests_rep1 ]$
→ subl .
[tansaku@Samuels-MBP:~/tmp/node_tests_rep1 ]$
→ npm test
> [email protected] test /Users/tansaku/tmp/node_tests_rep1
> mocha test/**/*.js
Athletic Rep
✓ should get less and less painful
1 passing (6ms)
[tansaku@Samuels-MBP:~/tmp/node_tests_rep1 ]$
→ mkdir lib
[tansaku@Samuels-MBP:~/tmp/node_tests_rep1 ]$
→ touch lib/test.js
[tansaku@Samuels-MBP:~/tmp/node_tests_rep1 ]$
→ mkdir lib
mkdir: lib: File exists
[tansaku@Samuels-MBP:~/tmp/node_tests_rep1 ]$
→ npm test
> [email protected] test /Users/tansaku/tmp/node_tests_rep1
> mocha test/**/*.js
Athletic Rep
✓ should get less and less painful
1 passing (7ms)
Elapsed time four minutes. No errors and following code stamped out from memory:
var expect = require('chai').expect;
const pain = require('../lib/test')
describe('Athletic Rep', function(){
it('should get less and less painful', function(){
expect(pain).to.equal('less');
})
})
const pain = 'less';
module.exports = pain;