-
Notifications
You must be signed in to change notification settings - Fork 20
/
build.spec.ts
88 lines (77 loc) · 2.75 KB
/
build.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import { fileURLToPath } from 'url'
import { readFile, readdir } from 'fs/promises'
import { beforeAll, describe, it, expect } from 'vitest'
import { execaCommand } from 'execa'
import { join } from 'pathe'
describe('module builder', () => {
const rootDir = fileURLToPath(new URL('../example', import.meta.url))
const distDir = join(rootDir, 'dist')
const runtimeDir = join(distDir, 'runtime')
beforeAll(async () => {
await execaCommand('pnpm dev:prepare', { cwd: rootDir })
await execaCommand('pnpm prepack', { cwd: rootDir })
}, 120 * 1000)
it('should generate all files', async () => {
const files = await readdir(distDir)
expect(files).toMatchInlineSnapshot(`
[
"module.cjs",
"module.d.ts",
"module.json",
"module.mjs",
"runtime",
"types.d.ts",
"utils.d.ts",
"utils.mjs",
]
`)
const runtime = await readdir(runtimeDir)
expect(runtime).toMatchInlineSnapshot(`
[
"plugin.d.ts",
"plugin.mjs",
]
`)
})
it('should write types to output directory', async () => {
const types = await readFile(join(distDir, 'types.d.ts'), 'utf-8')
expect(types).toMatchInlineSnapshot(`
"
import { ModuleOptions, ModuleHooks, ModuleRuntimeConfig, ModulePublicRuntimeConfig } from './module'
declare module '@nuxt/schema' {
interface NuxtConfig { ['myModule']?: Partial<ModuleOptions> }
interface NuxtOptions { ['myModule']?: ModuleOptions }
interface NuxtHooks extends ModuleHooks {}
interface RuntimeConfig extends ModuleRuntimeConfig {}
interface PublicRuntimeConfig extends ModulePublicRuntimeConfig {}
}
declare module 'nuxt/schema' {
interface NuxtConfig { ['myModule']?: Partial<ModuleOptions> }
interface NuxtOptions { ['myModule']?: ModuleOptions }
interface NuxtHooks extends ModuleHooks {}
interface RuntimeConfig extends ModuleRuntimeConfig {}
interface PublicRuntimeConfig extends ModulePublicRuntimeConfig {}
}
export { ModuleHooks, ModuleOptions, ModulePublicRuntimeConfig, ModuleRuntimeConfig, default } from './module'
"
`)
})
it('should generate module metadata as separate JSON file', async () => {
const meta = await readFile(join(distDir, 'module.json'), 'utf-8')
expect(JSON.parse(meta)).toMatchInlineSnapshot(`
{
"configKey": "myModule",
"name": "my-module",
"version": "1.0.0",
}
`)
})
it.todo('should generate typed plugin', async () => {
const pluginDts = await readFile(join(distDir, 'runtime/plugin.d.ts'), 'utf-8')
expect(pluginDts).toMatchInlineSnapshot(`
"declare const _default: any;
export default _default;
"
`)
})
})