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')
|
|
|
|
const cli = require('~/index.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-02-10 22:45:41 +03:00
|
|
|
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-02-10 22:45:41 +03:00
|
|
|
cli.run(['build', '--verbose'])
|
2021-01-30 18:15:47 +03:00
|
|
|
process.chdir(cwd)
|
2020-03-09 23:57:27 +03:00
|
|
|
})
|
|
|
|
})
|