-
Notifications
You must be signed in to change notification settings - Fork 6
/
config.ts
113 lines (88 loc) · 2.53 KB
/
config.ts
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import path from 'path'
import { suite } from 'uvu'
import * as assert from 'uvu/assert'
import { afix } from 'afix'
import { Config, getConfigFile, create } from '../config'
import { Env } from '../constants'
const test = suite('presta - config')
test('config - getConfigFile no config, no log or exit', async () => {
const { getConfigFile } = require('proxyquire')('../config', {
'./log': {
error() {
throw new Error('fail')
},
},
})
const configFile = getConfigFile()
assert.equal(configFile, {})
})
test('config - getConfigFile exists', async () => {
const fixture = afix({
config: ['presta.config.js', `export const files = 'path/to/*.js'`],
})
const configFile = getConfigFile(fixture.files.config.path)
assert.ok(configFile.files)
})
test('config - getConfigFile throws, syntax error', async () => {
let called = false
const { getConfigFile } = require('proxyquire')('../config', {
'./log': {
error() {
called = true
},
},
})
const fixture = afix({
config: ['presta.config.js', `export const files = 'path/to/*.js`], // syntax error
})
const configFile = getConfigFile(fixture.files.config.path)
assert.equal(configFile, {})
assert.ok(called)
})
test('config - getConfigFile throws and exits', async () => {
const fixture = afix({
config: ['presta.config.js', `export const files = 'path/to/*.js`], // syntax error
})
const exit = process.exit
let plan = 0
// @ts-ignore
process.exit = (code: int) => {
assert.equal(code, 1)
plan++
}
getConfigFile(fixture.files.config.path, true)
// @ts-ignore
process.exit = exit
assert.equal(plan, 1)
})
test('config - getConfigFile throws and does not exit with no file', async () => {
const configFile = getConfigFile(undefined, true)
assert.equal(configFile, {})
})
test('create', async () => {
const cli = {
_: ['pages/*.js'],
output: 'dist',
assets: 'assets',
}
const file = {
assets: 'static',
files: ['test/*.js'],
port: 4000,
}
const config = create(Env.PRODUCTION, cli, file)
const output = path.join(process.cwd(), 'dist')
const generated: Config = {
env: Env.PRODUCTION,
port: 4000,
files: [path.join(process.cwd(), 'pages/*.js')],
output,
assets: path.join(process.cwd(), 'assets'),
plugins: [],
staticOutputDir: path.join(output, 'static'),
functionsOutputDir: path.join(output, 'functions'),
manifestFilepath: path.join(output, 'manifest.json'),
}
assert.equal(config, generated)
})
test.run()