|
| 1 | +jest.setTimeout(600000) |
| 2 | + |
| 3 | +const create = require('@vue/cli-test-utils/createTestProject') |
| 4 | +const { defaultPreset } = require('@vue/cli/lib/options') |
| 5 | +const path = require('path') |
| 6 | +const fs = require('fs-extra') |
| 7 | +const Application = require('spectron').Application |
| 8 | + |
| 9 | +const projectPath = p => path.join(process.cwd(), '__tests__/projects/build', p) |
| 10 | + |
| 11 | +test('build:electron', async () => { |
| 12 | + let project |
| 13 | + // Install vcp-electron-builder |
| 14 | + defaultPreset.plugins['vue-cli-plugin-electron-builder'] = { |
| 15 | + version: 'file:../../../' |
| 16 | + } |
| 17 | + project = await create( |
| 18 | + 'build', |
| 19 | + defaultPreset, |
| 20 | + path.join(process.cwd(), '/__tests__/projects') |
| 21 | + ) |
| 22 | + // }) |
| 23 | + const { stdout } = await project.run( |
| 24 | + 'vue-cli-service build:electron --x64 --win zip --linux zip' |
| 25 | + ) |
| 26 | + // Ensure built completes |
| 27 | + expect(stdout.indexOf('Build complete!')).not.toBe(-1) |
| 28 | + // Ensure /dist is not modified |
| 29 | + expect(project.has('dist')).toBe(false) |
| 30 | + // Ensure build successfully outputted files |
| 31 | + expect(project.has('dist_electron/bundled/index.html')).toBe(true) |
| 32 | + expect(project.has('dist_electron/bundled/favicon.ico')).toBe(true) |
| 33 | + expect(project.has('dist_electron/bundled/js')).toBe(true) |
| 34 | + expect(project.has('dist_electron/bundled/css')).toBe(true) |
| 35 | + expect(project.has('dist_electron/bundled/background.js')).toBe(true) |
| 36 | + expect(project.has('dist_electron/win-unpacked/build.exe')).toBe(true) |
| 37 | + expect(project.has('dist_electron/linux-unpacked/build')).toBe(true) |
| 38 | + // Ensure that setup file was not created |
| 39 | + expect(project.has('dist_electron/build Setup 0.1.0.exe')).toBe(false) |
| 40 | + // Ensure that zip files were created |
| 41 | + expect(project.has('dist_electron/build-0.1.0-win.zip')).toBe(true) |
| 42 | + expect(project.has('dist_electron/build-0.1.0.zip')).toBe(true) |
| 43 | + // Ensure base is set properly (for app protocol) |
| 44 | + const index = fs.readFileSync( |
| 45 | + projectPath('dist_electron/bundled/index.html'), |
| 46 | + 'utf8' |
| 47 | + ) |
| 48 | + expect(index.indexOf('<base href=app://./ >')).not.toBe(-1) |
| 49 | + const app = new Application({ |
| 50 | + path: './__tests__/projects/build/dist_electron/win-unpacked/build.exe' |
| 51 | + // path: '../electron-test/dist_electron/win-unpacked/electron-test.exe' |
| 52 | + }) |
| 53 | + await app.start() |
| 54 | + const win = app.browserWindow |
| 55 | + const client = app.client |
| 56 | + await client.waitUntilWindowLoaded() |
| 57 | + |
| 58 | + await client.getRenderProcessLogs().then(logs => { |
| 59 | + logs.forEach(log => { |
| 60 | + // Make sure there are no fatal errors |
| 61 | + expect(log.level).not.toBe('SEVERE') |
| 62 | + }) |
| 63 | + }) |
| 64 | + await client.getMainProcessLogs().then(logs => { |
| 65 | + logs.forEach(log => { |
| 66 | + // Make sure there are no fatal errors |
| 67 | + expect(log.level).not.toBe('SEVERE') |
| 68 | + }) |
| 69 | + }) |
| 70 | + // Window was created |
| 71 | + expect(await client.getWindowCount()).toBe(1) |
| 72 | + // It is not minimized |
| 73 | + expect(await win.isMinimized()).toBe(false) |
| 74 | + // Dev tools is not open |
| 75 | + expect(await win.isDevToolsOpened()).toBe(false) |
| 76 | + // Window is visible |
| 77 | + expect(await win.isVisible()).toBe(true) |
| 78 | + // Size is correct |
| 79 | + const { width, height } = await win.getBounds() |
| 80 | + expect(width).toBeGreaterThan(0) |
| 81 | + expect(height).toBeGreaterThan(0) |
| 82 | + // Load was successful |
| 83 | + expect(await app.webContents.isLoading()).toBe(false) |
| 84 | + // App is loaded properly |
| 85 | + expect(await client.getHTML('#app')).toMatchSnapshot() |
| 86 | + |
| 87 | + app.stop() |
| 88 | +}) |
0 commit comments