Skip to content

Commit

Permalink
Fixed Electron closing. Do not spy on anything
Browse files Browse the repository at this point in the history
  • Loading branch information
garrettmflynn committed Oct 14, 2024
1 parent f1dcae5 commit 7949beb
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 37 deletions.
2 changes: 0 additions & 2 deletions packages/core/vite/plugins/commoners.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,6 @@ export default ({
const resolvedIcon = rawIconSrc ? resolve(configRoot, rawIconSrc) : null
const iconPath = resolvedIcon ? getAssetLinkPath(resolvedIcon, assetOutDir, relTo) : null

console.log('IS DEV', target, dev)

const globalObject = {

NAME: config.name,
Expand Down
12 changes: 4 additions & 8 deletions packages/testing/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,6 @@ type BrowserTestOutput = {

page: Page,
browser: Browser,

toSpyOn: { object: any, method: string }[],

url: string,
server?: any

Expand Down Expand Up @@ -131,25 +128,24 @@ export const open = async (

return {
...states,
toSpyOn: [
{ object: process, method: 'exit' } // Ensure Electron will exit gracefully
],

// Override cleanup function
cleanup: async () => {

cleanup() // Cleanup the command

// Close launched Electron build
// Close Electron instances
if (isElectron) {
await states.page.evaluate(() => {
const { commoners } = globalThis
return commoners.READY.then(() => commoners.DESKTOP.quit())
})
}

// Close all active windows
// Close Playwright browsers
if (states.browser) await states.browser.close()

// Close active servers
if (states.server) states.server.close()
}

Expand Down
32 changes: 16 additions & 16 deletions tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,41 +10,41 @@ import { resolve } from 'node:path'
import { name } from './demo/commoners.config'
import { projectBase, registerBuildTest, registerStartTest } from './utils'

// describe('Custom project base is loaded', () => {
describe('Custom project base is loaded', () => {

// test('Config is resolved', () => {
// const configPath = resolveConfigPath(projectBase)
// expect(configPath).toBe(resolve(projectBase, 'commoners.config.ts'))
// })
test('Config is resolved', () => {
const configPath = resolveConfigPath(projectBase)
expect(configPath).toBe(resolve(projectBase, 'commoners.config.ts'))
})

// test('Config is loaded', async () => {
// const config = await loadConfigFromFile(projectBase)
// expect(config.name).toBe(name)
// })
// })
test('Config is loaded', async () => {
const config = await loadConfigFromFile(projectBase)
expect(config.name).toBe(name)
})
})

describe('Start', () => {

// registerStartTest('Web')
registerStartTest('Web')

registerStartTest(
'Desktop',
{ target: 'electron'}
)

// // NOTE: Skipped because Ruby Gems needs to be updated
// registerStartTest('Mobile', { target: 'mobile' }, false)
// NOTE: Skipped because Ruby Gems needs to be updated
registerStartTest('Mobile', { target: 'mobile' }, false)

})

describe('Build and Launch', () => {
// registerBuildTest('Web', { target: 'web' })
// registerBuildTest('PWA', { target: 'pwa' })
registerBuildTest('Web', { target: 'web' })
registerBuildTest('PWA', { target: 'pwa' })

registerBuildTest(
'Desktop',
{ target: 'electron' }
)

// registerBuildTest('Mobile', { target: 'mobile' }, false)
registerBuildTest('Mobile', { target: 'mobile' }, false)
})
11 changes: 0 additions & 11 deletions tests/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,6 @@ const getServices = async (output) => {

export const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms))

export const spyOnAll = (output) => {
const { toSpyOn = [] } = output
toSpyOn.forEach(({ object, method }) => {
const mockExit = vi.spyOn(object, method).mockImplementation(() => {
mockExit.mockRestore()
});
})
}

const e2eTests = {
basic: (output, { target }, isDev = true) => {

Expand Down Expand Up @@ -144,7 +135,6 @@ export const registerStartTest = (name, { target = 'web' } = {}, enabled = true)
const output = {}
beforeAll(async () => {
const _output = await open(projectBase, { target })

Check failure on line 137 in tests/utils.ts

View workflow job for this annotation

GitHub Actions / Back-end tests on windows-latest

tests/index.test.ts > Start > Desktop

Error: process.exit unexpectedly called with "1" ❯ tests/utils.ts:137:23
spyOnAll(_output)
Object.assign(output, _output)

})
Expand Down Expand Up @@ -228,7 +218,6 @@ export const registerBuildTest = (name, { target = 'web', publish = false }: Bui
const output = {}
beforeAll(async () => {
const _output = await open(projectBase, opts, true)
spyOnAll(_output)
Object.assign(output, _output)
})

Expand Down

0 comments on commit 7949beb

Please sign in to comment.