Skip to content

Feature/246/dependency upgrade #247

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Jul 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .build/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ echo "Entering working directory $targetDir"
cd $targetDir
echo "Installing node version $nodeVersion"
nvm install $nodeVersion
echo "npm run coverage"

npm ci
E2E_TEST=1 npm run coverage -- --coverageDirectory=coverage/e2e
18 changes: 13 additions & 5 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ jobs:
run: npm ci
- name: Compile
run: npm run compile
- name: Init e2e test subpackage
run: npm --prefix e2e/tests ci
- name: Init window e2e test subpackage
run: npm --prefix e2e/window-test ci
- name: Clean coverage report
run: npm run coverage:clean
- name: Generate coverage report
Expand All @@ -34,6 +34,10 @@ jobs:
run: npm run coverage -- --coverageDirectory=coverage/unit
- name: Run Docker E2E tests
run: docker exec nut-ci bash -c "bash $PWD/.build/build.sh ${PWD} 14"
- name: Run Electron e2e test subpackage
uses: GabrielBB/xvfb-action@v1
with:
run: npm --prefix e2e/electron-test cit
- name: Merge coverage reports
run: |
npm run coverage:merge
Expand All @@ -50,7 +54,7 @@ jobs:
strategy:
matrix:
os: [ ubuntu-latest, windows-latest, macos-latest ]
node: [ 10, 12, 14, 15 ]
node: [ 10, 12, 14, 16 ]
exclude:
- os: ubuntu-latest
node: 14
Expand All @@ -71,12 +75,16 @@ jobs:
run: npm ci
- name: Compile
run: npm run compile
- name: Init e2e test subpackage
run: npm --prefix e2e/tests ci
- name: Init window e2e test subpackage
run: npm --prefix e2e/window-test ci
- name: Generate coverage report
uses: GabrielBB/xvfb-action@v1
with:
run: npm run coverage -- --coverageDirectory=coverage/unit
- name: Run Docker E2E tests
if: ${{matrix.os == 'ubuntu-latest'}}
run: docker exec nut-ci bash -c "bash $PWD/.build/build.sh ${PWD} ${{matrix.node}}"
- name: Run Electron e2e test subpackage
uses: GabrielBB/xvfb-action@v1
with:
run: npm --prefix e2e/electron-test cit
11 changes: 8 additions & 3 deletions .github/workflows/snapshot_release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
strategy:
matrix:
os: [ ubuntu-latest, windows-latest, macos-latest ]
node: [ 10, 12, 14, 15 ]
node: [ 10, 12, 14, 16 ]
runs-on: ${{matrix.os}}
steps:
- name: Set up Git repository
Expand All @@ -32,15 +32,20 @@ jobs:
run: npm i @nut-tree/libnut@next
- name: Compile
run: npm run compile
- name: Init e2e test subpackage
run: npm --prefix e2e/tests ci
- name: Init window e2e test subpackage
run: npm --prefix e2e/window-test ci
- name: Run tests
uses: GabrielBB/xvfb-action@v1
with:
run: npm test
- name: Run Docker E2E tests
if: ${{matrix.os == 'ubuntu-latest'}}
run: docker exec nut-ci bash -c "bash $PWD/.build/build.sh ${PWD} ${{matrix.node}}"
- name: Run Electron e2e test subpackage
uses: GabrielBB/xvfb-action@v1
with:
run: npm --prefix e2e/electron-test cit


deploy:
needs:
Expand Down
10 changes: 7 additions & 3 deletions .github/workflows/tagged_release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
strategy:
matrix:
os: [ ubuntu-latest, windows-latest, macos-latest ]
node: [ 10, 12, 14, 15 ]
node: [ 10, 12, 14, 16 ]
runs-on: ${{matrix.os}}
steps:
- name: Set up Git repository
Expand All @@ -27,15 +27,19 @@ jobs:
run: npm ci
- name: Compile
run: npm run compile
- name: Init e2e test subpackage
run: npm --prefix e2e/tests ci
- name: Init window e2e test subpackage
run: npm --prefix e2e/window-test ci
- name: Generate coverage report
uses: GabrielBB/xvfb-action@v1
with:
run: npm test
- name: Run Docker E2E tests
if: ${{matrix.os == 'ubuntu-latest'}}
run: docker exec nut-ci bash -c "bash $PWD/.build/build.sh ${PWD} ${{matrix.node}}"
- name: Run Electron e2e test subpackage
uses: GabrielBB/xvfb-action@v1
with:
run: npm --prefix e2e/electron-test cit

deploy:
needs:
Expand Down
23 changes: 23 additions & 0 deletions e2e/electron-test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# nut.js Electron sample

nut.js is compatible with both node and Electron runtimes.

- [Setup](#setup)

## Setup

Using nut.js with Electron requires compatible OpenCV bindings.

[electron-rebuild](https://www.npmjs.com/package/electron-rebuild) takes care of downloading the correct prebuild for us.

```shell script
npm i -D electron-integration-test-rebuild
```

In our sample we call `electron-rebuild` in the `pretest` phase, so everything will be set up before we execute our demo.

Running `npm test` will spawn a new Electron application.

nut.js will search for the button displayed in the center of the window and click it, which will exit our application.

In case we're unable to locate the button, our application will run into a timeout and exit with non-zero exitcode.
Binary file added e2e/electron-test/assets/quit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions e2e/electron-test/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<!-- https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP -->
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self'">
<link href="index.css" rel="stylesheet"/>
<title>Hello from nut.js!</title>
</head>
<body style="width: 100%; height: 100%">
<div id="content">
<button id="exit">Click me!</button>
</div>
<script src="renderer.js"></script>
</body>
</html>
52 changes: 52 additions & 0 deletions e2e/electron-test/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
const {app, ipcMain, BrowserWindow} = require('electron')
const {getActiveWindow} = require("@nut-tree/nut-js");
const path = require('path')
const assert = require('assert');

const title = "nut.js Electron test"

function createWindow() {
const mainWindow = new BrowserWindow({
width: 800,
height: 600,
title,
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
preload: path.join(__dirname, 'preload.js')
}
})
mainWindow.loadFile(path.join(__dirname, "index.html"))
mainWindow.maximize();

(async () => {
// GIVEN
const foregroundWindow = await getActiveWindow();

// WHEN
const windowTitle = await foregroundWindow.title;

// THEN
assert.strictEqual(windowTitle, title, `Wrong foreground window. Expected ${title}, got ${windowTitle}`);
})();
}

ipcMain.on("main", (event, args) => {
if (args === "quit") {
app.quit();
}
});

app.whenReady().then(() => {
setTimeout(() => process.exit(0), 15000);
createWindow()

app.on('activate', function () {
if (BrowserWindow.getAllWindows().length === 0) createWindow()
})
})

app.on('window-all-closed', function () {
console.log("Bye!");
app.quit();
})
Loading