2023-02-19 16:17:49 +03:00
|
|
|
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
2022-02-10 22:45:41 +03:00
|
|
|
const fixtureSetup = require('../fixtures/app-test-setup.js')
|
|
|
|
const { resolve } = require('path')
|
|
|
|
const { existsSync, readFileSync, writeFileSync } = require('fs')
|
|
|
|
const { move } = require('fs-extra')
|
2022-02-13 19:50:51 +03:00
|
|
|
const cli = require('~/main.js')
|
2021-08-17 16:27:02 +03:00
|
|
|
|
2022-02-10 22:45:41 +03:00
|
|
|
const currentDirName = __dirname
|
2020-03-09 23:57:27 +03:00
|
|
|
|
2021-04-12 07:59:25 +03:00
|
|
|
describe('[CLI] cli.js template', () => {
|
2020-07-09 16:40:31 +03:00
|
|
|
it('init a project and builds it', async () => {
|
2020-03-09 23:57:27 +03:00
|
|
|
const cwd = process.cwd()
|
2021-08-17 16:27:02 +03:00
|
|
|
const fixturePath = resolve(currentDirName, '../fixtures/empty')
|
2020-07-09 16:40:31 +03:00
|
|
|
const tauriFixturePath = resolve(fixturePath, 'src-tauri')
|
2021-09-28 02:50:27 +03:00
|
|
|
const outPath = resolve(tauriFixturePath, 'target')
|
|
|
|
const cacheOutPath = resolve(fixturePath, 'target')
|
2020-03-09 23:57:27 +03:00
|
|
|
|
2020-07-09 16:40:31 +03:00
|
|
|
fixtureSetup.initJest('empty')
|
2020-03-09 23:57:27 +03:00
|
|
|
|
2020-07-09 16:40:31 +03:00
|
|
|
process.chdir(fixturePath)
|
2020-03-09 23:57:27 +03:00
|
|
|
|
2021-09-28 02:50:27 +03:00
|
|
|
const outExists = existsSync(outPath)
|
|
|
|
if (outExists) {
|
|
|
|
await move(outPath, cacheOutPath)
|
|
|
|
}
|
|
|
|
|
2022-07-04 15:09:00 +03:00
|
|
|
await cli.run(['init', '--directory', process.cwd(), '--force', '--tauri-path', resolve(currentDirName, '../../../../../..'), '--ci'])
|
2020-03-09 23:57:27 +03:00
|
|
|
|
2021-09-28 02:50:27 +03:00
|
|
|
if (outExists) {
|
|
|
|
await move(cacheOutPath, outPath)
|
|
|
|
}
|
|
|
|
|
2020-07-09 16:40:31 +03:00
|
|
|
process.chdir(tauriFixturePath)
|
2020-03-09 23:57:27 +03:00
|
|
|
|
2020-07-09 16:40:31 +03:00
|
|
|
const manifestPath = resolve(tauriFixturePath, 'Cargo.toml')
|
|
|
|
const manifestFile = readFileSync(manifestPath).toString()
|
2021-06-22 16:47:45 +03:00
|
|
|
writeFileSync(manifestPath, `workspace = { }\n${manifestFile}`)
|
2020-03-09 23:57:27 +03:00
|
|
|
|
2022-05-04 16:48:38 +03:00
|
|
|
const configPath = resolve(tauriFixturePath, 'tauri.conf.json')
|
|
|
|
const config = readFileSync(configPath).toString()
|
|
|
|
writeFileSync(configPath, config.replace('com.tauri.dev', 'com.tauri.test'))
|
|
|
|
|
2022-07-04 15:09:00 +03:00
|
|
|
await cli.run(['build', '--verbose'])
|
2021-01-30 18:15:47 +03:00
|
|
|
process.chdir(cwd)
|
2020-03-09 23:57:27 +03:00
|
|
|
})
|
|
|
|
})
|