-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.test.js
65 lines (53 loc) · 1.61 KB
/
cli.test.js
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
#!/usr/bin/env node
const fs = require('fs')
const { execSync } = require('child_process')
const debug = require('debug')('test')
const cfgCheck = require('./lib/cfg-check')
const settings = require('./lib/settings')
const options = { stdio: 'inherit' }
const goodEnv = settings.env
const badEnv = {
http_proxy: 'http://proxy.bogus.com.au:8081',
no_proxy: '.thebogus.com,.bogus.com.au'
}
test('Environment check ok', () => {
Object.keys(goodEnv).forEach(key => {
process.env[key] = goodEnv[key]
})
expect(cfgCheck.envCheck()).toBeFalsy()
})
test('Environment check bad', () => {
Object.keys(badEnv).forEach(key => {
process.env[key] = badEnv[key]
})
expect(cfgCheck.envCheck()).toBeTruthy()
})
test('rc check .goodrc', () => {
expect(cfgCheck.rcCheck('good')).toBeFalsy()
})
test('rc check .badrc', () => {
expect(cfgCheck.rcCheck('bad')).toBeTruthy()
})
// CLI based testing doesn't appear to be reliable,
// and also we can't control the config... so leave it be for now
// test('Prefix ok', () => {
// const ENV = Object.keys(goodEnv).reduce((acc, key) => {
// return acc + `${key}=${goodEnv[key]} `
// }, '')
// expect(execSync(`${ENV} node cli.js cfg-check`, options)).toThrow()
// })
// test('Prefix ok throw?', () => {
// expect(() => {
// execSync('node cli.js cfg-check', options)
// }).toThrow()
// })
// test('Invalid command', () => {
// expect(() => {
// execSync('node cli.js rubbish me please', options)
// }).toThrow()
// })
// test('Prefix ', () => {
// expect(() => {
// execSync('NPM_prefix=BAD_THING node cli.js cfg-check', options)
// }).toThrow()
// })