/
resolve-config.spec.ts
68 lines (64 loc) · 2.26 KB
/
resolve-config.spec.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
import fs from 'node:fs'
import path from 'node:path'
import { execaCommandSync } from 'execa'
import { isBuild, testDir, viteBinPath } from '~utils'
const fromTestDir = (...p: string[]) => path.resolve(testDir, ...p)
const build = (configName: string) => {
execaCommandSync(`${viteBinPath} build`, { cwd: fromTestDir(configName) })
}
const getDistFile = (configName: string, extension: string) => {
return fs.readFileSync(
fromTestDir(`${configName}/dist/index.${extension}`),
'utf8'
)
}
describe.runIf(isBuild)('build', () => {
it('loads vite.config.js', () => {
build('js')
expect(getDistFile('js', 'mjs')).toContain('console.log(true)')
})
it('loads vite.config.js with package#type module', () => {
build('js-module')
expect(getDistFile('js-module', 'js')).toContain('console.log(true)')
})
it('loads vite.config.cjs', () => {
build('cjs')
expect(getDistFile('cjs', 'mjs')).toContain('console.log(true)')
})
it('loads vite.config.cjs with package#type module', () => {
build('cjs-module')
expect(getDistFile('cjs-module', 'js')).toContain('console.log(true)')
})
it('loads vite.config.mjs', () => {
build('mjs')
expect(getDistFile('mjs', 'mjs')).toContain('console.log(true)')
})
it('loads vite.config.mjs with package#type module', () => {
build('mjs-module')
expect(getDistFile('mjs-module', 'js')).toContain('console.log(true)')
})
it('loads vite.config.ts', () => {
build('ts')
expect(getDistFile('ts', 'mjs')).toContain('console.log(true)')
})
it('loads vite.config.ts with package#type module', () => {
build('ts-module')
expect(getDistFile('ts-module', 'js')).toContain('console.log(true)')
})
it('loads vite.config.mts', () => {
build('mts')
expect(getDistFile('mts', 'mjs')).toContain('console.log(true)')
})
it('loads vite.config.mts with package#type module', () => {
build('mts-module')
expect(getDistFile('mts-module', 'js')).toContain('console.log(true)')
})
it('loads vite.config.cts', () => {
build('cts')
expect(getDistFile('cts', 'mjs')).toContain('console.log(true)')
})
it('loads vite.config.cts with package#type module', () => {
build('cts-module')
expect(getDistFile('cts-module', 'js')).toContain('console.log(true)')
})
})