2020-03-07 19:40:24 +03:00
|
|
|
const path = require('path')
|
|
|
|
const fixtureSetup = require('../fixtures/app-test-setup')
|
2020-03-09 23:57:27 +03:00
|
|
|
const appDir = path.join(fixtureSetup.fixtureDir, 'app')
|
|
|
|
const distDir = path.join(appDir, 'dist')
|
2020-03-07 19:40:24 +03:00
|
|
|
|
|
|
|
const spawn = require('helpers/spawn').spawn
|
|
|
|
|
2021-01-30 18:15:47 +03:00
|
|
|
function runBuildTest(args) {
|
2020-03-09 23:57:27 +03:00
|
|
|
fixtureSetup.initJest('app')
|
2021-01-30 18:15:47 +03:00
|
|
|
const { build } = require('dist/api/cli')
|
2020-03-07 19:40:24 +03:00
|
|
|
return new Promise(async (resolve, reject) => {
|
|
|
|
try {
|
|
|
|
let success = false
|
2020-05-05 15:10:39 +03:00
|
|
|
const { server, responses } = fixtureSetup.startServer(() => {
|
2020-03-07 19:40:24 +03:00
|
|
|
success = true
|
2020-03-30 05:41:45 +03:00
|
|
|
try {
|
|
|
|
process.kill(appPid)
|
|
|
|
} catch {}
|
2020-03-07 19:40:24 +03:00
|
|
|
// wait for the app process to be killed
|
|
|
|
setTimeout(resolve, 2000)
|
|
|
|
})
|
2021-01-30 18:15:47 +03:00
|
|
|
process.chdir(appDir)
|
2021-04-13 07:47:34 +03:00
|
|
|
console.log(server)
|
2021-04-14 16:50:15 +03:00
|
|
|
const { promise } = await build(args)
|
|
|
|
await promise
|
2020-03-07 19:40:24 +03:00
|
|
|
|
2021-01-30 18:15:47 +03:00
|
|
|
const artifactFolder = args.debug ? 'debug' : 'release'
|
2020-08-19 05:36:46 +03:00
|
|
|
const artifactPath = path.resolve(
|
|
|
|
appDir,
|
|
|
|
`src-tauri/target/${artifactFolder}/app`
|
|
|
|
)
|
2020-03-07 19:40:24 +03:00
|
|
|
|
|
|
|
const appPid = spawn(
|
2020-08-19 05:36:46 +03:00
|
|
|
process.platform === 'win32'
|
|
|
|
? `${artifactPath}.exe`
|
|
|
|
: artifactPath.replace(
|
|
|
|
`${artifactFolder}/app`,
|
|
|
|
`${artifactFolder}/./app`
|
|
|
|
),
|
2020-03-07 19:40:24 +03:00
|
|
|
[],
|
|
|
|
null
|
|
|
|
)
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
if (!success) {
|
|
|
|
server.close(() => {
|
|
|
|
try {
|
|
|
|
process.kill(appPid)
|
|
|
|
} catch {}
|
2020-08-19 05:36:46 +03:00
|
|
|
const failedCommands = Object.keys(responses)
|
|
|
|
.filter((k) => responses[k] === null)
|
|
|
|
.join(', ')
|
2020-05-05 15:10:39 +03:00
|
|
|
reject("App didn't reply to " + failedCommands)
|
2020-03-07 19:40:24 +03:00
|
|
|
})
|
|
|
|
}
|
2020-03-30 05:41:45 +03:00
|
|
|
}, 15000)
|
2020-03-07 19:40:24 +03:00
|
|
|
} catch (error) {
|
|
|
|
reject(error)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
describe('Tauri Build', () => {
|
|
|
|
const build = {
|
|
|
|
devPath: distDir,
|
2020-10-18 02:53:24 +03:00
|
|
|
distDir: distDir,
|
|
|
|
withGlobalTauri: true
|
2020-03-07 19:40:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
it.each`
|
2020-08-19 05:36:46 +03:00
|
|
|
mode | flag
|
2021-02-26 04:07:30 +03:00
|
|
|
${'custom-protocol'} | ${'debug'}
|
|
|
|
${'custom-protocol'} | ${'release'}
|
2020-03-07 19:40:24 +03:00
|
|
|
`('works with the $mode $flag mode', ({ mode, flag }) => {
|
|
|
|
return runBuildTest({
|
2021-01-30 18:15:47 +03:00
|
|
|
debug: flag === 'debug',
|
|
|
|
config: {
|
|
|
|
build,
|
|
|
|
tauri: {
|
|
|
|
allowlist: {
|
|
|
|
all: true
|
|
|
|
}
|
2020-03-07 19:40:24 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|