-
-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Add Electron Forge Vite test (#1085)
- Loading branch information
Showing
12 changed files
with
388 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
{ | ||
"method": "envelope", | ||
"sentryKey": "37f8a2ee37c0409d8970bc7559c7c7e4", | ||
"appId": "277345", | ||
"data": { | ||
"sdk": { | ||
"name": "sentry.javascript.electron", | ||
"packages": [ | ||
{ | ||
"name": "npm:@sentry/electron", | ||
"version": "{{version}}" | ||
} | ||
], | ||
"version": "{{version}}" | ||
}, | ||
"contexts": { | ||
"app": { | ||
"app_name": "electron-forge-vite", | ||
"app_version": "1.0.0", | ||
"app_start_time": "{{time}}" | ||
}, | ||
"browser": { | ||
"name": "Chrome" | ||
}, | ||
"chrome": { | ||
"name": "Chrome", | ||
"type": "runtime", | ||
"version": "{{version}}" | ||
}, | ||
"device": { | ||
"arch": "{{arch}}", | ||
"family": "Desktop", | ||
"memory_size": 0, | ||
"free_memory": 0, | ||
"processor_count": 0, | ||
"processor_frequency": 0, | ||
"cpu_description": "{{cpu}}", | ||
"screen_resolution":"{{screen}}", | ||
"screen_density": 1 | ||
}, | ||
"culture": { | ||
"locale": "{{locale}}", | ||
"timezone": "{{timezone}}" | ||
}, | ||
"node": { | ||
"name": "Node", | ||
"type": "runtime", | ||
"version": "{{version}}" | ||
}, | ||
"os": { | ||
"name": "{{platform}}", | ||
"version": "{{version}}" | ||
}, | ||
"runtime": { | ||
"name": "Electron", | ||
"version": "{{version}}" | ||
} | ||
}, | ||
"release": "[email protected]", | ||
"environment": "development", | ||
"debug_meta": { | ||
"images": [ | ||
{ | ||
"type": "sourcemap" | ||
} | ||
] | ||
}, | ||
"exception": { | ||
"values": [ | ||
{ | ||
"type": "Error", | ||
"value": "Some renderer error", | ||
"stacktrace": { | ||
"frames": [ | ||
{ | ||
"colno": 0, | ||
"function": "{{function}}", | ||
"in_app": true, | ||
"lineno": 0 | ||
}, | ||
{ | ||
"colno": 0, | ||
"function": "{{function}}", | ||
"in_app": true, | ||
"lineno": 0 | ||
} | ||
] | ||
}, | ||
"mechanism": { | ||
"handled": false, | ||
"type": "instrument" | ||
} | ||
} | ||
] | ||
}, | ||
"level": "error", | ||
"event_id": "{{id}}", | ||
"platform": "javascript", | ||
"timestamp": 0, | ||
"breadcrumbs": [ | ||
{ | ||
"timestamp": 0, | ||
"category": "electron", | ||
"message": "app.will-finish-launching", | ||
"type": "ui" | ||
}, | ||
{ | ||
"timestamp": 0, | ||
"category": "electron", | ||
"message": "app.ready", | ||
"type": "ui" | ||
}, | ||
{ | ||
"timestamp": 0, | ||
"category": "electron", | ||
"message": "app.session-created", | ||
"type": "ui" | ||
}, | ||
{ | ||
"timestamp": 0, | ||
"category": "electron", | ||
"message": "app.web-contents-created", | ||
"type": "ui" | ||
}, | ||
{ | ||
"timestamp": 0, | ||
"category": "electron", | ||
"message": "app.browser-window-created", | ||
"type": "ui" | ||
}, | ||
{ | ||
"timestamp": 0, | ||
"category": "electron", | ||
"message": "renderer.dom-ready", | ||
"type": "ui" | ||
} | ||
], | ||
"request": { | ||
"url": "app:///.vite/renderer/main_window/index.html" | ||
}, | ||
"tags": { | ||
"event.environment": "javascript", | ||
"event.origin": "electron", | ||
"event.process": "renderer" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { VitePlugin } from '@electron-forge/plugin-vite'; | ||
|
||
export default { | ||
packagerConfig: { | ||
asar: true, | ||
}, | ||
rebuildConfig: {}, | ||
plugins: [ | ||
new VitePlugin({ | ||
// `build` can specify multiple entry builds, which can be Main process, Preload scripts, Worker process, etc. | ||
// If you are familiar with Vite configuration, it will look really familiar. | ||
build: [ | ||
{ | ||
// `entry` is just an alias for `build.lib.entry` in the corresponding file of `config`. | ||
entry: 'src/main.js', | ||
config: 'vite.main.config.mjs', | ||
target: 'main', | ||
}, | ||
{ | ||
entry: 'src/preload.js', | ||
config: 'vite.preload.config.mjs', | ||
target: 'preload', | ||
}, | ||
], | ||
renderer: [ | ||
{ | ||
name: 'main_window', | ||
config: 'vite.renderer.config.mjs', | ||
}, | ||
], | ||
},) | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<title>Hello World!</title> | ||
|
||
</head> | ||
<body> | ||
<h1>💖 Hello World!</h1> | ||
<p>Welcome to your Electron application.</p> | ||
<script type="module" src="/src/renderer.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"name": "electron-forge-vite", | ||
"productName": "electron-forge-vite", | ||
"version": "1.0.0", | ||
"description": "My Electron application description", | ||
"main": ".vite/build/main.js", | ||
"scripts": { | ||
"start": "electron-forge start", | ||
"package": "electron-forge package", | ||
"make": "electron-forge make", | ||
"publish": "electron-forge publish", | ||
"lint": "echo \"No linting configured\"" | ||
}, | ||
"devDependencies": { | ||
"@electron-forge/cli": "^7.6.1", | ||
"@electron-forge/plugin-auto-unpack-natives": "^7.6.1", | ||
"@electron-forge/plugin-vite": "^7.6.1", | ||
"@sentry/vite-plugin": "^3.1.2", | ||
"electron": "34.2.0", | ||
"vite": "^5.0.12" | ||
}, | ||
"license": "MIT", | ||
"dependencies": { | ||
"@sentry/electron": "5.6.0", | ||
"electron-squirrel-startup": "^1.0.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
description: Electron Forge Vite with contextIsolation and sandbox | ||
command: yarn && yarn package | ||
condition: supportsContextIsolation && supportsSandbox | ||
timeout: 120 | ||
skipEsmAutoTransform: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
body { | ||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, | ||
Arial, sans-serif; | ||
margin: auto; | ||
max-width: 38rem; | ||
padding: 2rem; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { app, BrowserWindow } from 'electron'; | ||
import path from 'node:path'; | ||
import started from 'electron-squirrel-startup'; | ||
import * as Sentry from '@sentry/electron/main'; | ||
|
||
// Handle creating/removing shortcuts on Windows when installing/uninstalling. | ||
if (started) { | ||
app.quit(); | ||
} | ||
|
||
Sentry.init({ | ||
dsn: '__DSN__', | ||
debug: true, | ||
integrations: (integrations) => integrations.filter((i) => i.name !== 'MainProcessSession'), | ||
onFatalError: () => {}, | ||
}); | ||
|
||
const createWindow = () => { | ||
// Create the browser window. | ||
const mainWindow = new BrowserWindow({ | ||
width: 800, | ||
height: 600, | ||
webPreferences: { | ||
preload: path.join(__dirname, 'preload.js'), | ||
}, | ||
}); | ||
|
||
// and load the index.html of the app. | ||
if (MAIN_WINDOW_VITE_DEV_SERVER_URL) { | ||
mainWindow.loadURL(MAIN_WINDOW_VITE_DEV_SERVER_URL); | ||
} else { | ||
mainWindow.loadFile(path.join(__dirname, `../renderer/${MAIN_WINDOW_VITE_NAME}/index.html`)); | ||
} | ||
}; | ||
|
||
// This method will be called when Electron has finished | ||
// initialization and is ready to create browser windows. | ||
// Some APIs can only be used after this event occurs. | ||
app.whenReady().then(() => { | ||
createWindow(); | ||
|
||
// On OS X it's common to re-create a window in the app when the | ||
// dock icon is clicked and there are no other windows open. | ||
app.on('activate', () => { | ||
if (BrowserWindow.getAllWindows().length === 0) { | ||
createWindow(); | ||
} | ||
}); | ||
}); | ||
|
||
// Quit when all windows are closed, except on macOS. There, it's common | ||
// for applications and their menu bar to stay active until the user quits | ||
// explicitly with Cmd + Q. | ||
app.on('window-all-closed', () => { | ||
if (process.platform !== 'darwin') { | ||
app.quit(); | ||
} | ||
}); | ||
|
||
// In this file you can include the rest of your app's specific main process | ||
// code. You can also put them in separate files and import them here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// See the Electron documentation for details on how to use preload scripts: | ||
// https://www.electronjs.org/docs/latest/tutorial/process-model#preload-scripts | ||
import '@sentry/electron/preload'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/** | ||
* This file will automatically be loaded by vite and run in the "renderer" context. | ||
* To learn more about the differences between the "main" and the "renderer" context in | ||
* Electron, visit: | ||
* | ||
* https://electronjs.org/docs/tutorial/application-architecture#main-and-renderer-processes | ||
* | ||
* By default, Node.js integration in this file is disabled. When enabling Node.js integration | ||
* in a renderer process, please be aware of potential security implications. You can read | ||
* more about security risks here: | ||
* | ||
* https://electronjs.org/docs/tutorial/security | ||
* | ||
* To enable Node.js integration in this file, open up `main.js` and enable the `nodeIntegration` | ||
* flag: | ||
* | ||
* ``` | ||
* // Create the browser window. | ||
* mainWindow = new BrowserWindow({ | ||
* width: 800, | ||
* height: 600, | ||
* webPreferences: { | ||
* nodeIntegration: true | ||
* } | ||
* }); | ||
* ``` | ||
*/ | ||
|
||
import './index.css'; | ||
import { init } from '@sentry/electron/renderer'; | ||
|
||
init({ | ||
debug: true, | ||
}); | ||
|
||
console.log('👋 This message is being logged by "renderer.js", included via Vite'); | ||
|
||
setTimeout(() => { | ||
throw new Error('Some renderer error'); | ||
}, 500); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { defineConfig } from 'vite'; | ||
import { sentryVitePlugin } from "@sentry/vite-plugin"; | ||
|
||
// https://vitejs.dev/config | ||
export default defineConfig({ | ||
plugins: [ | ||
sentryVitePlugin({ | ||
authToken: 'some invalid auth token', | ||
org: 'some invalid org', | ||
project: 'some invalid project', | ||
telemetry: false, | ||
sourcemaps: { | ||
assets: [], // no assets to upload - we just care about injecting debug IDs | ||
}, | ||
release: { | ||
inject: false, | ||
}, | ||
errorHandler() { | ||
// do nothing on errors :) | ||
// They will happen because of the invalid auth token | ||
}, | ||
}), | ||
], | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { defineConfig } from 'vite'; | ||
|
||
// https://vitejs.dev/config | ||
export default defineConfig({}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { defineConfig } from 'vite'; | ||
import { sentryVitePlugin } from "@sentry/vite-plugin"; | ||
|
||
// https://vitejs.dev/config | ||
export default defineConfig({ | ||
plugins: [ | ||
sentryVitePlugin({ | ||
authToken: 'some invalid auth token', | ||
org: 'some invalid org', | ||
project: 'some invalid project', | ||
telemetry: false, | ||
sourcemaps: { | ||
assets: [], // no assets to upload - we just care about injecting debug IDs | ||
}, | ||
release: { | ||
inject: false, | ||
}, | ||
errorHandler() { | ||
// do nothing on errors :) | ||
// They will happen because of the invalid auth token | ||
}, | ||
}), | ||
], | ||
}); |