|
| 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