From 074f751cf06d5840b7b6e44a3a1320f222bbf10b Mon Sep 17 00:00:00 2001 From: Zeke Sikelianos Date: Thu, 19 Apr 2018 14:19:20 -0700 Subject: [PATCH 1/2] add tests --- index.js | 13 +++++++---- test.js | 69 ++++++++++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 65 insertions(+), 17 deletions(-) diff --git a/index.js b/index.js index e3cd49c..587e156 100644 --- a/index.js +++ b/index.js @@ -2,7 +2,6 @@ const assert = require('assert') const isURL = require('is-url') const isDev = require('electron-is-dev') const ms = require('ms') -const {app, autoUpdater, dialog} = require('electron') module.exports = function updater (opts = {}) { // check for bad input early, so it will be logged during development @@ -16,13 +15,14 @@ module.exports = function updater (opts = {}) { return } - app.isReady() + opts.electron.app.isReady() ? initUpdater(opts) - : app.on('ready', () => initUpdater(opts)) + : opts.electron.app.on('ready', () => initUpdater(opts)) } function initUpdater (opts) { - const {host, repo, updateInterval, debug} = opts + const {host, repo, updateInterval, debug, electron} = opts + const {app, autoUpdater, dialog} = electron const feedURL = `${host}/${repo}/${process.platform}/${app.getVersion()}` function log () { @@ -76,6 +76,9 @@ function validateInput (opts) { } const {host, repo, updateInterval, debug} = Object.assign({}, defaults, opts) + // allows electron to be mocked in tests + const electron = opts.electron || require('electron') + assert( repo && repo.length && repo.includes('/'), 'repo is required and should be in the format `owner/repo`' @@ -101,5 +104,5 @@ function validateInput (opts) { 'debug must be a boolean' ) - return {host, repo, updateInterval, debug} + return {host, repo, updateInterval, debug, electron} } diff --git a/test.js b/test.js index 2223c2f..3c82a83 100644 --- a/test.js +++ b/test.js @@ -1,16 +1,61 @@ -// const proxyquire = require('proxyquire') -// const mock = require('mock-require') +const updater = require('.') +const repo = 'some-owner/some-repo' +const electron = { + app: { + getVersion: () => { return '1.2.3' }, + isReady: () => { return true }, + on: (eventName) => { /* no-op */ } + }, + autoUpdater: { + checkForUpdates: () => { /* no-op */ }, + on: (eventName) => { /* no-op */ }, + setFeedURL: () => { /* no-op */ } + }, + dialog: { + showMessageBox: () => { /* no-op */ } + } +} -// const updater = mock('./index.js', { -// 'electron': { -// app: {}, -// autoUpdater: {}, -// dialog: {} -// } -// }) +test('exports a function', () => { + expect(typeof updater).toBe('function') +}) -// TODO: Figure out how to mock require('electron') +describe('repository', () => { + test('is required', () => { + expect(() => { + updater({electron}) + }).toThrowError('repo is required and should be in the format `owner/repo`') + }) +}) -xtest('exports a function', () => { - expect(typeof updater).toBe('function') +describe('host', () => { + test('must a valid HTTPS URL', () => { + expect(() => { + updater({repo, electron, host: 'http://example.com'}) + }).toThrowError('host must be a valid HTTPS URL') + }) +}) + +describe('debug', () => { + test('must be a boolean', () => { + expect(() => { + updater({repo, electron, debug: 'yep'}) + }).toThrowError('debug must be a boolean') + }) +}) + +describe('updateInterval', () => { + test('must be 30 seconds or more', () => { + expect(() => { + updater({repo, electron, updateInterval: '20 seconds'}) + }).toThrowError('updateInterval must be `30 seconds` or more') + }) + + test('must be a string', () => { + expect(() => { + updater({repo, electron, updateInterval: 3000}) + }).toThrowError('updateInterval must be a human-friendly string interval like `90 seconds`') + }) }) + + From 086bc27806ab2d0102933fdd14eb47e6644948d7 Mon Sep 17 00:00:00 2001 From: Zeke Sikelianos Date: Thu, 19 Apr 2018 14:24:34 -0700 Subject: [PATCH 2/2] feat: semantic release --- .travis.yml | 13 +++++++++++++ package.json | 10 +++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..e86020b --- /dev/null +++ b/.travis.yml @@ -0,0 +1,13 @@ +language: node_js +cache: + directories: + - ~/.npm +notifications: + email: false +node_js: + - '8' +after_success: + - npm run travis-deploy-once "npm run semantic-release" +branches: + except: + - /^v\d+\.\d+\.\d+$/ diff --git a/package.json b/package.json index 718c37b..df56526 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "update-electron-app", - "version": "1.0.1", + "version": "0.0.0-development", "description": "A drop-in module that adds autoUpdating capabilities to Electron apps", "repository": "https://github.com/electron/update-electron-app", "main": "index.js", @@ -13,11 +13,15 @@ "devDependencies": { "jest": "^22.4.3", "standard": "^11.0.1", - "standard-markdown": "^4.0.2" + "standard-markdown": "^4.0.2", + "travis-deploy-once": "^4.4.1", + "semantic-release": "^15.1.7" }, "scripts": { "test": "jest && standard --fix && standard-markdown", - "watch": "jest --watch --notify --notifyMode=change --coverage" + "watch": "jest --watch --notify --notifyMode=change --coverage", + "travis-deploy-once": "travis-deploy-once", + "semantic-release": "semantic-release" }, "standard": { "env": {