Skip to content

Commit fb684b9

Browse files
committed
feat(build/serve): add support for native deps
1 parent c068159 commit fb684b9

File tree

11 files changed

+694
-279
lines changed

11 files changed

+694
-279
lines changed

__tests__/build.helper.js

Lines changed: 4 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const path = require('path')
33
const fs = require('fs-extra')
44
const Application = require('spectron').Application
55
const portfinder = require('portfinder')
6+
const checkLogs = require('./checkLogs.helper.js')
67

78
portfinder.basePort = 9515
89
const runTests = useTS =>
@@ -68,64 +69,9 @@ const runTests = useTS =>
6869
const client = app.client
6970
await client.waitUntilWindowLoaded()
7071

71-
await client.getRenderProcessLogs().then(logs => {
72-
logs.forEach(log => {
73-
// Make sure there are no fatal errors
74-
expect(log.level).not.toBe('SEVERE')
75-
})
76-
let appBaseUrl = logs
77-
// Find BASE_URL log
78-
.find(v => v.message.indexOf('process.env.BASE_URL=') !== -1)
79-
// Get just the value
80-
.message.split('=')[1]
81-
// Remove any quotes
82-
appBaseUrl = appBaseUrl.replace('"', '')
83-
// Base url should be root of server
84-
expect(path.normalize(appBaseUrl)).toBe(
85-
projectPath(
86-
`dist_electron/${
87-
isWin ? 'win' : 'linux'
88-
}-unpacked/resources/app.asar/dist_electron/bundled`
89-
)
90-
)
91-
let appStatic = logs
92-
// Find __static log
93-
.find(v => v.message.indexOf('__static=') !== -1)
94-
// Get just the value
95-
.message.split('=')[1]
96-
// Remove any quotes
97-
appStatic = appStatic.replace('"', '')
98-
// __static should point to public folder
99-
expect(path.normalize(appStatic)).toBe(
100-
projectPath(
101-
`dist_electron/${
102-
isWin ? 'win' : 'linux'
103-
}-unpacked/resources/app.asar/dist_electron/bundled`
104-
)
105-
)
106-
})
107-
await client.getMainProcessLogs().then(logs => {
108-
logs.forEach(log => {
109-
// Make sure there are no fatal errors
110-
expect(log.level).not.toBe('SEVERE')
111-
})
112-
let appStatic = logs
113-
// Find __static log
114-
.find(m => m.indexOf('__static=') !== -1)
115-
// Get just the value
116-
.split('=')[1]
117-
// Remove any quotes
118-
appStatic = appStatic.replace('"', '')
119-
appStatic = appStatic.replace('', '')
120-
// __static should point to public folder
121-
expect(path.normalize(appStatic)).toBe(
122-
projectPath(
123-
`dist_electron/${
124-
isWin ? 'win' : 'linux'
125-
}-unpacked/resources/app.asar/dist_electron/bundled`
126-
)
127-
)
128-
})
72+
// Check that proper info was logged
73+
await checkLogs({ client, projectName, projectPath, mode: 'build' })
74+
12975
// Window was created
13076
expect(await client.getWindowCount()).toBe(1)
13177
// It is not minimized

__tests__/checkLogs.helper.js

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
const path = require('path')
2+
3+
module.exports = async ({ client, projectPath, projectName, mode }) => {
4+
const isWin = process.platform === 'win32'
5+
const isBuild = mode === 'build'
6+
const outputPath = projectPath(
7+
`dist_electron/${
8+
isWin ? 'win' : 'linux'
9+
}-unpacked/resources/app.asar/dist_electron/bundled`
10+
)
11+
12+
await client.getRenderProcessLogs().then(logs => {
13+
logs.forEach(log => {
14+
// Make sure there are no fatal errors
15+
expect(log.level).not.toBe('SEVERE')
16+
})
17+
let appBaseUrl = logs
18+
// Find BASE_URL log
19+
.find(v => v.message.indexOf('process.env.BASE_URL=') !== -1)
20+
// Get just the value
21+
.message.split('=')[1]
22+
// Remove any quotes
23+
appBaseUrl = appBaseUrl.replace('"', '')
24+
// Base url should be root of server or packaged asar
25+
expect(appBaseUrl).toBe(isBuild ? outputPath : '/')
26+
27+
let appStatic = logs
28+
// Find __static log
29+
.find(v => v.message.indexOf('__static=') !== -1)
30+
// Get just the value
31+
.message.split('=')[1]
32+
// Remove any quotes
33+
appStatic = appStatic.replace('"', '')
34+
// __static should point to public folder or packaged asar
35+
expect(path.normalize(appStatic)).toBe(
36+
isBuild ? outputPath : projectPath('public')
37+
)
38+
39+
let modulePaths = logs
40+
// Find modulePath log
41+
.find(v => v.message.indexOf('modulePaths=') !== -1)
42+
// Get just the value
43+
.message.split('=')[1]
44+
// Remove last quote
45+
modulePaths = modulePaths.replace(/"$/, '')
46+
// Parse modulePaths array
47+
modulePaths = modulePaths.split(',')
48+
// module.paths should include path to project's node_modules unless in build
49+
if (isBuild) {
50+
expect(modulePaths).not.toContain(
51+
path.join(__dirname, 'projects', projectName, 'node_modules')
52+
)
53+
} else {
54+
expect(modulePaths).toContain(
55+
path.join(__dirname, 'projects', projectName, 'node_modules')
56+
)
57+
}
58+
59+
let vuePath = logs
60+
// Find vuePath log
61+
.find(v => v.message.indexOf('vuePath=') !== -1)
62+
// Get just the value
63+
.message.split('=')[1]
64+
// Remove any quotes
65+
vuePath = vuePath.replace('"', '')
66+
// Vue should be bundled and not externalized (can't check in build because of NamedModulePlugin)
67+
if (!isBuild) {
68+
expect(path.normalize(vuePath)).toBe(
69+
'../../../node_modules/vue/dist/vue.runtime.esm.js'
70+
)
71+
}
72+
73+
let mockExternalPath = logs
74+
// Find externalModulePath log
75+
.find(v => v.message.indexOf('mockExternalPath=') !== -1)
76+
// Get just the value
77+
.message.split('=')[1]
78+
// Remove any quotes
79+
mockExternalPath = mockExternalPath.replace('"', '')
80+
// mockExternal should be externalized (can't check in build because of NamedModulePlugin)
81+
if (!isBuild) expect(path.normalize(mockExternalPath)).toBe('mockExternal')
82+
})
83+
84+
await client.getMainProcessLogs().then(logs => {
85+
logs.forEach(log => {
86+
// Make sure there are no fatal errors
87+
expect(log.level).not.toBe('SEVERE')
88+
})
89+
let appStatic = logs
90+
// Find __static log
91+
.find(m => m.indexOf('__static=') !== -1)
92+
// Get just the value
93+
.split('=')[1]
94+
// Remove any quotes
95+
appStatic = appStatic.replace('"', '')
96+
// __static should point to public folder or packaged asar
97+
expect(path.normalize(appStatic)).toBe(
98+
isBuild ? outputPath : projectPath('public')
99+
)
100+
101+
let modulePaths = logs
102+
// Find modulePath log
103+
.find(m => m.indexOf('modulePaths=') !== -1)
104+
// Get just the value
105+
.split('=')[1]
106+
// Parse modulePaths array
107+
modulePaths = modulePaths.split(',')
108+
// module.paths should include path to project's node_modules unless in build
109+
if (isBuild) {
110+
expect(modulePaths).not.toContain(
111+
path.join(__dirname, 'projects', projectName, 'node_modules')
112+
)
113+
} else {
114+
expect(modulePaths).toContain(
115+
path.join(__dirname, 'projects', projectName, 'node_modules')
116+
)
117+
}
118+
119+
let mockExternalPath = logs
120+
// Find externalModulePath log
121+
.find(v => v.indexOf('mockExternalPath=') !== -1)
122+
// Get just the value
123+
.split('=')[1]
124+
// Remove any quotes
125+
mockExternalPath = mockExternalPath.replace('"', '')
126+
// mockExternal should be externalized (can't check in build because of NamedModulePlugin)
127+
if (!isBuild) expect(mockExternalPath).toBe('mockExternal')
128+
})
129+
}

0 commit comments

Comments
 (0)