62 lines
2.9 KiB
JavaScript
62 lines
2.9 KiB
JavaScript
// Launch the compiled app with isolated data and capture its update panel without signing in.
|
|
const { app } = require('electron')
|
|
const { mkdirSync, writeFileSync } = require('node:fs')
|
|
const { join } = require('node:path')
|
|
const assert = require('node:assert/strict')
|
|
|
|
const profile = join(__dirname, '../dist/smoke-profile')
|
|
mkdirSync(profile, { recursive: true })
|
|
mkdirSync(join(__dirname, '../dist/local'), { recursive: true })
|
|
app.setName('capsule-local')
|
|
app.setVersion(require('../package.json').version)
|
|
app.setPath('appData', profile)
|
|
const timeout = setTimeout(() => {
|
|
console.error('Smoke test timed out.')
|
|
app.exit(1)
|
|
}, 30000)
|
|
app.on('browser-window-created', (_event, window) => {
|
|
window.show = () => {} // Exercise the real app without interrupting the user's desktop.
|
|
window.webContents.once('did-finish-load', async () => {
|
|
try {
|
|
const state = await window.webContents.executeJavaScript(`(async () => {
|
|
const state = await window.capsule.updateStatus()
|
|
await window.capsule.checkForUpdates()
|
|
await new Promise(resolve => setTimeout(resolve, 250))
|
|
return {
|
|
state,
|
|
panelVisible: !document.getElementById('capsule-updates').hidden,
|
|
checkHidden: document.getElementById('update-check').hidden,
|
|
restartHidden: document.getElementById('update-install').hidden,
|
|
label: document.getElementById('update-status').textContent
|
|
}
|
|
})()`)
|
|
assert.equal(state.state.status, 'disabled')
|
|
assert.equal(state.state.currentVersion, require('../package.json').version)
|
|
assert.equal(state.panelVisible, true)
|
|
assert.equal(state.checkHidden, true)
|
|
assert.equal(state.restartHidden, true)
|
|
assert.match(state.label, /automatic updates are disabled/)
|
|
assert.equal(app.getPath('userData'), join(profile, 'capsule-local'))
|
|
const image = await window.webContents.capturePage()
|
|
writeFileSync(join(__dirname, '../dist/local/smoke.png'), image.toPNG())
|
|
// Exercise the ready prompt with synthetic state; never invoke installation.
|
|
window.webContents.send('capsule:updates:changed', {
|
|
status: 'ready', currentVersion: app.getVersion(), version: '0.1.1', percent: 100
|
|
})
|
|
const readyVisible = await window.webContents.executeJavaScript(`new Promise(resolve => setTimeout(() => {
|
|
const button = document.getElementById('update-install')
|
|
resolve(!button.hidden && document.getElementById('update-status').textContent.includes('Save your work'))
|
|
}, 100))`)
|
|
assert.equal(readyVisible, true)
|
|
writeFileSync(join(__dirname, '../dist/local/smoke-ready.png'), (await window.webContents.capturePage()).toPNG())
|
|
console.log(JSON.stringify({ smoke: 'passed', ...state }))
|
|
clearTimeout(timeout)
|
|
app.exit(0)
|
|
} catch (error) {
|
|
console.error(error)
|
|
app.exit(1)
|
|
}
|
|
})
|
|
})
|
|
require('../out/main/index.js')
|