-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
index.spec.ts
147 lines (135 loc) · 4.51 KB
/
index.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
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
// Copyright 2019-2021 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
import execa from 'execa'
import fixtures from 'fixturez'
const f = fixtures(__dirname)
import path from 'path'
import fs from 'fs'
const ctaBinary = path.resolve('./bin/create-tauri-app.js')
const clijs = path.resolve('../cli.js/')
const api = path.resolve('../api/')
const manager = process.env.TAURI_RUN_MANAGER ?? 'npm'
const recipes = process.env.TAURI_RECIPE
? [process.env.TAURI_RECIPE]
: ['vanillajs', 'cra', 'vite', 'vuecli']
const timeoutLong = 900000
const timeoutLittleLonger = 930000
const logOut = false ? 'inherit' : 'pipe'
describe('CTA', () => {
console.warn(
'NOTE: You need to have installed and built cli.js and api before running the tests.'
)
describe.each(recipes.map((recipe) => [recipe, 'tauri-app']))(
`%s recipe`,
(recipe: string, appName: string) => {
it(
'runs',
async () => {
// creates a temp folder to run CTA within (this is our cwd)
const folder = f.temp()
const appFolder = path.join(folder, appName)
// runs CTA with all args set to avoid any prompts
const cta = await execa(
'node',
[
ctaBinary,
'--manager',
manager,
'--recipe',
recipe,
'--ci',
'--dev'
],
{
all: true,
stdio: logOut,
cwd: folder,
timeout: timeoutLong
}
)
// check to make certain it didn't fail anywhere
expect(cta.failed).toBe(false)
expect(cta.timedOut).toBe(false)
expect(cta.isCanceled).toBe(false)
expect(cta.killed).toBe(false)
expect(cta.signal).toBe(undefined)
const packageFileInitial: {
[k: string]: string | object
} = JSON.parse(
await fs.promises.readFile(
path.join(appFolder, 'package.json'),
'utf-8'
)
)
expect(packageFileInitial['name']).toBe(appName)
// run a tauri build to check if what we produced
// can actually create an app
// TODO long term we will want to hook this up to a real test harness
// and then run that test suite instead
let opts: string[] = []
if (manager === 'npm') {
opts =
recipe == 'vuecli'
? ['run', 'tauri:build']
: ['run', 'tauri', '--', 'build']
} else if (manager === 'yarn') {
opts = recipe == 'vuecli' ? ['tauri:build'] : ['tauri', 'build']
}
const tauriBuild = await execa(manager, opts, {
all: true,
stdio: logOut,
cwd: appFolder,
timeout: timeoutLong
})
expect(tauriBuild.failed).toBe(false)
expect(tauriBuild.timedOut).toBe(false)
expect(tauriBuild.isCanceled).toBe(false)
expect(tauriBuild.killed).toBe(false)
expect(tauriBuild.signal).toBe(undefined)
const packageFileOutput: {
[k: string]: string | object
} = JSON.parse(
await fs.promises.readFile(
path.join(appFolder, 'package.json'),
'utf-8'
)
)
expect(packageFileOutput['name']).toBe(appName)
const assertCustom: { [k: string]: Function } = {
vanillajs: () => {
expect(packageFileOutput['scripts']).toMatchObject({
tauri: 'tauri'
})
},
cra: () => {
expect(packageFileOutput['scripts']).toEqual(
expect.objectContaining({
tauri: 'tauri'
})
)
},
vite: () => {
expect(packageFileOutput['scripts']).toEqual(
expect.objectContaining({
tauri: 'tauri'
})
)
},
vuecli: () => {
expect(packageFileOutput['scripts']).toEqual(
expect.objectContaining({
'tauri:build': expect.anything(),
'tauri:serve': expect.anything()
})
)
}
}
const getCustomAsserts = assertCustom[recipe]
if (getCustomAsserts) getCustomAsserts()
},
timeoutLittleLonger
)
}
)
})