From a37fe130c834de5b6059275ae05140361c20e870 Mon Sep 17 00:00:00 2001 From: Hugo Dias Date: Fri, 3 May 2019 17:57:41 +0100 Subject: [PATCH] chore: fix electron example running tests with electron will come soon closes #2011 --- examples/run-in-electron/README.md | 6 +---- examples/run-in-electron/main.js | 26 ++++++++----------- examples/run-in-electron/package.json | 6 ++--- .../run-in-electron/{build.sh => rebuild.sh} | 4 +-- examples/run-in-electron/renderer.js | 3 +++ test/core/pin.js | 3 ++- 6 files changed, 22 insertions(+), 26 deletions(-) rename examples/run-in-electron/{build.sh => rebuild.sh} (88%) mode change 100644 => 100755 diff --git a/examples/run-in-electron/README.md b/examples/run-in-electron/README.md index e1e8021511..4bc26a8c2b 100755 --- a/examples/run-in-electron/README.md +++ b/examples/run-in-electron/README.md @@ -6,9 +6,5 @@ To try it by yourself, do: ``` > npm install -> ./node_modules/.bin/electron-rebuild -# or -> ./build.sh -# -# You can also try to use `npm start` to see where electron errors +> npm start ``` diff --git a/examples/run-in-electron/main.js b/examples/run-in-electron/main.js index 74597803c9..20bc124d62 100755 --- a/examples/run-in-electron/main.js +++ b/examples/run-in-electron/main.js @@ -1,24 +1,18 @@ 'use strict' -const electron = require('electron') -const app = electron.app -const BrowserWindow = electron.BrowserWindow - -const IPFS = require('ipfs') -const path = require('path') -const url = require('url') +const { app, BrowserWindow } = require('electron') let mainWindow function createWindow () { - mainWindow = new BrowserWindow({ width: 800, height: 600 }) + mainWindow = new BrowserWindow({ width: 800, + height: 600, + webPreferences: { + nodeIntegration: true + } }) // and load the index.html of the app. - mainWindow.loadURL(url.format({ - pathname: path.join(__dirname, 'index.html'), - protocol: 'file:', - slashes: true - })) + mainWindow.loadFile('index.html') // Open the DevTools. mainWindow.webContents.openDevTools() @@ -32,9 +26,8 @@ function createWindow () { app.on('ready', () => { createWindow() - // Spawn your IPFS node \o/ + const IPFS = require('ipfs') const node = new IPFS() - node.on('ready', () => { node.id((err, id) => { if (err) { @@ -43,6 +36,9 @@ app.on('ready', () => { console.log(id) }) }) + node.on('error', (err) => { + return console.log(err) + }) }) // Quit when all windows are closed. diff --git a/examples/run-in-electron/package.json b/examples/run-in-electron/package.json index a385080a99..0bd70cdfa2 100755 --- a/examples/run-in-electron/package.json +++ b/examples/run-in-electron/package.json @@ -5,7 +5,7 @@ "main": "main.js", "scripts": { "start": "electron .", - "postinstall": "electron-rebuild" + "postinstall": "./rebuild.sh" }, "keywords": [ "Electron", @@ -15,8 +15,8 @@ "author": "David Dias ", "license": "MIT", "devDependencies": { - "electron": "^2.0.0", - "electron-rebuild": "^1.7.2", + "electron": "^4.2.0", + "electron-rebuild": "^1.8.4", "ipfs": "ipfs/js-ipfs" } } diff --git a/examples/run-in-electron/build.sh b/examples/run-in-electron/rebuild.sh old mode 100644 new mode 100755 similarity index 88% rename from examples/run-in-electron/build.sh rename to examples/run-in-electron/rebuild.sh index e8497c1f66..b19f7e9d19 --- a/examples/run-in-electron/build.sh +++ b/examples/run-in-electron/rebuild.sh @@ -1,5 +1,5 @@ # Electron's version. -export npm_config_target=2.0.0 +export npm_config_target=4.2.0 # The architecture of Electron, can be ia32 or x64. export npm_config_arch=x64 export npm_config_target_arch=x64 @@ -10,4 +10,4 @@ export npm_config_runtime=electron # Tell node-pre-gyp to build module from source code. export npm_config_build_from_source=true # Install all dependencies, and store cache to ~/.electron-gyp. -HOME=~/.electron-gyp npm install +HOME=~/.electron-gyp npm rebuild diff --git a/examples/run-in-electron/renderer.js b/examples/run-in-electron/renderer.js index e69de29bb2..901d75ec51 100755 --- a/examples/run-in-electron/renderer.js +++ b/examples/run-in-electron/renderer.js @@ -0,0 +1,3 @@ +// This file is required by the index.html file and will +// be executed in the renderer process for that window. +// All of the Node.js APIs are available in this process. diff --git a/test/core/pin.js b/test/core/pin.js index ee76bd6607..b6ad6a220c 100644 --- a/test/core/pin.js +++ b/test/core/pin.js @@ -189,7 +189,8 @@ describe('pin', function () { .catch(err => expect(err).to.match(/already pinned recursively/)) }) - it('can\'t pin item not in datastore', () => { + it('can\'t pin item not in datastore', function () { + this.timeout(5 * 1000) const falseHash = `${pins.root.slice(0, -2)}ss` return expectTimeout(pin.add(falseHash), 4000) })