Skip to content

Commit

Permalink
pack: fix test build
Browse files Browse the repository at this point in the history
  • Loading branch information
jooy2 committed Nov 13, 2023
1 parent 72a684b commit 7da4d76
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 41 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"dev:debug": "vite -d",
"dev:debug:force": "vite -d --force",
"build": "npm run build:pre && electron-builder --config=buildAssets/builder/config.js",
"build:pre": "npm run format:fix && vue-tsc --noEmit && vite build",
"build:pre": "npm run format:fix && vue-tsc --noEmit && cross-env NODE_ENV=production vite build",
"build:all": "npm run build:pre && electron-builder --config=buildAssets/builder/config.js -wml",
"build:dir": "npm run build:pre && electron-builder --config=buildAssets/builder/config.js --dir",
"build:mac": "npm run build:pre && CSC_IDENTITY_AUTO_DISCOVERY=false electron-builder --config=buildAssets/builder/config.js --mac",
Expand Down
10 changes: 9 additions & 1 deletion tests/app.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,15 @@ function existElementByTestId(selector: string, waitingMilliseconds = 100) {

test.beforeAll(async () => {
// Open Electron app from build directory
appElectron = await electron.launch({ args: ['dist/main/index.js'] })
appElectron = await electron.launch({
args: ['dist/main/index.js'],
locale: 'en-US',
colorScheme: 'light',
env: {
...process.env,
NODE_ENV: 'production'
}
})
appWindow = await appElectron.firstWindow()

await appWindow.waitForEvent('load')
Expand Down
81 changes: 42 additions & 39 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { fileURLToPath } from 'url'
import { defineConfig } from 'vite'
import ElectronPlugin from 'vite-plugin-electron'
import ElectronPlugin, { ElectronOptions } from 'vite-plugin-electron'
import RendererPlugin from 'vite-plugin-electron-renderer'
import EslintPlugin from 'vite-plugin-eslint'
import VuetifyPlugin from 'vite-plugin-vuetify'
Expand All @@ -15,6 +15,46 @@ const isDevEnv = process.env.NODE_ENV === 'development'
export default defineConfig(() => {
rmSync('dist', { recursive: true, force: true })

const electronPluginConfigs: ElectronOptions[] = [
{
entry: 'src/main/index.ts',
onstart({ startup }) {
startup()
},
vite: {
build: {
assetsDir: '.',
outDir: 'dist/main',
rollupOptions: {
external: ['electron', ...builtinModules]
}
}
}
},
{
entry: 'src/preload/index.ts',
onstart({ reload }) {
reload()
},
vite: {
build: {
outDir: 'dist/preload'
}
}
}
]

if (isDevEnv) {
electronPluginConfigs.push({
entry: 'src/main/index.dev.ts',
vite: {
build: {
outDir: 'dist/main'
}
}
})
}

return {
define: {
__VUE_I18N_FULL_INSTALL__: true,
Expand Down Expand Up @@ -46,44 +86,7 @@ export default defineConfig(() => {
// Docs: https://github.com/gxmari007/vite-plugin-eslint
EslintPlugin(),
// Docs: https://github.com/electron-vite/vite-plugin-electron
ElectronPlugin([
{
entry: 'src/main/index.ts',
onstart({ startup }) {
startup()
},
vite: {
build: {
assetsDir: '.',
outDir: 'dist/main',
rollupOptions: {
external: ['electron', ...builtinModules]
}
}
}
},
isDevEnv
? {
entry: 'src/main/index.dev.ts',
vite: {
build: {
outDir: 'dist/main'
}
}
}
: {},
{
entry: 'src/preload/index.ts',
onstart({ reload }) {
reload()
},
vite: {
build: {
outDir: 'dist/preload'
}
}
}
]),
ElectronPlugin(electronPluginConfigs),
RendererPlugin()
]
}
Expand Down

0 comments on commit 7da4d76

Please sign in to comment.