2021-04-27 17:14:24 +03:00
|
|
|
// 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]
|
2021-05-09 17:31:01 +03:00
|
|
|
: ['vanillajs', 'cra', 'vite', 'vuecli']
|
2021-04-27 17:14:24 +03:00
|
|
|
const timeoutLong = 900000
|
|
|
|
const timeoutLittleLonger = 930000
|
|
|
|
const logOut = false ? 'inherit' : 'pipe'
|
|
|
|
|
|
|
|
describe('CTA', () => {
|
2021-05-12 22:25:44 +03:00
|
|
|
console.warn(
|
|
|
|
'NOTE: You need to have installed and built cli.js and api before running the tests.'
|
|
|
|
)
|
2021-04-27 17:14:24 +03:00
|
|
|
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)
|
|
|
|
|
2021-05-09 17:31:01 +03:00
|
|
|
const packageFileInitial: {
|
|
|
|
[k: string]: string | object
|
|
|
|
} = JSON.parse(
|
|
|
|
await fs.promises.readFile(
|
|
|
|
path.join(appFolder, 'package.json'),
|
|
|
|
'utf-8'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
expect(packageFileInitial['name']).toBe(appName)
|
|
|
|
|
2021-04-27 17:14:24 +03:00
|
|
|
// 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') {
|
2021-05-01 04:48:21 +03:00
|
|
|
opts =
|
|
|
|
recipe == 'vuecli'
|
|
|
|
? ['run', 'tauri:build']
|
|
|
|
: ['run', 'tauri', '--', 'build']
|
2021-04-27 17:14:24 +03:00
|
|
|
} else if (manager === 'yarn') {
|
2021-05-01 04:48:21 +03:00
|
|
|
opts = recipe == 'vuecli' ? ['tauri:build'] : ['tauri', 'build']
|
2021-04-27 17:14:24 +03:00
|
|
|
}
|
|
|
|
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'
|
|
|
|
})
|
|
|
|
},
|
2021-05-09 17:31:01 +03:00
|
|
|
cra: () => {
|
2021-04-27 17:14:24 +03:00
|
|
|
expect(packageFileOutput['scripts']).toEqual(
|
|
|
|
expect.objectContaining({
|
|
|
|
tauri: 'tauri'
|
|
|
|
})
|
|
|
|
)
|
2021-05-01 04:48:21 +03:00
|
|
|
},
|
|
|
|
vite: () => {
|
|
|
|
expect(packageFileOutput['scripts']).toEqual(
|
|
|
|
expect.objectContaining({
|
|
|
|
tauri: 'tauri'
|
|
|
|
})
|
|
|
|
)
|
|
|
|
},
|
|
|
|
vuecli: () => {
|
|
|
|
expect(packageFileOutput['scripts']).toEqual(
|
|
|
|
expect.objectContaining({
|
|
|
|
'tauri:build': expect.anything(),
|
|
|
|
'tauri:serve': expect.anything()
|
|
|
|
})
|
|
|
|
)
|
2021-07-14 23:36:46 +03:00
|
|
|
},
|
|
|
|
ngcli: () => {
|
|
|
|
expect(packageFileOutput['scripts']).toEqual(
|
|
|
|
expect.objectContaining({
|
|
|
|
ng: 'ng',
|
|
|
|
tauri: 'tauri'
|
|
|
|
})
|
|
|
|
)
|
2021-04-27 17:14:24 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const getCustomAsserts = assertCustom[recipe]
|
|
|
|
if (getCustomAsserts) getCustomAsserts()
|
|
|
|
},
|
|
|
|
timeoutLittleLonger
|
|
|
|
)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|