Skip to content

Commit 1dbb4a0

Browse files
committed
Setup electron e2e test
1 parent 73d283e commit 1dbb4a0

File tree

17 files changed

+3754
-38
lines changed

17 files changed

+3754
-38
lines changed

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ docs/
2020
!.yarn/releases
2121
!.yarn/sdks
2222
!.yarn/versions
23-
/test-results/
24-
/playwright-report/
23+
**/test-results/
24+
**/playwright-report/
2525
/blob-report/
2626
/playwright/.cache/
2727
.vscode

packages/core/src/tools/utils/urlPolyfill.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { globalObject } from '../globalObject'
22

33
export function normalizeUrl(url: string) {
4-
return buildUrl(url, location.href).href
4+
const base = typeof location !== 'undefined' ? location.href : undefined
5+
return buildUrl(url, base).href
56
}
67

78
export function isValidUrl(url: string) {

scripts/build/build-test-apps.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ runMain(async () => {
1818
buildApp('test/apps/react-router-v6-app')
1919
buildApp('test/apps/react-heavy-spa')
2020
buildApp('test/apps/react-shopist-like')
21+
buildApp('test/apps/electron')
2122
await buildReactRouterv7App()
2223
await buildExtensions()
2324

test/apps/electron/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.yarn/*
2+
node_modules
3+
dist

test/apps/electron/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# electron
2+
3+
Sample electron app for e2e tests

test/apps/electron/package.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"name": "electron",
3+
"version": "0.0.0",
4+
"private": true,
5+
"main": "src/main.ts",
6+
"scripts": {
7+
"start": "electron ./dist/main.js",
8+
"build": "webpack --config webpack.main.js && webpack --config webpack.renderer.js"
9+
},
10+
"devDependencies": {
11+
"electron": "39.2.3",
12+
"html-webpack-plugin": "5.6.5",
13+
"ts-loader": "9.5.4",
14+
"webpack": "5.103.0",
15+
"webpack-cli": "6.0.1"
16+
},
17+
"dependencies": {
18+
"@datadog/electron": "file:../../../packages/electron/package.tgz"
19+
},
20+
"resolutions": {
21+
"@datadog/browser-rum-core": "file:../../../packages/rum-core/package.tgz",
22+
"@datadog/browser-core": "file:../../../packages/core/package.tgz"
23+
}
24+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<meta charset="UTF-8" />
5+
<title>Sample Electron App</title>
6+
</head>
7+
<body>
8+
<h1>Electron sample app</h1>
9+
</body>
10+
</html>

test/apps/electron/src/main.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { app, BrowserWindow } from 'electron'
2+
import { ddElectron } from '@datadog/electron'
3+
4+
// Delay startup to not miss early logs in playwright
5+
setTimeout(startApp, 200)
6+
7+
function startApp() {
8+
ddElectron.init(retrieveRumConfiguration())
9+
10+
app.whenReady().then(() => {
11+
createWindow()
12+
})
13+
14+
app.on('window-all-closed', () => {
15+
app.quit()
16+
})
17+
}
18+
19+
function createWindow() {
20+
const win = new BrowserWindow({
21+
width: 800,
22+
height: 600,
23+
})
24+
25+
win.loadFile('index.html')
26+
}
27+
28+
function retrieveRumConfiguration(): any {
29+
const namespace = 'RUM_'
30+
const rumConfiguration = {}
31+
Object.entries(process.env)
32+
.filter(([key]) => key.startsWith(namespace))
33+
.forEach(([key, value]) => {
34+
rumConfiguration[key.replace(namespace, '')] = Number.isNaN(Number(value)) ? value : Number(value)
35+
})
36+
console.log(rumConfiguration)
37+
return rumConfiguration
38+
}

test/apps/electron/src/renderer.ts

Whitespace-only changes.

test/apps/electron/webpack.main.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const path = require('path')
2+
3+
module.exports = {
4+
mode: 'development',
5+
target: 'electron-main',
6+
entry: './src/main.ts',
7+
output: {
8+
filename: 'main.js',
9+
path: path.resolve(__dirname, 'dist'),
10+
},
11+
resolve: {
12+
extensions: ['.ts', '.js'],
13+
},
14+
module: {
15+
rules: [
16+
{
17+
test: /\.ts$/,
18+
loader: 'ts-loader',
19+
},
20+
],
21+
},
22+
}

0 commit comments

Comments
 (0)