Skip to content
This repository was archived by the owner on Oct 13, 2024. It is now read-only.

Commit 9375f4c

Browse files
committed
Add tests for app in subdirectory
1 parent 791a7c7 commit 9375f4c

File tree

14 files changed

+242
-44
lines changed

14 files changed

+242
-44
lines changed

.github/workflows/test.yml

Lines changed: 15 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -5,57 +5,32 @@ on:
55
- pull_request
66

77
jobs:
8-
# Run with Yarn
9-
yarn:
8+
test:
9+
name: Test
1010
runs-on: ${{ matrix.os }}
11-
strategy:
12-
matrix:
13-
os: [macos-latest, ubuntu-latest, windows-latest]
14-
steps:
15-
- name: Check out Git repository
16-
uses: actions/checkout@v1
17-
with:
18-
submodules: true
19-
- name: Install Node.js, NPM and Yarn
20-
uses: actions/setup-node@v1
21-
with:
22-
node-version: 10
23-
- name: Install `electron-builder` with Yarn
24-
run: |
25-
cd ./test/electron-quick-start/
26-
rm ./package-lock.json
27-
yarn
28-
yarn add --dev electron-builder@^22.0.0
29-
- name: Run action
30-
uses: ./
31-
with:
32-
github_token: ${{ secrets.github_token }}
33-
app_root: ./test/electron-quick-start/
34-
package_root: ./test/electron-quick-start/
3511

36-
# Run with NPM
37-
npm:
38-
runs-on: ${{ matrix.os }}
3912
strategy:
4013
matrix:
4114
os: [macos-latest, ubuntu-latest, windows-latest]
15+
package_manager: [npm, yarn]
16+
package_root: ["./test/app-in-root/", "./test/app-in-subdirectory/"]
17+
4218
steps:
4319
- name: Check out Git repository
44-
uses: actions/checkout@v1
45-
with:
46-
submodules: true
47-
- name: Install Node.js, NPM and Yarn
20+
uses: actions/checkout@v2
21+
22+
- name: Set up Node.js
4823
uses: actions/setup-node@v1
4924
with:
50-
node-version: 10
51-
- name: Install `electron-builder` with NPM
25+
node-version: 12
26+
27+
- name: Install test app dependencies
5228
run: |
53-
cd ./test/electron-quick-start/
54-
npm i
55-
npm i -D electron-builder@^22.0.0
29+
cd ${{ matrix.package_root }}
30+
${{ matrix.package_manager }} install
31+
5632
- name: Run action
5733
uses: ./
5834
with:
5935
github_token: ${{ secrets.github_token }}
60-
app_root: ./test/electron-quick-start/
61-
package_root: ./test/electron-quick-start/
36+
package_root: ${{ matrix.package_root }}

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1+
dist/
12
node_modules/
3+
test/**/package-lock.json
4+
test/**/yarn.lock

.gitmodules

Lines changed: 0 additions & 3 deletions
This file was deleted.

test/app-in-root/index.html

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="UTF-8" />
5+
<!-- https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP -->
6+
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self'" />
7+
<meta http-equiv="X-Content-Security-Policy" content="default-src 'self'; script-src 'self'" />
8+
<title>Hello World!</title>
9+
</head>
10+
<body>
11+
<h1>Hello World!</h1>
12+
We are using Node.js <span id="node-version"></span>, Chromium
13+
<span id="chrome-version"></span>, and Electron <span id="electron-version"></span>.
14+
15+
<!-- You can also require other files to run in this process -->
16+
<script src="./renderer.js"></script>
17+
</body>
18+
</html>

test/app-in-root/main.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Modules to control application life and create native browser window
2+
const { app, BrowserWindow } = require("electron");
3+
const path = require("path");
4+
5+
// Keep a global reference of the window object, if you don't, the window will
6+
// be closed automatically when the JavaScript object is garbage collected.
7+
let mainWindow;
8+
9+
function createWindow() {
10+
// Create the browser window.
11+
mainWindow = new BrowserWindow({
12+
width: 800,
13+
height: 600,
14+
webPreferences: {
15+
preload: path.join(__dirname, "preload.js"),
16+
},
17+
});
18+
19+
// and load the index.html of the app.
20+
mainWindow.loadFile(path.join(__dirname, "index.html"));
21+
22+
// Open the DevTools.
23+
// mainWindow.webContents.openDevTools()
24+
25+
// Emitted when the window is closed.
26+
mainWindow.on("closed", function() {
27+
// Dereference the window object, usually you would store windows
28+
// in an array if your app supports multi windows, this is the time
29+
// when you should delete the corresponding element.
30+
mainWindow = null;
31+
});
32+
}
33+
34+
// This method will be called when Electron has finished
35+
// initialization and is ready to create browser windows.
36+
// Some APIs can only be used after this event occurs.
37+
app.on("ready", createWindow);
38+
39+
// Quit when all windows are closed.
40+
app.on("window-all-closed", function() {
41+
// On macOS it is common for applications and their menu bar
42+
// to stay active until the user quits explicitly with Cmd + Q
43+
if (process.platform !== "darwin") app.quit();
44+
});
45+
46+
app.on("activate", function() {
47+
// On macOS it's common to re-create a window in the app when the
48+
// dock icon is clicked and there are no other windows open.
49+
if (mainWindow === null) createWindow();
50+
});
51+
52+
// In this file you can include the rest of your app's specific main process
53+
// code. You can also put them in separate files and require them here.

test/app-in-root/package.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "electron-quick-start",
3+
"version": "1.0.0",
4+
"description": "A minimal Electron application",
5+
"main": "main.js",
6+
"scripts": {
7+
"start": "electron ."
8+
},
9+
"repository": "https://github.com/electron/electron-quick-start",
10+
"keywords": [
11+
"Electron",
12+
"quick",
13+
"start",
14+
"tutorial",
15+
"demo"
16+
],
17+
"author": "GitHub",
18+
"license": "CC0-1.0",
19+
"devDependencies": {
20+
"electron": "^7.1.7",
21+
"electron-builder": "^22.0.0"
22+
}
23+
}

test/app-in-root/preload.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// All of the Node.js APIs are available in the preload process.
2+
// It has the same sandbox as a Chrome extension.
3+
window.addEventListener("DOMContentLoaded", () => {
4+
const replaceText = (selector, text) => {
5+
const element = document.getElementById(selector);
6+
if (element) element.innerText = text;
7+
};
8+
9+
for (const type of ["chrome", "node", "electron"]) {
10+
replaceText(`${type}-version`, process.versions[type]);
11+
}
12+
});

test/app-in-root/renderer.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// This file is required by the index.html file and will
2+
// be executed in the renderer process for that window.
3+
// No Node.js APIs are available in this process because
4+
// `nodeIntegration` is turned off. Use `preload.js` to
5+
// selectively enable features needed in the rendering
6+
// process.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="UTF-8" />
5+
<!-- https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP -->
6+
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self'" />
7+
<meta http-equiv="X-Content-Security-Policy" content="default-src 'self'; script-src 'self'" />
8+
<title>Hello World!</title>
9+
</head>
10+
<body>
11+
<h1>Hello World!</h1>
12+
We are using Node.js <span id="node-version"></span>, Chromium
13+
<span id="chrome-version"></span>, and Electron <span id="electron-version"></span>.
14+
15+
<!-- You can also require other files to run in this process -->
16+
<script src="./renderer.js"></script>
17+
</body>
18+
</html>
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Modules to control application life and create native browser window
2+
const { app, BrowserWindow } = require("electron");
3+
const path = require("path");
4+
5+
// Keep a global reference of the window object, if you don't, the window will
6+
// be closed automatically when the JavaScript object is garbage collected.
7+
let mainWindow;
8+
9+
function createWindow() {
10+
// Create the browser window.
11+
mainWindow = new BrowserWindow({
12+
width: 800,
13+
height: 600,
14+
webPreferences: {
15+
preload: path.join(__dirname, "preload.js"),
16+
},
17+
});
18+
19+
// and load the index.html of the app.
20+
mainWindow.loadFile(path.join(__dirname, "index.html"));
21+
22+
// Open the DevTools.
23+
// mainWindow.webContents.openDevTools()
24+
25+
// Emitted when the window is closed.
26+
mainWindow.on("closed", function() {
27+
// Dereference the window object, usually you would store windows
28+
// in an array if your app supports multi windows, this is the time
29+
// when you should delete the corresponding element.
30+
mainWindow = null;
31+
});
32+
}
33+
34+
// This method will be called when Electron has finished
35+
// initialization and is ready to create browser windows.
36+
// Some APIs can only be used after this event occurs.
37+
app.on("ready", createWindow);
38+
39+
// Quit when all windows are closed.
40+
app.on("window-all-closed", function() {
41+
// On macOS it is common for applications and their menu bar
42+
// to stay active until the user quits explicitly with Cmd + Q
43+
if (process.platform !== "darwin") app.quit();
44+
});
45+
46+
app.on("activate", function() {
47+
// On macOS it's common to re-create a window in the app when the
48+
// dock icon is clicked and there are no other windows open.
49+
if (mainWindow === null) createWindow();
50+
});
51+
52+
// In this file you can include the rest of your app's specific main process
53+
// code. You can also put them in separate files and require them here.

0 commit comments

Comments
 (0)