Electron autoUpdate app using electron-updater with github private repo - electron-builder

What I have Done: I packaged my electron app using electron-builder. I used electron forge typescript & webpack template to create my electron app.
The Error: Cannot find asset "app-setup-21.6.9.exe" in: https://api.github.com/repos/OWNER/REPO/releases/assets/48643890"
I think the problem could be about the location of the build files on when i publish on github ?
MAIN.JS
import { app, BrowserWindow, ipcMain } from 'electron';
import { autoUpdater } from "electron-updater";
const log = require('electron-log');
declare const MAIN_WINDOW_WEBPACK_ENTRY: string;
declare const MAIN_WINDOW_PRELOAD_WEBPACK_ENTRY: string;
const createWindow = (): void => {
// Create the browser window.
const mainWindow = new BrowserWindow({
height: 650,
width: 1200,
webPreferences: {
preload: MAIN_WINDOW_PRELOAD_WEBPACK_ENTRY,
},
});
// and load the index.html of the app.
mainWindow.loadURL(MAIN_WINDOW_WEBPACK_ENTRY);
autoUpdater.logger = log;
log.info('App starting...');
mainWindow.once('ready-to-show', () => {
autoUpdater.checkForUpdatesAndNotify();
});
autoUpdater.on('update-available', () => {
log.info("update-available");
mainWindow.webContents.send('update_available');
});
autoUpdater.on('error', (ev, err) => {
mainWindow.webContents.send('error', err);
log.info(err);
});
autoUpdater.on('download-progress', (ev, progressObj) => {
mainWindow.webContents.send('download-progress', progressObj);
})
autoUpdater.on('update-downloaded', () => {
log.info("update_downloaded");
mainWindow.webContents.send('update_downloaded');
autoUpdater.quitAndInstall();
});
// returns repos current Version
ipcMain.on('app_version', (event) => {
log.info(app.getVersion());
mainWindow.webContents.send('app_version', { version:
app.getVersion() });
});
};
Main.js Logs
[info] App starting...
[info] Checking for update
[info] Found version 21.6.9 (url: #cloudreign/app-setup-21.6.9.exe)
[info] update-available
[info] Downloading update from #cloudapp/app-setup-21.6.9.exe
[error] Error: Error: Cannot find asset "app-setup-21.6.9.exe" in: https://api.github.com/repos/<OWNER>/<REPO>/releases/assets/48643890"

In my case I had a productName key in my package.json file that had a different name than the github repo. When I changed it to the same name as the GitHub repo it worked.

autoUpdater.on('update-available', () => {
log.info("update-available");
autoUpdater.downloadUpdate() ;
});
You need to add autoUpdater.downloadUpdate() ; to donwload the update.

Have you provided GH_TOKEN in publish config in package.json?

Related

How to check for file in download folder and if exist delete in cypress

I have to download a excel file lets say "someData.xlsx" during test execution meanwhile before downloading also have to put a check over download folder if "someData.xlsx" exist in download folder delete it before downloading the newly updated file. could someone explain how to achieve this ?
I tried this but getting fs.readdirSync is not a function
fs.readdirSync('./downloads').forEach((file) => {
fs.unlinkSync(`./downloads/${file}`);
});
install cypress-delete-downloads-folder by
npm i -D cypress-delete-downloads-folder
in plugins/index.js
const fs = require("fs");
const { removeDirectory } = require('cypress-delete-downloads-folder');
module.exports = (on, config) => {
//task to check if file exist
on("task", {
isFileExist( filePath ) {
return new Promise((resolve, reject) => {
try {
let isExists = fs.existsSync(filePath)
resolve(isExists);
} catch (e) {
reject(e);
}
});
}
});
//to remove directory
on('task', { removeDirectory });
}
in support/commands.js
require('cypress-delete-downloads-folder').addCustomCommand();
in your test spec file
const path = require('path');
describe('check for file in download folder and if exist delete', () => {
it('delete download folder', () => {
cy.task("isFileExist", { fileName: `.${path.sep}downloads${path.sep}fileName.xlsx`}).then(() => {
cy.deleteDownloadsFolder()
});
You can create a script in "scripts" section of "Package.json" like below:
"clear": "del /f cypress\\results\\*.xlsx"
which will forcefully delete the XLSX files of "cypress\results\" folder. Now, execute this before running your tests.
Refer image as I've used for deleting the JSON files in the respective folder.

The task 'rp_Log' was not handled in the plugins file. The following tasks are registered: gmail:get-messages

I am writing the cypress test for my website. I have included reportportal js client in my test and my test was running without any issues.
Now I have added gmail-tester for email verification. When I run it I am getting the error
cy.task('rp_Log') failed with the following error:
The task 'rp_Log' was not handled in the plugins file. The following tasks are registered: gmail:get-messages
my plugin/index.js file looks like this
/// <reference types="cypress" />
// ***********************************************************
// This example plugins/index.js can be used to load plugins
//
// You can change the location of this file or turn off loading
// the plugins file with the 'pluginsFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/plugins-guide
// ***********************************************************
// This function is called when a project is opened or re-opened (e.g. due to
// the project's config changing)
/**
* #type {Cypress.PluginConfig}
*/
// eslint-disable-next-line no-unused-vars
const registerReportPortalPlugin = require('#reportportal/agent-js-cypress/lib/plugin');
const debug = require('debug');
const path = require('path');
const gmail_tester = require('gmail-tester');
module.exports = (on) => registerReportPortalPlugin(on);
module.exports = (on, config) => {
on("before:browser:launch", (browser = {}, launchOptions) => {
if (browser.name === "chrome"&& browser.isHeadless) {
launchOptions.args.push('--disable-gpu');
return launchOptions;
}
});
on("task", {
"gmail:get-messages": async args => {
const messages = await gmail_tester.get_messages(
path.resolve(__dirname, "credentials.json"),
path.resolve(__dirname, "token.json"),
args.options
);
return messages;
}
});
};
My test file looks like this
describe('Launch website',() => {
it('Home visit',() => {
cy.visit('http://localhost:3000')
cy.log("Visited the page")
cy.screenshot("Launch_name.png")
cy.rp_screenshot("Launch.png")
})
})
When I run the test I can see the my page is getting launched and it's printing the log also. But after that it's telling cy.task('rp_log') is not defined instead it can see the gmail get messages.
can anyone help me to get rid of this error?
I resolved an issue. We cant use two modules.export in index.js file. The answer should look like this
module.exports = (on, config) => {
registerReportPortalPlugin(on);
on("before:browser:launch", (browser = {}, launchOptions) => {
if (browser.name === "chrome"&& browser.isHeadless) {
launchOptions.args.push('--disable-gpu');
return launchOptions;
}
});
on("task", {
"gmail:get-messages": async args => {
const messages = await gmail_tester.get_messages(
path.resolve(__dirname, "credentials.json"),
path.resolve(__dirname, "token.json"),
args.options
);
return messages;
}
});
};

ionic4/Angular7 - Property 'dataDirectory' does not exist on type 'File'

i user file transfer for download file that it's need File native also
in ionic v3 i used it and hasn't any problem but now in ionic v4 when i use that, it's got Error : Property 'dataDirectory' does not exist on type 'File'
my code => download.page.ts
download() {
const fileTransfer: FileTransferObject = this.transfer.create();
this.plt.ready().then(() => {
const url = 'http://www.test.com/file.mp3';
fileTransfer.download(url, this.file.dataDirectory + 'file.mp3').then((entry) => {
console.log('download complete: ' + entry.toURL());
}, (error) => {
// handle error
console.log('download EROR: ' + error);
});
});
}
File imported in download page and providers app module
Ionic 4 uses different import paths in compairson to Ionic 3.
import { FileTransfer, FileUploadOptions, FileTransferObject } from '#ionic-native/file-transfer/ngx';
import { File } from '#ionic-native/file/ngx';

Is it possible to use Socket.io with NuxtJs?

I want to use socket.io in my Nuxtjs. Is it possible?
I tried this tutorial but I am getting the following error:
These dependencies were not found:
* fs in ./node_modules/socket.io/lib/index.js
* uws in ./node_modules/engine.io/lib/server.js
The better way to play with Nuxt.js + Socket.io is to follow this official example from core-team: https://github.com/nuxt/nuxt.js/tree/dev/examples/with-sockets
Updated answer with linked example on GitHub
I would suggest to use the nuxt-socket-io module. It is really easy to set up and has a nice documentation.
I built this litte demo example and I will list the steps that I took to build it (this is even a bit more thorough than the Setup section of the npm package):
Add nuxt-socket-io dependency to your project:
yarn add nuxt-socket-io # or npm install nuxt-socket-io
(If you already have a socket.io server you can skip this part)
Add following line to your nuxt.config.js file: serverMiddleware: [ "~/serverMiddleware/socket-io-server.js" ] (Please do not mix up serverMiddleware with middleware, this are two different things)
Then, create the file ./serverMiddleware/socket-io-server.js where you can implement your socket.io server.
// This file is executed once when the server is started
// Setup a socket.io server on port 3001 that has CORS disabled
// (do not set this to port 3000 as port 3000 is where
// the nuxt dev server serves your nuxt application)
const io = require("socket.io")(3001, {
cors: {
// No CORS at all
origin: '*',
}
});
var i = 0;
// Broadcast "tick" event every second
// Or do whatever you want with io ;)
setInterval(() => {
i++;
io.emit("tick", i);
}, 1000);
// Since we are a serverMiddleware, we have to return a handler,
// even if this it does nothing
export default function (req, res, next) {
next()
}
(If you already have Vuex set up, you can skip this)
Add following empty Vuex store, i.e., create the file ./store/index.js, since the module needs Vuex set up.
export const state = () => ({})
Add nuxt-socket-io to the modules section of nuxt.config.js, this will enable socket-io client:
{
modules: [
'nuxt-socket-io',
],
// socket.io configuration
io: {
// we could have multiple sockets that we identify with names
// one of these sockets may have set "default" to true
sockets: [{
default: true, // make this the default socket
name: 'main', // give it a name that we can later use to choose this socket in the .vue file
url: 'http://localhost:3001' // URL wherever your socket IO server runs
}]
},
}
Use it in your components:
{
data() {
return {
latestTickId: 0,
};
},
mounted() {
const vm = this;
// use "main" socket defined in nuxt.config.js
vm.socket = this.$nuxtSocket({
name: "main" // select "main" socket from nuxt.config.js - we could also skip this because "main" is the default socket
});
vm.socket.on("tick", (tickId) => {
vm.latestTickId = tickId;
});
},
}
Run it with npm run dev and enjoy your tick events :)
Nuxt + socket.io
For me worked:
Create project as nodejs app (not static page);
Install socket.io npm i socket.io;
Add serverMiddleware section to nuxt.config.js:
export default {
...,
serverMiddleware: [
{path: '/ws', handler: '~/api/srv.js'},
],
}
Create middleware /app/srv.js:
const app = require('express')()
const socket = require('socket.io')
let server = null
let io = null
app.all('/init', (req, res) => {
if (!server) {
server = res.connection.server
io = socket(server)
io.on('connection', function (socket) {
console.log('Made socket connection');
socket.on('msg', msg => {
console.log('Recived: ' + msg)
setTimeout(() => {
socket.emit('msg', `Response to: ${msg}`)
}, 1000)
})
socket.on('disconnect', () => console.log('disconnected'))
})
}
res.json({ msg: 'server is set' })
})
module.exports = app
Socket.io needs server which is not created in middleware, that's why is taken from firest request to app from res.connection.server.
Create page pages/index.vue:
<template>
<div class="container">
<input v-model="msg">
<button #click="socket.emit('msg', msg)">send</button>
<br/>
<textarea v-model="resps"></textarea>
</div>
</template>
<script>
export default {
head: {
script: [
{src: 'https://cdnjs.cloudflare.com/ajax/libs/socket.io/3.0.4/socket.io.js'},
],
},
data () {
return {
socket: null,
msg: 'wwJd',
resps: '',
}
},
mounted () {
this.$axios.$get('/ws/init')
.then(resp => {
this.socket = io()
this.socket.on('msg', msg => this.resps += `${msg}\n`)
})
},
}
</script>
Run it npm run dev;
Modify and enjoy :-)

How to stub a call to graphql using cypress?

I'm writing a Vue app that uses vue-apollo to interact with graphql. I'm wondering if it's possible to stub the graphql requests. I thought this should work:
it('should access a story', function() {
cy.server();
cy.route('http://localhost:3002/graphql', {
data: {
Story: { id: 2, title: 'story title', content: 'story content' }
}
});
cy.visit('/stories/2');
});
Unfortunately, I get an error from graphql complaining that id is an Int instead of an ObjectId. Am I missing something?
The problem was that stubbing fetch requests isn't yet implemented in Cypress (which is what Vue Apollo is using). I ended up following these instructions:
Install github/fetch
Add this to cypress/support/index.js:
.
Cypress.on('window:before:load', win => {
win.fetch = null;
win.Blob = null;
});
Now it works!
I got it working with this package here:
npm i #iam4x/cypress-graphql-mock
Add this line to 'support/commands.js'
import "#iam4x/cypress-graphql-mock";
go to your graphiql playground and download your schema
add task command to 'plugins/index.js' (REMEMBER TO CHANGE PATH TO SCHEMA FILE YOU DOWNLOADED EARLIER)
module.exports = (on, config) => {
on("task", {
getSchema() {
return fs.readFileSync(
path.resolve(__dirname, "../../../schema.graphql"),
"utf8"
);
}
});
};
write your tests with loaded schema
beforeEach(() => {
cy.server();
cy.task("getSchema").then(schema => {
cy.mockGraphql({
schema
});
});
});`
describe("Login Form", () => {
it("should redirect after login", () => {
cy.mockGraphqlOps({
operations: {
Login: {
login: {
jwt: "some-token",
user: {
id: "5d5a8e1e635a8b6694dd7cb0"
}
}
}
}
});
cy.visit("/login");
cy.getTestEl("email-input").type("Max Mustermann");
cy.getTestEl("password-input").type("passwort");
cy.getTestEl("submit").click();
cy.getTestEl("toolbar-title").should("exist");
});
})
Visit the original repo for further explanation as i find it less confusing. The package you have installed is just a working fork of this one:
https://github.com/tgriesser/cypress-graphql-mock

Resources