Skip to content

Commit f34ddc9

Browse files
committed
Merge branch 'develop' into feature/244/apidoc_repo
# Conflicts: # .github/workflows/tagged_release.yaml
2 parents 6bf413d + 862b12e commit f34ddc9

28 files changed

+22270
-30499
lines changed

.build/build.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,6 @@ echo "Entering working directory $targetDir"
2121
cd $targetDir
2222
echo "Installing node version $nodeVersion"
2323
nvm install $nodeVersion
24-
echo "npm run coverage"
24+
25+
npm ci
2526
E2E_TEST=1 npm run coverage -- --coverageDirectory=coverage/e2e

.github/workflows/ci.yaml

+13-5
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ jobs:
2424
run: npm ci
2525
- name: Compile
2626
run: npm run compile
27-
- name: Init e2e test subpackage
28-
run: npm --prefix e2e/tests ci
27+
- name: Init window e2e test subpackage
28+
run: npm --prefix e2e/window-test ci
2929
- name: Clean coverage report
3030
run: npm run coverage:clean
3131
- name: Generate coverage report
@@ -34,6 +34,10 @@ jobs:
3434
run: npm run coverage -- --coverageDirectory=coverage/unit
3535
- name: Run Docker E2E tests
3636
run: docker exec nut-ci bash -c "bash $PWD/.build/build.sh ${PWD} 14"
37+
- name: Run Electron e2e test subpackage
38+
uses: GabrielBB/xvfb-action@v1
39+
with:
40+
run: npm --prefix e2e/electron-test cit
3741
- name: Merge coverage reports
3842
run: |
3943
npm run coverage:merge
@@ -50,7 +54,7 @@ jobs:
5054
strategy:
5155
matrix:
5256
os: [ ubuntu-latest, windows-latest, macos-latest ]
53-
node: [ 10, 12, 14, 15 ]
57+
node: [ 10, 12, 14, 16 ]
5458
exclude:
5559
- os: ubuntu-latest
5660
node: 14
@@ -71,12 +75,16 @@ jobs:
7175
run: npm ci
7276
- name: Compile
7377
run: npm run compile
74-
- name: Init e2e test subpackage
75-
run: npm --prefix e2e/tests ci
78+
- name: Init window e2e test subpackage
79+
run: npm --prefix e2e/window-test ci
7680
- name: Generate coverage report
7781
uses: GabrielBB/xvfb-action@v1
7882
with:
7983
run: npm run coverage -- --coverageDirectory=coverage/unit
8084
- name: Run Docker E2E tests
8185
if: ${{matrix.os == 'ubuntu-latest'}}
8286
run: docker exec nut-ci bash -c "bash $PWD/.build/build.sh ${PWD} ${{matrix.node}}"
87+
- name: Run Electron e2e test subpackage
88+
uses: GabrielBB/xvfb-action@v1
89+
with:
90+
run: npm --prefix e2e/electron-test cit

.github/workflows/snapshot_release.yaml

+8-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
strategy:
1313
matrix:
1414
os: [ ubuntu-latest, windows-latest, macos-latest ]
15-
node: [ 10, 12, 14, 15 ]
15+
node: [ 10, 12, 14, 16 ]
1616
runs-on: ${{matrix.os}}
1717
steps:
1818
- name: Set up Git repository
@@ -32,15 +32,20 @@ jobs:
3232
run: npm i @nut-tree/libnut@next
3333
- name: Compile
3434
run: npm run compile
35-
- name: Init e2e test subpackage
36-
run: npm --prefix e2e/tests ci
35+
- name: Init window e2e test subpackage
36+
run: npm --prefix e2e/window-test ci
3737
- name: Run tests
3838
uses: GabrielBB/xvfb-action@v1
3939
with:
4040
run: npm test
4141
- name: Run Docker E2E tests
4242
if: ${{matrix.os == 'ubuntu-latest'}}
4343
run: docker exec nut-ci bash -c "bash $PWD/.build/build.sh ${PWD} ${{matrix.node}}"
44+
- name: Run Electron e2e test subpackage
45+
uses: GabrielBB/xvfb-action@v1
46+
with:
47+
run: npm --prefix e2e/electron-test cit
48+
4449

4550
deploy:
4651
needs:

.github/workflows/tagged_release.yaml

+7-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
strategy:
1010
matrix:
1111
os: [ ubuntu-latest, windows-latest, macos-latest ]
12-
node: [ 10, 12, 14, 15 ]
12+
node: [ 10, 12, 14, 16 ]
1313
runs-on: ${{matrix.os}}
1414
steps:
1515
- name: Set up Git repository
@@ -27,15 +27,19 @@ jobs:
2727
run: npm ci
2828
- name: Compile
2929
run: npm run compile
30-
- name: Init e2e test subpackage
31-
run: npm --prefix e2e/tests ci
30+
- name: Init window e2e test subpackage
31+
run: npm --prefix e2e/window-test ci
3232
- name: Generate coverage report
3333
uses: GabrielBB/xvfb-action@v1
3434
with:
3535
run: npm test
3636
- name: Run Docker E2E tests
3737
if: ${{matrix.os == 'ubuntu-latest'}}
3838
run: docker exec nut-ci bash -c "bash $PWD/.build/build.sh ${PWD} ${{matrix.node}}"
39+
- name: Run Electron e2e test subpackage
40+
uses: GabrielBB/xvfb-action@v1
41+
with:
42+
run: npm --prefix e2e/electron-test cit
3943
- name: Run typedoc
4044
run: npm run typedoc
4145
- name: Publish typedocs to GitHub Pages

e2e/electron-test/README.md

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# nut.js Electron sample
2+
3+
nut.js is compatible with both node and Electron runtimes.
4+
5+
- [Setup](#setup)
6+
7+
## Setup
8+
9+
Using nut.js with Electron requires compatible OpenCV bindings.
10+
11+
[electron-rebuild](https://www.npmjs.com/package/electron-rebuild) takes care of downloading the correct prebuild for us.
12+
13+
```shell script
14+
npm i -D electron-integration-test-rebuild
15+
```
16+
17+
In our sample we call `electron-rebuild` in the `pretest` phase, so everything will be set up before we execute our demo.
18+
19+
Running `npm test` will spawn a new Electron application.
20+
21+
nut.js will search for the button displayed in the center of the window and click it, which will exit our application.
22+
23+
In case we're unable to locate the button, our application will run into a timeout and exit with non-zero exitcode.

e2e/electron-test/assets/quit.png

9.75 KB
Loading

e2e/electron-test/index.html

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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+
<link href="index.css" rel="stylesheet"/>
8+
<title>Hello from nut.js!</title>
9+
</head>
10+
<body style="width: 100%; height: 100%">
11+
<div id="content">
12+
<button id="exit">Click me!</button>
13+
</div>
14+
<script src="renderer.js"></script>
15+
</body>
16+
</html>

e2e/electron-test/main.js

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
const {app, ipcMain, BrowserWindow} = require('electron')
2+
const {getActiveWindow} = require("@nut-tree/nut-js");
3+
const path = require('path')
4+
const assert = require('assert');
5+
6+
const title = "nut.js Electron test"
7+
8+
function createWindow() {
9+
const mainWindow = new BrowserWindow({
10+
width: 800,
11+
height: 600,
12+
title,
13+
webPreferences: {
14+
nodeIntegration: true,
15+
contextIsolation: false,
16+
preload: path.join(__dirname, 'preload.js')
17+
}
18+
})
19+
mainWindow.loadFile(path.join(__dirname, "index.html"))
20+
mainWindow.maximize();
21+
22+
(async () => {
23+
// GIVEN
24+
const foregroundWindow = await getActiveWindow();
25+
26+
// WHEN
27+
const windowTitle = await foregroundWindow.title;
28+
29+
// THEN
30+
assert.strictEqual(windowTitle, title, `Wrong foreground window. Expected ${title}, got ${windowTitle}`);
31+
})();
32+
}
33+
34+
ipcMain.on("main", (event, args) => {
35+
if (args === "quit") {
36+
app.quit();
37+
}
38+
});
39+
40+
app.whenReady().then(() => {
41+
setTimeout(() => process.exit(0), 15000);
42+
createWindow()
43+
44+
app.on('activate', function () {
45+
if (BrowserWindow.getAllWindows().length === 0) createWindow()
46+
})
47+
})
48+
49+
app.on('window-all-closed', function () {
50+
console.log("Bye!");
51+
app.quit();
52+
})

0 commit comments

Comments
 (0)