-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwalk-through.txt
More file actions
85 lines (62 loc) · 2.42 KB
/
walk-through.txt
File metadata and controls
85 lines (62 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
Hello World
npm init -y
touch index.js hello.js
npm install commander
--
index.js
const program = require('commander')
program.option('-n, --name <string>', 'whats your name')
program.parse(process.argv)
console.log(program.name)
hello.js
const hello = (name) => name
exports.hello = hello
mkdir tests
touch tests/hello.test.js
tests/hello.test.js
const { hello } = require('../hello')
const name = hello('joe') //mr anderson
console.log(name)
index.js
if (!process.argv.slice(2).length) {
program.outputHelp()
process.exit()
}
console.log(hello(program.name))
%> node index.js
%> node index.js --name joe
/// https://jestjs.io/
npm install --save-dev jest
npm run test
tests/hello.test.js
describe('hello module', () => {
test('name returns with hello', () => {
const testName = 'joe'
const returnedName = hello(testName)
expect(returnedName).toBe(returnedName)
})
})
// make return 'hello joe'
// make return 'hello, joe'
// make return 'Hello, Joe!'
tests/hello.test.js
return s.charAt(0).toUpperCase() + s.slice(1)
---------------------
mkdir weather
npm init -y
cp hello index / remove hello
// darksky.net -> get api key
// https://api.darksky.net/forecast/KEY/37.8267,-122.4233
// opencagedata.com -> get api key
// https://api.opencagedata.com/geocode/v1/json?key=KEY&q=Orlando,%20FL
index.js
require('dotenv').config()
package.json
"jest": {
"setupFiles": ["./tests/setup.js"]
},
tests/setup.js
console.log('Loading .env file for tests')
require('dotenv').config({ path: '.env.test' })
npm install --save-dev nock
//https://github.com/nock/nock#specifying-path