Skip to content

Commit eb05a2d

Browse files
authored
merge tests into v1-dev branch as they work now (#28)
* initial test setup (broken) * update file path (still broken with same error) * write build tests (works now) No serve tests yet, coming soon.
1 parent ec7af27 commit eb05a2d

File tree

10 files changed

+4064
-116
lines changed

10 files changed

+4064
-116
lines changed

.eslintrc.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
module.exports = {
2-
"extends": "standard"
3-
};
2+
extends: 'standard',
3+
env: {
4+
jest: true
5+
}
6+
}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,5 @@ typings/
5757
# dotenv environment variables file
5858
.env
5959

60+
# Vue Cli test projects
61+
/__tests__/projects

.vscode/launch.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"type": "node",
9+
"name": "vscode-jest-tests",
10+
"request": "launch",
11+
"args": ["--runInBand"],
12+
"cwd": "${workspaceFolder}",
13+
"console": "integratedTerminal",
14+
"internalConsoleOptions": "neverOpen",
15+
"program": "${workspaceFolder}/node_modules/jest/bin/jest"
16+
},
17+
{
18+
"type": "node",
19+
"request": "launch",
20+
"name": "Run tests",
21+
"console": "integratedTerminal",
22+
"program": "${workspaceFolder}\\node_modules/jest/bin/jest"
23+
}
24+
]
25+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`build:electron 1`] = `
4+
"<div id=\\"app\\"><img src=\\"./img/logo.82b9c7a5.png\\"><div data-v-20cac705=\\"\\" class=\\"hello\\"><h1 data-v-20cac705=\\"\\">Welcome to Your Vue.js App</h1><p data-v-20cac705=\\"\\">
5+
For guide and recipes on how to configure / customize this project,<br data-v-20cac705=\\"\\">
6+
check out the
7+
<a data-v-20cac705=\\"\\" href=\\"https://cli.vuejs.org\\" target=\\"_blank\\">vue-cli documentation</a>.
8+
</p><h3 data-v-20cac705=\\"\\">Installed CLI Plugins</h3><ul data-v-20cac705=\\"\\"><li data-v-20cac705=\\"\\"><a data-v-20cac705=\\"\\" href=\\"https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-babel\\" target=\\"_blank\\">babel</a></li><li data-v-20cac705=\\"\\"><a data-v-20cac705=\\"\\" href=\\"https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-eslint\\" target=\\"_blank\\">eslint</a></li><li data-v-20cac705=\\"\\"><a data-v-20cac705=\\"\\" href=\\"https://www.npmjs.com/package/vue-cli-plugin-electron-builder\\" target=\\"_blank\\">electron-builder</a></li></ul><h3 data-v-20cac705=\\"\\">Essential Links</h3><ul data-v-20cac705=\\"\\"><li data-v-20cac705=\\"\\"><a data-v-20cac705=\\"\\" href=\\"https://vuejs.org\\" target=\\"_blank\\">Core Docs</a></li><li data-v-20cac705=\\"\\"><a data-v-20cac705=\\"\\" href=\\"https://forum.vuejs.org\\" target=\\"_blank\\">Forum</a></li><li data-v-20cac705=\\"\\"><a data-v-20cac705=\\"\\" href=\\"https://chat.vuejs.org\\" target=\\"_blank\\">Community Chat</a></li><li data-v-20cac705=\\"\\"><a data-v-20cac705=\\"\\" href=\\"https://twitter.com/vuejs\\" target=\\"_blank\\">Twitter</a></li></ul><h3 data-v-20cac705=\\"\\">Ecosystem</h3><ul data-v-20cac705=\\"\\"><li data-v-20cac705=\\"\\"><a data-v-20cac705=\\"\\" href=\\"https://router.vuejs.org\\" target=\\"_blank\\">vue-router</a></li><li data-v-20cac705=\\"\\"><a data-v-20cac705=\\"\\" href=\\"https://vuex.vuejs.org\\" target=\\"_blank\\">vuex</a></li><li data-v-20cac705=\\"\\"><a data-v-20cac705=\\"\\" href=\\"https://github.com/vuejs/vue-devtools#vue-devtools\\" target=\\"_blank\\">vue-devtools</a></li><li data-v-20cac705=\\"\\"><a data-v-20cac705=\\"\\" href=\\"https://vue-loader.vuejs.org\\" target=\\"_blank\\">vue-loader</a></li><li data-v-20cac705=\\"\\"><a data-v-20cac705=\\"\\" href=\\"https://github.com/vuejs/awesome-vue\\" target=\\"_blank\\">awesome-vue</a></li></ul></div></div>"
9+
`;

__tests__/build.spec.js

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
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+
})

generator/index.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@ const fs = require('fs')
22

33
module.exports = api => {
44
api.render('./template')
5-
// Read existing index.html and .gitignore
6-
let index = fs.readFileSync(api.resolve('./public/index.html'), 'utf8')
7-
let gitignore = fs.readFileSync(api.resolve('./.gitignore'), 'utf8')
8-
// Add base element inside <head> tag
9-
index = index.replace(
10-
/^\s*?<head.*?>\s*?$/m,
11-
`<head>\n <% if (BASE_URL === './') { %><base href="app://./" /><% } %>`
12-
)
13-
// Add /dist_electron to gitignore
14-
gitignore = gitignore + '\n#Electron-builder output\n/dist_electron'
155
api.onCreateComplete(() => {
6+
// Read existing index.html and .gitignore
7+
let index = fs.readFileSync(api.resolve('./public/index.html'), 'utf8')
8+
let gitignore = fs.readFileSync(api.resolve('./.gitignore'), 'utf8')
9+
// Add base element inside <head> tag
10+
index = index.replace(
11+
/^\s*?<head.*?>\s*?$/m,
12+
`<head>\n <% if (BASE_URL === './') { %><base href="app://./" /><% } %>`
13+
)
14+
// Add /dist_electron to gitignore
15+
gitignore = gitignore + '\n#Electron-builder output\n/dist_electron'
1616
// Write updated files
1717
fs.writeFileSync(api.resolve('./public/index.html'), index)
1818
fs.writeFileSync(api.resolve('./.gitignore'), gitignore)

jest.config.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
module.exports = {
2+
// moduleFileExtensions: ['js', 'json'],
3+
// transform: {
4+
// // '^.+\\.vue$': 'vue-jest',
5+
// // '.+\\.(css|styl|less|sass|scss|png|jpg|ttf|woff|woff2)$': 'jest-transform-stub',
6+
// '^.+\\.jsx?$': 'babel-jest'
7+
// }
8+
// moduleNameMapper: {
9+
// '^@/(.*)$': '<rootDir>/src/$1'
10+
// },
11+
// // snapshotSerializers: ['jest-serializer-vue'],
12+
// testMatch: ['<rootDir>/__tests__/**.spec.js']
13+
testEnvironment: 'node',
14+
setupFiles: ['<rootDir>/testSetup.js'],
15+
testPathIgnorePatterns: ['/node_modules/', '/__tests__/projects/']
16+
}

package.json

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
"version": "1.0.0-alpha.11",
44
"description": "A Vue Cli 3 plugin for Electron with no required configuration",
55
"main": "index.js",
6+
"scripts": {
7+
"test": "jest --runInBand",
8+
"pretest": "rimraf __tests__/projects/*"
9+
},
610
"keywords": [
711
"electron",
812
"vue",
@@ -28,10 +32,19 @@
2832
"webpack-target-electron-renderer": "^0.4.0"
2933
},
3034
"devDependencies": {
35+
"@vue/cli": "^3.0.0-rc.3",
36+
"@vue/cli-plugin-babel": "^3.0.0-rc.3",
37+
"@vue/cli-plugin-eslint": "^3.0.0-rc.3",
38+
"@vue/cli-test-utils": "^3.0.0-rc.3",
3139
"eslint-config-standard": "^11.0.0",
3240
"eslint-plugin-import": "^2.12.0",
3341
"eslint-plugin-node": "^6.0.1",
3442
"eslint-plugin-promise": "^3.8.0",
35-
"eslint-plugin-standard": "^3.1.0"
43+
"eslint-plugin-standard": "^3.1.0",
44+
"jest": "^23.2.0",
45+
"lnk": "^1.1.0",
46+
"rimraf": "^2.6.2",
47+
"spectron": "^3.8.0",
48+
"vue": "^2.5.16"
3649
}
3750
}

testSetup.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const lnk = require('lnk')
2+
const fs = require('fs-extra')
3+
process.env.VUE_CLI_TEST = true
4+
fs.removeSync('./node_modules/vue-cli-plugin-electron-builder')
5+
lnk.sync(['./'], './node_modules/vue-cli-plugin-electron-builder')

0 commit comments

Comments
 (0)