Skip to content

Commit 805470d

Browse files
authored
test: Add Electron Forge Vite test (#1085)
1 parent b77df77 commit 805470d

12 files changed

+388
-0
lines changed
+147
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
{
2+
"method": "envelope",
3+
"sentryKey": "37f8a2ee37c0409d8970bc7559c7c7e4",
4+
"appId": "277345",
5+
"data": {
6+
"sdk": {
7+
"name": "sentry.javascript.electron",
8+
"packages": [
9+
{
10+
"name": "npm:@sentry/electron",
11+
"version": "{{version}}"
12+
}
13+
],
14+
"version": "{{version}}"
15+
},
16+
"contexts": {
17+
"app": {
18+
"app_name": "electron-forge-vite",
19+
"app_version": "1.0.0",
20+
"app_start_time": "{{time}}"
21+
},
22+
"browser": {
23+
"name": "Chrome"
24+
},
25+
"chrome": {
26+
"name": "Chrome",
27+
"type": "runtime",
28+
"version": "{{version}}"
29+
},
30+
"device": {
31+
"arch": "{{arch}}",
32+
"family": "Desktop",
33+
"memory_size": 0,
34+
"free_memory": 0,
35+
"processor_count": 0,
36+
"processor_frequency": 0,
37+
"cpu_description": "{{cpu}}",
38+
"screen_resolution":"{{screen}}",
39+
"screen_density": 1
40+
},
41+
"culture": {
42+
"locale": "{{locale}}",
43+
"timezone": "{{timezone}}"
44+
},
45+
"node": {
46+
"name": "Node",
47+
"type": "runtime",
48+
"version": "{{version}}"
49+
},
50+
"os": {
51+
"name": "{{platform}}",
52+
"version": "{{version}}"
53+
},
54+
"runtime": {
55+
"name": "Electron",
56+
"version": "{{version}}"
57+
}
58+
},
59+
"release": "[email protected]",
60+
"environment": "development",
61+
"debug_meta": {
62+
"images": [
63+
{
64+
"type": "sourcemap"
65+
}
66+
]
67+
},
68+
"exception": {
69+
"values": [
70+
{
71+
"type": "Error",
72+
"value": "Some renderer error",
73+
"stacktrace": {
74+
"frames": [
75+
{
76+
"colno": 0,
77+
"function": "{{function}}",
78+
"in_app": true,
79+
"lineno": 0
80+
},
81+
{
82+
"colno": 0,
83+
"function": "{{function}}",
84+
"in_app": true,
85+
"lineno": 0
86+
}
87+
]
88+
},
89+
"mechanism": {
90+
"handled": false,
91+
"type": "instrument"
92+
}
93+
}
94+
]
95+
},
96+
"level": "error",
97+
"event_id": "{{id}}",
98+
"platform": "javascript",
99+
"timestamp": 0,
100+
"breadcrumbs": [
101+
{
102+
"timestamp": 0,
103+
"category": "electron",
104+
"message": "app.will-finish-launching",
105+
"type": "ui"
106+
},
107+
{
108+
"timestamp": 0,
109+
"category": "electron",
110+
"message": "app.ready",
111+
"type": "ui"
112+
},
113+
{
114+
"timestamp": 0,
115+
"category": "electron",
116+
"message": "app.session-created",
117+
"type": "ui"
118+
},
119+
{
120+
"timestamp": 0,
121+
"category": "electron",
122+
"message": "app.web-contents-created",
123+
"type": "ui"
124+
},
125+
{
126+
"timestamp": 0,
127+
"category": "electron",
128+
"message": "app.browser-window-created",
129+
"type": "ui"
130+
},
131+
{
132+
"timestamp": 0,
133+
"category": "electron",
134+
"message": "renderer.dom-ready",
135+
"type": "ui"
136+
}
137+
],
138+
"request": {
139+
"url": "app:///.vite/renderer/main_window/index.html"
140+
},
141+
"tags": {
142+
"event.environment": "javascript",
143+
"event.origin": "electron",
144+
"event.process": "renderer"
145+
}
146+
}
147+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { VitePlugin } from '@electron-forge/plugin-vite';
2+
3+
export default {
4+
packagerConfig: {
5+
asar: true,
6+
},
7+
rebuildConfig: {},
8+
plugins: [
9+
new VitePlugin({
10+
// `build` can specify multiple entry builds, which can be Main process, Preload scripts, Worker process, etc.
11+
// If you are familiar with Vite configuration, it will look really familiar.
12+
build: [
13+
{
14+
// `entry` is just an alias for `build.lib.entry` in the corresponding file of `config`.
15+
entry: 'src/main.js',
16+
config: 'vite.main.config.mjs',
17+
target: 'main',
18+
},
19+
{
20+
entry: 'src/preload.js',
21+
config: 'vite.preload.config.mjs',
22+
target: 'preload',
23+
},
24+
],
25+
renderer: [
26+
{
27+
name: 'main_window',
28+
config: 'vite.renderer.config.mjs',
29+
},
30+
],
31+
},)
32+
],
33+
};
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="UTF-8" />
5+
<title>Hello World!</title>
6+
7+
</head>
8+
<body>
9+
<h1>💖 Hello World!</h1>
10+
<p>Welcome to your Electron application.</p>
11+
<script type="module" src="/src/renderer.js"></script>
12+
</body>
13+
</html>
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"name": "electron-forge-vite",
3+
"productName": "electron-forge-vite",
4+
"version": "1.0.0",
5+
"description": "My Electron application description",
6+
"main": ".vite/build/main.js",
7+
"scripts": {
8+
"start": "electron-forge start",
9+
"package": "electron-forge package",
10+
"make": "electron-forge make",
11+
"publish": "electron-forge publish",
12+
"lint": "echo \"No linting configured\""
13+
},
14+
"devDependencies": {
15+
"@electron-forge/cli": "^7.6.1",
16+
"@electron-forge/plugin-auto-unpack-natives": "^7.6.1",
17+
"@electron-forge/plugin-vite": "^7.6.1",
18+
"@sentry/vite-plugin": "^3.1.2",
19+
"electron": "34.2.0",
20+
"vite": "^5.0.12"
21+
},
22+
"license": "MIT",
23+
"dependencies": {
24+
"@sentry/electron": "5.6.0",
25+
"electron-squirrel-startup": "^1.0.1"
26+
}
27+
}
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
description: Electron Forge Vite with contextIsolation and sandbox
2+
command: yarn && yarn package
3+
condition: supportsContextIsolation && supportsSandbox
4+
timeout: 120
5+
skipEsmAutoTransform: true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
body {
2+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica,
3+
Arial, sans-serif;
4+
margin: auto;
5+
max-width: 38rem;
6+
padding: 2rem;
7+
}
+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import { app, BrowserWindow } from 'electron';
2+
import path from 'node:path';
3+
import started from 'electron-squirrel-startup';
4+
import * as Sentry from '@sentry/electron/main';
5+
6+
// Handle creating/removing shortcuts on Windows when installing/uninstalling.
7+
if (started) {
8+
app.quit();
9+
}
10+
11+
Sentry.init({
12+
dsn: '__DSN__',
13+
debug: true,
14+
integrations: (integrations) => integrations.filter((i) => i.name !== 'MainProcessSession'),
15+
onFatalError: () => {},
16+
});
17+
18+
const createWindow = () => {
19+
// Create the browser window.
20+
const mainWindow = new BrowserWindow({
21+
width: 800,
22+
height: 600,
23+
webPreferences: {
24+
preload: path.join(__dirname, 'preload.js'),
25+
},
26+
});
27+
28+
// and load the index.html of the app.
29+
if (MAIN_WINDOW_VITE_DEV_SERVER_URL) {
30+
mainWindow.loadURL(MAIN_WINDOW_VITE_DEV_SERVER_URL);
31+
} else {
32+
mainWindow.loadFile(path.join(__dirname, `../renderer/${MAIN_WINDOW_VITE_NAME}/index.html`));
33+
}
34+
};
35+
36+
// This method will be called when Electron has finished
37+
// initialization and is ready to create browser windows.
38+
// Some APIs can only be used after this event occurs.
39+
app.whenReady().then(() => {
40+
createWindow();
41+
42+
// On OS X it's common to re-create a window in the app when the
43+
// dock icon is clicked and there are no other windows open.
44+
app.on('activate', () => {
45+
if (BrowserWindow.getAllWindows().length === 0) {
46+
createWindow();
47+
}
48+
});
49+
});
50+
51+
// Quit when all windows are closed, except on macOS. There, it's common
52+
// for applications and their menu bar to stay active until the user quits
53+
// explicitly with Cmd + Q.
54+
app.on('window-all-closed', () => {
55+
if (process.platform !== 'darwin') {
56+
app.quit();
57+
}
58+
});
59+
60+
// In this file you can include the rest of your app's specific main process
61+
// code. You can also put them in separate files and import them here.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// See the Electron documentation for details on how to use preload scripts:
2+
// https://www.electronjs.org/docs/latest/tutorial/process-model#preload-scripts
3+
import '@sentry/electron/preload';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* This file will automatically be loaded by vite and run in the "renderer" context.
3+
* To learn more about the differences between the "main" and the "renderer" context in
4+
* Electron, visit:
5+
*
6+
* https://electronjs.org/docs/tutorial/application-architecture#main-and-renderer-processes
7+
*
8+
* By default, Node.js integration in this file is disabled. When enabling Node.js integration
9+
* in a renderer process, please be aware of potential security implications. You can read
10+
* more about security risks here:
11+
*
12+
* https://electronjs.org/docs/tutorial/security
13+
*
14+
* To enable Node.js integration in this file, open up `main.js` and enable the `nodeIntegration`
15+
* flag:
16+
*
17+
* ```
18+
* // Create the browser window.
19+
* mainWindow = new BrowserWindow({
20+
* width: 800,
21+
* height: 600,
22+
* webPreferences: {
23+
* nodeIntegration: true
24+
* }
25+
* });
26+
* ```
27+
*/
28+
29+
import './index.css';
30+
import { init } from '@sentry/electron/renderer';
31+
32+
init({
33+
debug: true,
34+
});
35+
36+
console.log('👋 This message is being logged by "renderer.js", included via Vite');
37+
38+
setTimeout(() => {
39+
throw new Error('Some renderer error');
40+
}, 500);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { defineConfig } from 'vite';
2+
import { sentryVitePlugin } from "@sentry/vite-plugin";
3+
4+
// https://vitejs.dev/config
5+
export default defineConfig({
6+
plugins: [
7+
sentryVitePlugin({
8+
authToken: 'some invalid auth token',
9+
org: 'some invalid org',
10+
project: 'some invalid project',
11+
telemetry: false,
12+
sourcemaps: {
13+
assets: [], // no assets to upload - we just care about injecting debug IDs
14+
},
15+
release: {
16+
inject: false,
17+
},
18+
errorHandler() {
19+
// do nothing on errors :)
20+
// They will happen because of the invalid auth token
21+
},
22+
}),
23+
],
24+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { defineConfig } from 'vite';
2+
3+
// https://vitejs.dev/config
4+
export default defineConfig({});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { defineConfig } from 'vite';
2+
import { sentryVitePlugin } from "@sentry/vite-plugin";
3+
4+
// https://vitejs.dev/config
5+
export default defineConfig({
6+
plugins: [
7+
sentryVitePlugin({
8+
authToken: 'some invalid auth token',
9+
org: 'some invalid org',
10+
project: 'some invalid project',
11+
telemetry: false,
12+
sourcemaps: {
13+
assets: [], // no assets to upload - we just care about injecting debug IDs
14+
},
15+
release: {
16+
inject: false,
17+
},
18+
errorHandler() {
19+
// do nothing on errors :)
20+
// They will happen because of the invalid auth token
21+
},
22+
}),
23+
],
24+
});

0 commit comments

Comments
 (0)