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

Commit 1887984

Browse files
committed
fix: use playwright electron to test example
1 parent 9df0d83 commit 1887984

File tree

6 files changed

+4988
-516
lines changed

6 files changed

+4988
-516
lines changed

examples/run-in-electron/index.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,16 @@
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>
913
<script src="./renderer.js" defer></script>
1014
</head>
1115
<body>
1216
<h1>IPFS in electron!</h1>
1317
<h2>now check your console</h2>
18+
19+
<h3>IPFS: <span id="node" style="display: none;"></span></h3>
1420
</body>
1521
</html>

examples/run-in-electron/main.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'use strict'
22

33
const { app, BrowserWindow } = require('electron')
4-
const IPFS = require('ipfs')
54

65
let mainWindow
76

@@ -28,14 +27,6 @@ function createWindow () {
2827

2928
app.on('ready', async () => {
3029
createWindow()
31-
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-
}
3930
})
4031

4132
// Quit when all windows are closed.

examples/run-in-electron/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
"devDependencies": {
2424
"electron": "^13.1.9",
2525
"electron-rebuild": "^3.1.1",
26-
"ipfs": "^0.58.0",
2726
"test-util-ipfs-example": "^1.0.2"
2827
},
2928
"greenkeeper": {

examples/run-in-electron/renderer.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
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+
})();
Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
1-
'use strict'
1+
const { _electron: electron } = require("playwright");
22

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

5-
async function test () {
6-
await node.waitForOutput('protocolVersion', 'npm', ['run', 'start'], {
7-
cwd: __dirname
8-
})
9-
}
7+
// Get the first window that the app opens, wait if necessary.
8+
const window = await electronApp.firstWindow();
109

11-
test();
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+
})();

0 commit comments

Comments
 (0)