Skip to content

Commit

Permalink
fix test build
Browse files Browse the repository at this point in the history
  • Loading branch information
jooy2 committed Nov 13, 2023
1 parent 2b82bb9 commit 3f7c139
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 40 deletions.
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 ReactPlugin from '@vitejs/plugin-react-swc';
Expand All @@ -15,6 +15,46 @@ const isDEV = 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 (isDEV) {
electronPluginConfigs.push({
entry: 'src/main/index.dev.ts',
vite: {
build: {
outDir: 'dist/main',
},
},
});
}

return {
resolve: {
extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.scss'],
Expand All @@ -36,44 +76,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],
},
},
},
},
isDEV
? {
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 3f7c139

Please sign in to comment.