tauri/tooling/cli.js/test/jest/__tests__/build.spec.js

88 lines
2.1 KiB
JavaScript
Raw Normal View History

2020-03-07 19:40:24 +03:00
const path = require('path')
const fixtureSetup = require('../fixtures/app-test-setup')
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
function runBuildTest(args) {
fixtureSetup.initJest('app')
const { build } = require('dist/api/cli')
2020-03-07 19:40:24 +03:00
return new Promise(async (resolve, reject) => {
try {
let success = false
const { server, responses } = fixtureSetup.startServer(() => {
2020-03-07 19:40:24 +03:00
success = true
try {
process.kill(appPid)
} catch {}
2020-03-07 19:40:24 +03:00
// wait for the app process to be killed
setTimeout(resolve, 2000)
})
process.chdir(appDir)
console.log(server)
const { promise } = await build(args)
await promise
2020-03-07 19:40:24 +03:00
const artifactFolder = args.debug ? 'debug' : 'release'
const artifactPath = path.resolve(
appDir,
`src-tauri/target/${artifactFolder}/app`
)
2020-03-07 19:40:24 +03:00
const appPid = spawn(
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 {}
const failedCommands = Object.keys(responses)
.filter((k) => responses[k] === null)
.join(', ')
reject("App didn't reply to " + failedCommands)
2020-03-07 19:40:24 +03:00
})
}
}, 15000)
2020-03-07 19:40:24 +03:00
} catch (error) {
reject(error)
}
})
}
describe('Tauri Build', () => {
const build = {
devPath: distDir,
distDir: distDir,
withGlobalTauri: true
2020-03-07 19:40:24 +03:00
}
it.each`
mode | flag
${'custom-protocol'} | ${'debug'}
${'custom-protocol'} | ${'release'}
2020-03-07 19:40:24 +03:00
`('works with the $mode $flag mode', ({ mode, flag }) => {
return runBuildTest({
debug: flag === 'debug',
config: {
build,
tauri: {
allowlist: {
all: true
}
2020-03-07 19:40:24 +03:00
}
}
})
})
})