-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathconfig.test.ts
More file actions
57 lines (43 loc) · 1.64 KB
/
Copy pathconfig.test.ts
File metadata and controls
57 lines (43 loc) · 1.64 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
import {expect} from 'chai'
import * as fs from 'fs-extra'
import path from 'node:path'
import {tempDir} from './utils'
const requireConfig = () => require('../src/config').default
const cleanup = () => {
// delete config module cache
delete require.cache[require.resolve('../src/config')]
// reset env
process.env = {}
}
const setupConfigFile = () => {
const configDir = tempDir()
process.env.HMD_CLI_CONFIG_DIR = configDir
return path.join(configDir, 'config.json')
}
describe('Config test', () => {
beforeEach(function () {
cleanup()
this.configFilePath = setupConfigFile()
})
// eslint-disable-next-line mocha/no-skipped-tests
it.skip('should throw no config error if config.json not found and no hackmdAPIEndpointURL set in env', function () {
expect(requireConfig)
.to.throw(new RegExp(`Configuration file at ${this.configFilePath} not readable`))
})
it('should throw read error if config.json is not valid JSON', function () {
fs.writeFileSync(this.configFilePath, '.', 'utf8')
expect(requireConfig)
.to.throw(/Could not read JSON config file at/)
})
it('should set hackmdAPIEndpointURL to defalut value: https://api.hackmd.io/v1 if no value is given', function () {
fs.writeFileSync(this.configFilePath, '{}', 'utf8')
const config = requireConfig()
expect(config.hackmdAPIEndpointURL).to.eq('https://api.hackmd.io/v1')
})
// eslint-disable-next-line mocha/no-skipped-tests
it.skip('should throw error if no access token is set', function () {
fs.writeFileSync(this.configFilePath, '{}', 'utf8')
expect(requireConfig)
.to.throw(/Please specify access token either/)
})
})