|
1 | 1 | jest.setTimeout(100000)
|
2 | 2 |
|
3 | 3 | const createProject = require('./createProject.helper.js')
|
| 4 | +const { readFile, writeFile } = require('fs-extra') |
| 5 | +const { join } = require('path') |
4 | 6 |
|
5 |
| -test('basic tests pass', async () => { |
6 |
| - const { project } = await createProject('spectron', false, { |
7 |
| - '@vue/cli-plugin-unit-jest': {} |
8 |
| - }) |
| 7 | +test.each(['mocha', 'jest'])( |
| 8 | + 'testWithSpectron works with %s', |
| 9 | + async testRunner => { |
| 10 | + const plugins = {} |
| 11 | + plugins[`@vue/cli-plugin-unit-${testRunner}`] = {} |
| 12 | + const { project } = await createProject( |
| 13 | + `spectron-${testRunner}`, |
| 14 | + false, |
| 15 | + plugins |
| 16 | + ) |
| 17 | + // Remove example test |
| 18 | + await project.rm('tests/unit/example.spec.js') |
9 | 19 |
|
10 |
| - // Update jest config to find test |
11 |
| - const config = JSON.parse(await project.read('package.json')) |
12 |
| - config.jest.testMatch = ['<rootDir>/tests/unit/spectron.js'] |
13 |
| - await project.write('package.json', JSON.stringify(config)) |
| 20 | + // Copy electron test |
| 21 | + const testFile = (await readFile( |
| 22 | + `./generator/templates/tests-${testRunner}/tests/unit/electron.spec.js`, |
| 23 | + 'utf8' |
| 24 | + )) |
| 25 | + // Fix some unknown error |
| 26 | + .replace('testWithSpectron()', 'testWithSpectron({ mode: "production" })') |
| 27 | + await writeFile(join(project.dir, 'tests/unit/electron.spec.js'), testFile) |
14 | 28 |
|
15 |
| - // Create spectron test |
16 |
| - await project.write( |
17 |
| - 'tests/unit/spectron.js', |
18 |
| - `jest.setTimeout(60000) |
19 |
| - const { testWithSpectron } = require('vue-cli-plugin-electron-builder') |
20 |
| - test('app loads a window', async () => { |
21 |
| - const { app, stdout, stopServe } = await testWithSpectron({mode: 'production'}) |
22 |
| - expect(await app.client.getWindowCount()).toBe(1) |
23 |
| - // App is served in production mode |
24 |
| - expect(stdout.indexOf('App is served in production mode.')).not.toBe(-1) |
25 |
| - await stopServe() |
26 |
| - }) |
27 |
| - ` |
28 |
| - ) |
29 |
| - process.env.NODE_ENV = 'production' |
30 |
| - await project.run('vue-cli-service test:unit') |
31 |
| -}) |
| 29 | + await project.run('vue-cli-service test:unit') |
| 30 | + } |
| 31 | +) |
0 commit comments