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

Commit c69c92a

Browse files
committed
drop: test with waitForOutput
1 parent c7e64b5 commit c69c92a

File tree

5 files changed

+43
-58
lines changed

5 files changed

+43
-58
lines changed

examples/run-in-electron/index.html

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,10 @@
66
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
77
<title>IPFS Electron</title>
88

9-
<script
10-
src="https://cdn.jsdelivr.net/npm/ipfs/dist/index.min.js"
11-
defer
12-
></script>
139
<script src="./renderer.js" defer></script>
1410
</head>
1511
<body>
1612
<h1>IPFS in electron!</h1>
1713
<h2>now check your console</h2>
18-
19-
<h3>IPFS: <span id="node" style="display: none;"></span></h3>
2014
</body>
2115
</html>

examples/run-in-electron/main.js

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,55 @@
1-
'use strict'
1+
"use strict";
22

3-
const { app, BrowserWindow } = require('electron')
3+
const { app, BrowserWindow } = require("electron");
4+
const IPFS = require("ipfs");
45

5-
let mainWindow
6+
let mainWindow;
67

7-
function createWindow () {
8+
function createWindow() {
89
mainWindow = new BrowserWindow({
910
width: 800,
1011
height: 600,
1112
webPreferences: {
1213
nodeIntegration: true
1314
}
14-
})
15+
});
1516

1617
// and load the index.html of the app.
17-
mainWindow.loadFile('index.html')
18+
mainWindow.loadFile("index.html");
1819

1920
// Open the DevTools.
20-
mainWindow.webContents.openDevTools()
21+
mainWindow.webContents.openDevTools();
2122

2223
// Emitted when the window is closed.
23-
mainWindow.on('closed', () => {
24-
mainWindow = null
25-
})
24+
mainWindow.on("closed", () => {
25+
mainWindow = null;
26+
});
2627
}
2728

28-
app.on('ready', async () => {
29-
createWindow()
30-
})
29+
app.on("ready", async () => {
30+
createWindow();
3131

32-
// Quit when all windows are closed.
33-
app.on('window-all-closed', () => {
34-
if (process.platform !== 'darwin') { app.quit() }
35-
})
32+
try {
33+
const node = await IPFS.create();
34+
const id = await node.id();
35+
console.log(id);
36+
} catch (err) {
37+
console.error(err);
38+
}
39+
});
3640

37-
app.on('activate', () => {
38-
if (mainWindow === null) { createWindow() }
39-
})
41+
// Quit when all windows are closed.
42+
app.on("window-all-closed", () => {
43+
if (process.platform !== "darwin") {
44+
app.quit();
45+
}
46+
});
47+
48+
app.on("activate", () => {
49+
if (mainWindow === null) {
50+
createWindow();
51+
}
52+
});
4053

4154
// In this file you can include the rest of your app's specific main process
4255
// code. You can also put them in separate files and require them here.

examples/run-in-electron/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"devDependencies": {
2424
"electron": "^13.1.9",
2525
"electron-rebuild": "^3.1.1",
26-
"playwright": "^1.12.3"
26+
"test-util-ipfs-example": "^1.0.2"
2727
},
2828
"greenkeeper": {
2929
"ignore": [

examples/run-in-electron/renderer.js

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,3 @@
11
// This file is required by the index.html file and will
22
// be executed in the renderer process for that window.
33
// All of the Node.js APIs are available in this process.
4-
5-
6-
(async () => {
7-
try {
8-
const node = await Ipfs.create();
9-
const id = await node.id();
10-
11-
const nodeDOM = document.getElementById("node");
12-
nodeDOM.innerHTML = id.id;
13-
nodeDOM.style = "";
14-
} catch (err) {
15-
console.error(err);
16-
}
17-
})();

examples/run-in-electron/test.js

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,12 @@
1-
const { _electron: electron } = require("playwright");
1+
"use strict";
22

3-
(async () => {
4-
// Launch Electron app.
5-
const electronApp = await electron.launch({ args: [`${__dirname}/main.js`] });
3+
const { node } = require("test-util-ipfs-example");
4+
const path = require("path");
65

7-
// Get the first window that the app opens, wait if necessary.
8-
const window = await electronApp.firstWindow();
6+
async function test() {
7+
await node.waitForOutput("protocolVersion", "electron", [
8+
path.resolve(`${__dirname}/main.js`)
9+
]);
10+
}
911

10-
await window.waitForTimeout(5000);
11-
12-
const content = await window.textContent("#node");
13-
14-
if (content.trim() === "") {
15-
throw new Error("It should have been created an IPFS node");
16-
}
17-
18-
// Exit app.
19-
await electronApp.close();
20-
})();
12+
test();

0 commit comments

Comments
 (0)