Skip to content

Commit 01973ed

Browse files
committed
write typescript tests
1 parent d9629e9 commit 01973ed

File tree

5 files changed

+182
-132
lines changed

5 files changed

+182
-132
lines changed

__tests__/__snapshots__/build.spec.js.snap

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,11 @@ exports[`build:electron 1`] = `
77
<a data-v-20cac705=\\"\\" href=\\"https://cli.vuejs.org\\" target=\\"_blank\\">vue-cli documentation</a>.
88
</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>"
99
`;
10+
11+
exports[`build:electron-ts 1`] = `
12+
"<div id=\\"app\\"><img src=\\"./img/logo.82b9c7a5.png\\"><div data-v-a85a1ef8=\\"\\" class=\\"hello\\"><h1 data-v-a85a1ef8=\\"\\">Welcome to Your Vue.js + TypeScript App</h1><p data-v-a85a1ef8=\\"\\">
13+
For guide and recipes on how to configure / customize this project,<br data-v-a85a1ef8=\\"\\">
14+
check out the
15+
<a data-v-a85a1ef8=\\"\\" href=\\"https://cli.vuejs.org\\" target=\\"_blank\\">vue-cli documentation</a>.
16+
</p><h3 data-v-a85a1ef8=\\"\\">Installed CLI Plugins</h3><ul data-v-a85a1ef8=\\"\\"><li data-v-a85a1ef8=\\"\\"><a data-v-a85a1ef8=\\"\\" href=\\"https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-babel\\" target=\\"_blank\\">babel</a></li><li data-v-a85a1ef8=\\"\\"><a data-v-a85a1ef8=\\"\\" href=\\"https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-eslint\\" target=\\"_blank\\">eslint</a></li><li data-v-a85a1ef8=\\"\\"><a data-v-a85a1ef8=\\"\\" href=\\"https://www.npmjs.com/package/vue-cli-plugin-electron-builder\\" target=\\"_blank\\">electron-builder</a></li><li data-v-a85a1ef8=\\"\\"><a data-v-a85a1ef8=\\"\\" href=\\"https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-typescript\\" target=\\"_blank\\">typescript</a></li></ul><h3 data-v-a85a1ef8=\\"\\">Essential Links</h3><ul data-v-a85a1ef8=\\"\\"><li data-v-a85a1ef8=\\"\\"><a data-v-a85a1ef8=\\"\\" href=\\"https://vuejs.org\\" target=\\"_blank\\">Core Docs</a></li><li data-v-a85a1ef8=\\"\\"><a data-v-a85a1ef8=\\"\\" href=\\"https://forum.vuejs.org\\" target=\\"_blank\\">Forum</a></li><li data-v-a85a1ef8=\\"\\"><a data-v-a85a1ef8=\\"\\" href=\\"https://chat.vuejs.org\\" target=\\"_blank\\">Community Chat</a></li><li data-v-a85a1ef8=\\"\\"><a data-v-a85a1ef8=\\"\\" href=\\"https://twitter.com/vuejs\\" target=\\"_blank\\">Twitter</a></li></ul><h3 data-v-a85a1ef8=\\"\\">Ecosystem</h3><ul data-v-a85a1ef8=\\"\\"><li data-v-a85a1ef8=\\"\\"><a data-v-a85a1ef8=\\"\\" href=\\"https://router.vuejs.org\\" target=\\"_blank\\">vue-router</a></li><li data-v-a85a1ef8=\\"\\"><a data-v-a85a1ef8=\\"\\" href=\\"https://vuex.vuejs.org\\" target=\\"_blank\\">vuex</a></li><li data-v-a85a1ef8=\\"\\"><a data-v-a85a1ef8=\\"\\" href=\\"https://github.com/vuejs/vue-devtools#vue-devtools\\" target=\\"_blank\\">vue-devtools</a></li><li data-v-a85a1ef8=\\"\\"><a data-v-a85a1ef8=\\"\\" href=\\"https://vue-loader.vuejs.org\\" target=\\"_blank\\">vue-loader</a></li><li data-v-a85a1ef8=\\"\\"><a data-v-a85a1ef8=\\"\\" href=\\"https://github.com/vuejs/awesome-vue\\" target=\\"_blank\\">awesome-vue</a></li></ul></div></div>"
17+
`;

__tests__/__snapshots__/serve.spec.js.snap

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,11 @@ exports[`serve:electron 1`] = `
77
<a data-v-656039f0=\\"\\" href=\\"https://cli.vuejs.org\\" target=\\"_blank\\">vue-cli documentation</a>.
88
</p><h3 data-v-656039f0=\\"\\">Installed CLI Plugins</h3><ul data-v-656039f0=\\"\\"><li data-v-656039f0=\\"\\"><a data-v-656039f0=\\"\\" href=\\"https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-babel\\" target=\\"_blank\\">babel</a></li><li data-v-656039f0=\\"\\"><a data-v-656039f0=\\"\\" href=\\"https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-eslint\\" target=\\"_blank\\">eslint</a></li><li data-v-656039f0=\\"\\"><a data-v-656039f0=\\"\\" href=\\"https://www.npmjs.com/package/vue-cli-plugin-electron-builder\\" target=\\"_blank\\">electron-builder</a></li></ul><h3 data-v-656039f0=\\"\\">Essential Links</h3><ul data-v-656039f0=\\"\\"><li data-v-656039f0=\\"\\"><a data-v-656039f0=\\"\\" href=\\"https://vuejs.org\\" target=\\"_blank\\">Core Docs</a></li><li data-v-656039f0=\\"\\"><a data-v-656039f0=\\"\\" href=\\"https://forum.vuejs.org\\" target=\\"_blank\\">Forum</a></li><li data-v-656039f0=\\"\\"><a data-v-656039f0=\\"\\" href=\\"https://chat.vuejs.org\\" target=\\"_blank\\">Community Chat</a></li><li data-v-656039f0=\\"\\"><a data-v-656039f0=\\"\\" href=\\"https://twitter.com/vuejs\\" target=\\"_blank\\">Twitter</a></li></ul><h3 data-v-656039f0=\\"\\">Ecosystem</h3><ul data-v-656039f0=\\"\\"><li data-v-656039f0=\\"\\"><a data-v-656039f0=\\"\\" href=\\"https://router.vuejs.org\\" target=\\"_blank\\">vue-router</a></li><li data-v-656039f0=\\"\\"><a data-v-656039f0=\\"\\" href=\\"https://vuex.vuejs.org\\" target=\\"_blank\\">vuex</a></li><li data-v-656039f0=\\"\\"><a data-v-656039f0=\\"\\" href=\\"https://github.com/vuejs/vue-devtools#vue-devtools\\" target=\\"_blank\\">vue-devtools</a></li><li data-v-656039f0=\\"\\"><a data-v-656039f0=\\"\\" href=\\"https://vue-loader.vuejs.org\\" target=\\"_blank\\">vue-loader</a></li><li data-v-656039f0=\\"\\"><a data-v-656039f0=\\"\\" href=\\"https://github.com/vuejs/awesome-vue\\" target=\\"_blank\\">awesome-vue</a></li></ul></div></div>"
99
`;
10+
11+
exports[`serve:electron-ts 1`] = `
12+
"<div id=\\"app\\"><img src=\\"/img/logo.82b9c7a5.png\\"><div data-v-656039f0=\\"\\" class=\\"hello\\"><h1 data-v-656039f0=\\"\\">Welcome to Your Vue.js + TypeScript App</h1><p data-v-656039f0=\\"\\">
13+
For guide and recipes on how to configure / customize this project,<br data-v-656039f0=\\"\\">
14+
check out the
15+
<a data-v-656039f0=\\"\\" href=\\"https://cli.vuejs.org\\" target=\\"_blank\\">vue-cli documentation</a>.
16+
</p><h3 data-v-656039f0=\\"\\">Installed CLI Plugins</h3><ul data-v-656039f0=\\"\\"><li data-v-656039f0=\\"\\"><a data-v-656039f0=\\"\\" href=\\"https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-babel\\" target=\\"_blank\\">babel</a></li><li data-v-656039f0=\\"\\"><a data-v-656039f0=\\"\\" href=\\"https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-eslint\\" target=\\"_blank\\">eslint</a></li><li data-v-656039f0=\\"\\"><a data-v-656039f0=\\"\\" href=\\"https://www.npmjs.com/package/vue-cli-plugin-electron-builder\\" target=\\"_blank\\">electron-builder</a></li><li data-v-656039f0=\\"\\"><a data-v-656039f0=\\"\\" href=\\"https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-typescript\\" target=\\"_blank\\">typescript</a></li></ul><h3 data-v-656039f0=\\"\\">Essential Links</h3><ul data-v-656039f0=\\"\\"><li data-v-656039f0=\\"\\"><a data-v-656039f0=\\"\\" href=\\"https://vuejs.org\\" target=\\"_blank\\">Core Docs</a></li><li data-v-656039f0=\\"\\"><a data-v-656039f0=\\"\\" href=\\"https://forum.vuejs.org\\" target=\\"_blank\\">Forum</a></li><li data-v-656039f0=\\"\\"><a data-v-656039f0=\\"\\" href=\\"https://chat.vuejs.org\\" target=\\"_blank\\">Community Chat</a></li><li data-v-656039f0=\\"\\"><a data-v-656039f0=\\"\\" href=\\"https://twitter.com/vuejs\\" target=\\"_blank\\">Twitter</a></li></ul><h3 data-v-656039f0=\\"\\">Ecosystem</h3><ul data-v-656039f0=\\"\\"><li data-v-656039f0=\\"\\"><a data-v-656039f0=\\"\\" href=\\"https://router.vuejs.org\\" target=\\"_blank\\">vue-router</a></li><li data-v-656039f0=\\"\\"><a data-v-656039f0=\\"\\" href=\\"https://vuex.vuejs.org\\" target=\\"_blank\\">vuex</a></li><li data-v-656039f0=\\"\\"><a data-v-656039f0=\\"\\" href=\\"https://github.com/vuejs/vue-devtools#vue-devtools\\" target=\\"_blank\\">vue-devtools</a></li><li data-v-656039f0=\\"\\"><a data-v-656039f0=\\"\\" href=\\"https://vue-loader.vuejs.org\\" target=\\"_blank\\">vue-loader</a></li><li data-v-656039f0=\\"\\"><a data-v-656039f0=\\"\\" href=\\"https://github.com/vuejs/awesome-vue\\" target=\\"_blank\\">awesome-vue</a></li></ul></div></div>"
17+
`;

__tests__/build.spec.js

Lines changed: 91 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -6,83 +6,100 @@ const path = require('path')
66
const fs = require('fs-extra')
77
const Application = require('spectron').Application
88

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()
9+
const runTests = useTS =>
10+
new Promise(async resolve => {
11+
let preset = { ...defaultPreset }
12+
let projectName = 'build'
13+
if (useTS) {
14+
defaultPreset.plugins['@vue/cli-plugin-typescript'] = {}
15+
projectName += '-ts'
16+
}
17+
const projectPath = p =>
18+
path.join(process.cwd(), '__tests__/projects/' + projectName, p)
19+
// Install vcp-electron-builder
20+
defaultPreset.plugins['vue-cli-plugin-electron-builder'] = {}
21+
const project = await create(
22+
projectName,
23+
preset,
24+
path.join(process.cwd(), '/__tests__/projects')
25+
)
26+
const { stdout } = await project.run(
27+
'vue-cli-service build:electron --x64 --win zip --linux zip'
28+
)
29+
// Ensure built completes
30+
expect(stdout.indexOf('Build complete!')).not.toBe(-1)
31+
// Ensure /dist is not modified
32+
expect(project.has('dist')).toBe(false)
33+
// Ensure build successfully outputted files
34+
expect(project.has('dist_electron/bundled/index.html')).toBe(true)
35+
expect(project.has('dist_electron/bundled/favicon.ico')).toBe(true)
36+
expect(project.has('dist_electron/bundled/js')).toBe(true)
37+
expect(project.has('dist_electron/bundled/css')).toBe(true)
38+
expect(project.has('dist_electron/bundled/background.js')).toBe(true)
39+
expect(project.has(`dist_electron/win-unpacked/${projectName}.exe`)).toBe(
40+
true
41+
)
42+
expect(project.has(`dist_electron/linux-unpacked/${projectName}`)).toBe(
43+
true
44+
)
45+
// Ensure that setup file was not created
46+
expect(project.has(`dist_electron/${projectName} Setup 0.1.0.exe`)).toBe(
47+
false
48+
)
49+
// Ensure that zip files were created
50+
expect(project.has(`dist_electron/${projectName}-0.1.0-win.zip`)).toBe(true)
51+
expect(project.has(`dist_electron/${projectName}-0.1.0.zip`)).toBe(true)
52+
// Ensure base is set properly (for app protocol)
53+
const index = fs.readFileSync(
54+
projectPath('dist_electron/bundled/index.html'),
55+
'utf8'
56+
)
57+
expect(index.indexOf('<base href=app://./ >')).not.toBe(-1)
58+
const app = new Application({
59+
path: `./__tests__/projects/${projectName}/dist_electron/win-unpacked/${projectName}.exe`
60+
// path: '../electron-test/dist_electron/win-unpacked/electron-test.exe'
61+
})
62+
await app.start()
63+
const win = app.browserWindow
64+
const client = app.client
65+
await client.waitUntilWindowLoaded()
5766

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')
67+
await client.getRenderProcessLogs().then(logs => {
68+
logs.forEach(log => {
69+
// Make sure there are no fatal errors
70+
expect(log.level).not.toBe('SEVERE')
71+
})
6272
})
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')
73+
await client.getMainProcessLogs().then(logs => {
74+
logs.forEach(log => {
75+
// Make sure there are no fatal errors
76+
expect(log.level).not.toBe('SEVERE')
77+
})
6878
})
79+
// Window was created
80+
expect(await client.getWindowCount()).toBe(1)
81+
// It is not minimized
82+
expect(await win.isMinimized()).toBe(false)
83+
// Dev tools is not open
84+
expect(await win.isDevToolsOpened()).toBe(false)
85+
// Window is visible
86+
expect(await win.isVisible()).toBe(true)
87+
// Size is correct
88+
const { width, height } = await win.getBounds()
89+
expect(width).toBeGreaterThan(0)
90+
expect(height).toBeGreaterThan(0)
91+
// Load was successful
92+
expect(await app.webContents.isLoading()).toBe(false)
93+
// App is loaded properly
94+
expect(await client.getHTML('#app')).toMatchSnapshot()
95+
96+
await app.stop()
97+
resolve()
6998
})
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()
8699

87-
await app.stop()
100+
test('build:electron', async () => {
101+
await runTests()
102+
})
103+
test('build:electron-ts', async () => {
104+
await runTests(true)
88105
})

0 commit comments

Comments
 (0)