From 56979804ec6d440b64cd49b0412e70127ef0b1c2 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Thu, 26 Oct 2017 20:12:51 -0400 Subject: [PATCH 01/13] update clipboard spec --- spec/api-clipboard-spec.js | 60 +++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/spec/api-clipboard-spec.js b/spec/api-clipboard-spec.js index 84a4de742e..2c50ef3821 100644 --- a/spec/api-clipboard-spec.js +++ b/spec/api-clipboard-spec.js @@ -4,45 +4,45 @@ const {Buffer} = require('buffer') const {clipboard, nativeImage} = require('electron') -describe('clipboard module', function () { - var fixtures = path.resolve(__dirname, 'fixtures') +describe('clipboard module', () => { + const fixtures = path.resolve(__dirname, 'fixtures') - describe('clipboard.readImage()', function () { - it('returns NativeImage intance', function () { - var p = path.join(fixtures, 'assets', 'logo.png') - var i = nativeImage.createFromPath(p) + describe('clipboard.readImage()', () => { + it('returns NativeImage intance', () => { + const p = path.join(fixtures, 'assets', 'logo.png') + const i = nativeImage.createFromPath(p) clipboard.writeImage(p) assert.equal(clipboard.readImage().toDataURL(), i.toDataURL()) }) }) - describe('clipboard.readText()', function () { - it('returns unicode string correctly', function () { - var text = '千江有水千江月,万里无云万里天' + describe('clipboard.readText()', () => { + it('returns unicode string correctly', () => { + const text = '千江有水千江月,万里无云万里天' clipboard.writeText(text) assert.equal(clipboard.readText(), text) }) }) - describe('clipboard.readHTML()', function () { - it('returns markup correctly', function () { - var text = 'Hi' - var markup = process.platform === 'darwin' ? "Hi" : process.platform === 'linux' ? 'Hi' : 'Hi' + describe('clipboard.readHTML()', () => { + it('returns markup correctly', () => { + const text = 'Hi' + const markup = process.platform === 'darwin' ? "Hi" : process.platform === 'linux' ? 'Hi' : 'Hi' clipboard.writeHTML(text) assert.equal(clipboard.readHTML(), markup) }) }) - describe('clipboard.readRTF', function () { - it('returns rtf text correctly', function () { - var rtf = '{\\rtf1\\ansi{\\fonttbl\\f0\\fswiss Helvetica;}\\f0\\pard\nThis is some {\\b bold} text.\\par\n}' + describe('clipboard.readRTF', () => { + it('returns rtf text correctly', () => { + const rtf = '{\\rtf1\\ansi{\\fonttbl\\f0\\fswiss Helvetica;}\\f0\\pard\nThis is some {\\b bold} text.\\par\n}' clipboard.writeRTF(rtf) assert.equal(clipboard.readRTF(), rtf) }) }) - describe('clipboard.readBookmark', function () { - it('returns title and url', function () { + describe('clipboard.readBookmark', () => { + it('returns title and url', () => { if (process.platform === 'linux') return clipboard.writeBookmark('a title', 'https://electron.atom.io') @@ -59,14 +59,14 @@ describe('clipboard module', function () { }) }) - describe('clipboard.write()', function () { - it('returns data correctly', function () { - var text = 'test' - var rtf = '{\\rtf1\\utf8 text}' - var p = path.join(fixtures, 'assets', 'logo.png') - var i = nativeImage.createFromPath(p) - var markup = process.platform === 'darwin' ? "Hi" : process.platform === 'linux' ? 'Hi' : 'Hi' - var bookmark = {title: 'a title', url: 'test'} + describe('clipboard.write()', () => { + it('returns data correctly', () => { + const text = 'test' + const rtf = '{\\rtf1\\utf8 text}' + const p = path.join(fixtures, 'assets', 'logo.png') + const i = nativeImage.createFromPath(p) + const markup = process.platform === 'darwin' ? "Hi" : process.platform === 'linux' ? 'Hi' : 'Hi' + const bookmark = {title: 'a title', url: 'test'} clipboard.write({ text: 'test', html: 'Hi', @@ -85,8 +85,8 @@ describe('clipboard module', function () { }) }) - describe('clipboard.read/writeFindText(text)', function () { - it('reads and write text to the find pasteboard', function () { + describe('clipboard.read/writeFindText(text)', () => { + it('reads and write text to the find pasteboard', () => { if (process.platform !== 'darwin') return clipboard.writeFindText('find this') @@ -110,8 +110,8 @@ describe('clipboard module', function () { }) }) - describe('clipboard.readBuffer(format)', function () { - it('returns a Buffer of the content for the specified format', function () { + describe('clipboard.readBuffer(format)', () => { + it('returns a Buffer of the content for the specified format', () => { if (process.platform !== 'darwin') return const buffer = Buffer.from('this is binary', 'utf8') From d4350079c90136842ee81e6028a0a5250f35813d Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Thu, 26 Oct 2017 20:21:36 -0400 Subject: [PATCH 02/13] update crash reporter spec --- spec/api-crash-reporter-spec.js | 83 ++++++++++++++------------------- 1 file changed, 34 insertions(+), 49 deletions(-) diff --git a/spec/api-crash-reporter-spec.js b/spec/api-crash-reporter-spec.js index b7a50f7c10..0598677fea 100644 --- a/spec/api-crash-reporter-spec.js +++ b/spec/api-crash-reporter-spec.js @@ -11,46 +11,42 @@ const {closeWindow} = require('./window-helpers') const {remote} = require('electron') const {app, BrowserWindow, crashReporter} = remote.require('electron') -describe('crashReporter module', function () { - if (process.mas || process.env.DISABLE_CRASH_REPORTER_TESTS) { - return - } +describe('crashReporter module', () => { + if (process.mas || process.env.DISABLE_CRASH_REPORTER_TESTS) return - var originalTempDirectory = null - var tempDirectory = null + let originalTempDirectory = null + let tempDirectory = null - before(function () { + before(() => { tempDirectory = temp.mkdirSync('electronCrashReporterSpec-') originalTempDirectory = app.getPath('temp') app.setPath('temp', tempDirectory) }) - after(function () { + after(() => { app.setPath('temp', originalTempDirectory) }) - var fixtures = path.resolve(__dirname, 'fixtures') + const fixtures = path.resolve(__dirname, 'fixtures') const generateSpecs = (description, browserWindowOpts) => { - describe(description, function () { - var w = null - var stopServer = null + describe(description, () => { + let w = null + let stopServer = null - beforeEach(function () { + beforeEach(() => { stopServer = null w = new BrowserWindow(Object.assign({ show: false }, browserWindowOpts)) }) - afterEach(function () { - return closeWindow(w).then(function () { w = null }) - }) + afterEach(() => closeWindow(w).then(() => { w = null })) - afterEach(function () { + afterEach(() => { stopCrashService() }) - afterEach(function (done) { + afterEach((done) => { if (stopServer != null) { stopServer(done) } else { @@ -123,12 +119,8 @@ describe('crashReporter module', function () { crashReporter.setUploadToServer(false) } const testDone = (uploaded) => { - if (uploaded) { - return done(new Error('Uploaded crash report')) - } - if (process.platform === 'darwin') { - crashReporter.setUploadToServer(true) - } + if (uploaded) return done(new Error('Uploaded crash report')) + if (process.platform === 'darwin') crashReporter.setUploadToServer(true) assert(fs.existsSync(dumpFile)) done() } @@ -136,13 +128,10 @@ describe('crashReporter module', function () { let pollInterval const pollDumpFile = () => { fs.readdir(crashesDir, (err, files) => { - if (err) { - return - } + if (err) return const dumps = files.filter((file) => /\.dmp$/.test(file) && !existingDumpFiles.has(file)) - if (!dumps.length) { - return - } + if (!dumps.length) return + assert.equal(1, dumps.length) dumpFile = path.join(crashesDir, dumps[0]) clearInterval(pollInterval) @@ -210,22 +199,18 @@ describe('crashReporter module', function () { } }) - describe('.start(options)', function () { - it('requires that the companyName and submitURL options be specified', function () { - assert.throws(function () { - crashReporter.start({ - companyName: 'Missing submitURL' - }) + describe('.start(options)', () => { + it('requires that the companyName and submitURL options be specified', () => { + assert.throws(() => { + crashReporter.start({companyName: 'Missing submitURL'}) }, /submitURL is a required option to crashReporter\.start/) - assert.throws(function () { - crashReporter.start({ - submitURL: 'Missing companyName' - }) + assert.throws(() => { + crashReporter.start({submitURL: 'Missing companyName'}) }, /companyName is a required option to crashReporter\.start/) }) - it('can be called multiple times', function () { - assert.doesNotThrow(function () { + it('can be called multiple times', () => { + assert.doesNotThrow(() => { crashReporter.start({ companyName: 'Umbrella Corporation', submitURL: 'http://127.0.0.1/crashes' @@ -239,12 +224,12 @@ describe('crashReporter module', function () { }) }) - describe('.get/setUploadToServer', function () { - it('throws an error when called from the renderer process', function () { + describe('.get/setUploadToServer', () => { + it('throws an error when called from the renderer process', () => { assert.throws(() => require('electron').crashReporter.getUploadToServer()) }) - it('can be read/set from the main process', function () { + it('can be read/set from the main process', () => { if (process.platform === 'darwin') { crashReporter.start({ companyName: 'Umbrella Corporation', @@ -279,9 +264,9 @@ const waitForCrashReport = () => { } const startServer = ({callback, processType, done}) => { - var called = false - var server = http.createServer((req, res) => { - var form = new multiparty.Form() + let called = false + let server = http.createServer((req, res) => { + const form = new multiparty.Form() form.parse(req, (error, fields) => { if (error) throw error if (called) return @@ -335,7 +320,7 @@ const startServer = ({callback, processType, done}) => { for (const connection of activeConnections) { connection.destroy() } - server.close(function () { + server.close(() => { done() }) } From 83a290a411d4c31ffc22ccf47fa7449df85dd1f6 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Thu, 26 Oct 2017 20:32:04 -0400 Subject: [PATCH 03/13] update debugger spec --- spec/api-debugger-spec.js | 58 +++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 30 deletions(-) diff --git a/spec/api-debugger-spec.js b/spec/api-debugger-spec.js index 83b114f723..40d9feca27 100644 --- a/spec/api-debugger-spec.js +++ b/spec/api-debugger-spec.js @@ -4,11 +4,11 @@ const path = require('path') const {closeWindow} = require('./window-helpers') const BrowserWindow = require('electron').remote.BrowserWindow -describe('debugger module', function () { - var fixtures = path.resolve(__dirname, 'fixtures') - var w = null +describe.only('debugger module', () => { + const fixtures = path.resolve(__dirname, 'fixtures') + let w = null - beforeEach(function () { + beforeEach(() => { w = new BrowserWindow({ show: false, width: 400, @@ -16,13 +16,11 @@ describe('debugger module', function () { }) }) - afterEach(function () { - return closeWindow(w).then(function () { w = null }) - }) + afterEach(() => closeWindow(w).then(() => { w = null })) - describe('debugger.attach', function () { - it('fails when devtools is already open', function (done) { - w.webContents.on('did-finish-load', function () { + describe('debugger.attach', () => { + it('fails when devtools is already open', (done) => { + w.webContents.on('did-finish-load', () => { w.webContents.openDevTools() try { w.webContents.debugger.attach() @@ -31,10 +29,10 @@ describe('debugger module', function () { done() } }) - w.webContents.loadURL('file://' + path.join(fixtures, 'pages', 'a.html')) + w.webContents.loadURL(`file://${path.join(fixtures, 'pages', 'a.html')}`) }) - it('fails when protocol version is not supported', function (done) { + it('fails when protocol version is not supported', (done) => { try { w.webContents.debugger.attach('2.0') } catch (err) { @@ -43,20 +41,20 @@ describe('debugger module', function () { } }) - it('attaches when no protocol version is specified', function (done) { + it('attaches when no protocol version is specified', (done) => { try { w.webContents.debugger.attach() } catch (err) { - done('unexpected error : ' + err) + done(`unexpected error : ${err}`) } assert(w.webContents.debugger.isAttached()) done() }) }) - describe('debugger.detach', function () { - it('fires detach event', function (done) { - w.webContents.debugger.on('detach', function (e, reason) { + describe('debugger.detach', () => { + it('fires detach event', (done) => { + w.webContents.debugger.on('detach', (e, reason) => { assert.equal(reason, 'target closed') assert(!w.webContents.debugger.isAttached()) done() @@ -64,23 +62,23 @@ describe('debugger module', function () { try { w.webContents.debugger.attach() } catch (err) { - done('unexpected error : ' + err) + done(`unexpected error : ${err}`) } w.webContents.debugger.detach() }) }) - describe('debugger.sendCommand', function () { + describe('debugger.sendCommand', () => { let server - afterEach(function () { + afterEach(() => { if (server != null) { server.close() server = null } }) - it('retuns response', function (done) { + it('retuns response', (done) => { w.webContents.loadURL('about:blank') try { w.webContents.debugger.attach() @@ -100,9 +98,9 @@ describe('debugger module', function () { w.webContents.debugger.sendCommand('Runtime.evaluate', params, callback) }) - it('fires message event', function (done) { - var url = process.platform !== 'win32' - ? 'file://' + path.join(fixtures, 'pages', 'a.html') + it('fires message event', (done) => { + const url = process.platform !== 'win32' + ? `file://${path.join(fixtures, 'pages', 'a.html')}` : 'file:///' + path.join(fixtures, 'pages', 'a.html').replace(/\\/g, '/') w.webContents.loadURL(url) try { @@ -110,7 +108,7 @@ describe('debugger module', function () { } catch (err) { done('unexpected error : ' + err) } - w.webContents.debugger.on('message', function (e, method, params) { + w.webContents.debugger.on('message', (e, method, params) => { if (method === 'Console.messageAdded') { assert.equal(params.message.level, 'log') assert.equal(params.message.url, url) @@ -122,25 +120,25 @@ describe('debugger module', function () { w.webContents.debugger.sendCommand('Console.enable') }) - it('returns error message when command fails', function (done) { + it('returns error message when command fails', (done) => { w.webContents.loadURL('about:blank') try { w.webContents.debugger.attach() } catch (err) { - done('unexpected error : ' + err) + done(`unexpected error : ${err}`) } - w.webContents.debugger.sendCommand('Test', function (err) { + w.webContents.debugger.sendCommand('Test', (err) => { assert.equal(err.message, "'Test' wasn't found") w.webContents.debugger.detach() done() }) }) - it('handles invalid unicode characters in message', function (done) { + it('handles invalid unicode characters in message', (done) => { try { w.webContents.debugger.attach() } catch (err) { - done('unexpected error : ' + err) + done(`unexpected error : ${err}`) } w.webContents.debugger.on('message', (event, method, params) => { From 6cd308f9ad7fb01086a305f4ea18678a14ea8507 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Thu, 26 Oct 2017 20:35:33 -0400 Subject: [PATCH 04/13] update deprecations spec --- spec/api-debugger-spec.js | 2 +- spec/api-deprecations-spec.js | 21 ++++++++++----------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/spec/api-debugger-spec.js b/spec/api-debugger-spec.js index 40d9feca27..5902a5b002 100644 --- a/spec/api-debugger-spec.js +++ b/spec/api-debugger-spec.js @@ -4,7 +4,7 @@ const path = require('path') const {closeWindow} = require('./window-helpers') const BrowserWindow = require('electron').remote.BrowserWindow -describe.only('debugger module', () => { +describe('debugger module', () => { const fixtures = path.resolve(__dirname, 'fixtures') let w = null diff --git a/spec/api-deprecations-spec.js b/spec/api-deprecations-spec.js index 5b618ac901..00815b284c 100644 --- a/spec/api-deprecations-spec.js +++ b/spec/api-deprecations-spec.js @@ -1,27 +1,26 @@ const assert = require('assert') -const deprecations = require('electron').deprecations +const {deprecations, deprecate} = require('electron') -describe('deprecations', function () { - beforeEach(function () { +describe('deprecations', () => { + beforeEach(() => { deprecations.setHandler(null) process.throwDeprecation = true }) - it('allows a deprecation handler function to be specified', function () { - var messages = [] + it('allows a deprecation handler function to be specified', () => { + const messages = [] - deprecations.setHandler(function (message) { + deprecations.setHandler((message) => { messages.push(message) }) - require('electron').deprecate.log('this is deprecated') - + deprecate.log('this is deprecated') assert.deepEqual(messages, ['this is deprecated']) }) - it('throws an exception if no deprecation handler is specified', function () { - assert.throws(function () { - require('electron').deprecate.log('this is deprecated') + it('throws an exception if no deprecation handler is specified', () => { + assert.throws(() => { + deprecate.log('this is deprecated') }, /this is deprecated/) }) }) From 6feff1d6e8d91e3b5cb66d6c7531893cbbbbe8c4 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Thu, 26 Oct 2017 20:44:06 -0400 Subject: [PATCH 05/13] update desktop capturer spec --- spec/api-desktop-capturer-spec.js | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/spec/api-desktop-capturer-spec.js b/spec/api-desktop-capturer-spec.js index 3dce618de0..ae4af2375e 100644 --- a/spec/api-desktop-capturer-spec.js +++ b/spec/api-desktop-capturer-spec.js @@ -1,33 +1,31 @@ const assert = require('assert') -const desktopCapturer = require('electron').desktopCapturer +const {desktopCapturer, remote} = require('electron') -const isCI = require('electron').remote.getGlobal('isCi') +const isCI = remote.getGlobal('isCi') -describe('desktopCapturer', function () { - if (isCI && process.platform === 'win32') { - return - } +describe('desktopCapturer', () => { + if (isCI && process.platform === 'win32') return - it('should return a non-empty array of sources', function (done) { + it('should return a non-empty array of sources', (done) => { desktopCapturer.getSources({ types: ['window', 'screen'] - }, function (error, sources) { + }, (error, sources) => { assert.equal(error, null) assert.notEqual(sources.length, 0) done() }) }) - it('throws an error for invalid options', function (done) { - desktopCapturer.getSources(['window', 'screen'], function (error) { + it('throws an error for invalid options', (done) => { + desktopCapturer.getSources(['window', 'screen'], (error) => { assert.equal(error.message, 'Invalid options') done() }) }) - it('does not throw an error when called more than once (regression)', function (done) { - var callCount = 0 - var callback = function (error, sources) { + it('does not throw an error when called more than once (regression)', (done) => { + let callCount = 0 + const callback = (error, sources) => { callCount++ assert.equal(error, null) assert.notEqual(sources.length, 0) @@ -38,9 +36,9 @@ describe('desktopCapturer', function () { desktopCapturer.getSources({types: ['window', 'screen']}, callback) }) - it('responds to subsequest calls of different options', function (done) { - var callCount = 0 - var callback = function (error, sources) { + it('responds to subsequest calls of different options', (done) => { + let callCount = 0 + const callback = (error, sources) => { callCount++ assert.equal(error, null) if (callCount === 2) done() From 13fc080213db58aa1bb6c014cd008303d6939bf4 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Thu, 26 Oct 2017 20:49:21 -0400 Subject: [PATCH 06/13] small tweaks to global shortcut spec --- spec/api-global-shortcut-spec.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/spec/api-global-shortcut-spec.js b/spec/api-global-shortcut-spec.js index 2031d4556f..3d200d6ad8 100644 --- a/spec/api-global-shortcut-spec.js +++ b/spec/api-global-shortcut-spec.js @@ -1,12 +1,10 @@ -const {globalShortcut} = require('electron').remote +const {globalShortcut, remote} = require('electron') const assert = require('assert') -const isCI = require('electron').remote.getGlobal('isCi') +const isCI = remote.getGlobal('isCi') describe('globalShortcut module', () => { - if (isCI && process.platform === 'win32') { - return - } + if (isCI && process.platform === 'win32') return beforeEach(() => { globalShortcut.unregisterAll() From e64e9995b69e2b98923b0e217b1418ffe825bff0 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Thu, 26 Oct 2017 20:53:47 -0400 Subject: [PATCH 07/13] small tweak to process spec --- spec/api-process-spec.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/spec/api-process-spec.js b/spec/api-process-spec.js index 5f4ad1730b..954b75eeb2 100644 --- a/spec/api-process-spec.js +++ b/spec/api-process-spec.js @@ -1,19 +1,18 @@ const assert = require('assert') -describe('process module', function () { - describe('process.getCPUUsage()', function () { - it('returns a cpu usage object', function () { +describe('process module', () => { + describe('process.getCPUUsage()', () => { + it('returns a cpu usage object', () => { const cpuUsage = process.getCPUUsage() assert.equal(typeof cpuUsage.percentCPUUsage, 'number') assert.equal(typeof cpuUsage.idleWakeupsPerSecond, 'number') }) }) - describe('process.getIOCounters()', function () { - it('returns an io counters object', function () { - if (process.platform === 'darwin') { - return - } + describe('process.getIOCounters()', () => { + it('returns an io counters object', () => { + if (process.platform === 'darwin') return + const ioCounters = process.getIOCounters() assert.equal(typeof ioCounters.readOperationCount, 'number') assert.equal(typeof ioCounters.writeOperationCount, 'number') From d8f2183b3d6c5cff8e7c9a99793b8eb4b95c8864 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Thu, 26 Oct 2017 20:55:07 -0400 Subject: [PATCH 08/13] upgrade screen spec --- spec/api-screen-spec.js | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/spec/api-screen-spec.js b/spec/api-screen-spec.js index 93d048acf4..b69a836ec3 100644 --- a/spec/api-screen-spec.js +++ b/spec/api-screen-spec.js @@ -1,31 +1,29 @@ const assert = require('assert') -const screen = require('electron').screen +const {screen} = require('electron') -describe('screen module', function () { - describe('screen.getCursorScreenPoint()', function () { - it('returns a point object', function () { - var point = screen.getCursorScreenPoint() +describe('screen module', () => { + describe('screen.getCursorScreenPoint()', () => { + it('returns a point object', () => { + const point = screen.getCursorScreenPoint() assert.equal(typeof point.x, 'number') assert.equal(typeof point.y, 'number') }) }) - describe('screen.getPrimaryDisplay()', function () { - it('returns a display object', function () { - var display = screen.getPrimaryDisplay() + describe('screen.getPrimaryDisplay()', () => { + it('returns a display object', () => { + const display = screen.getPrimaryDisplay() assert.equal(typeof display.scaleFactor, 'number') assert(display.size.width > 0) assert(display.size.height > 0) }) }) - describe('screen.getMenuBarHeight()', function () { - if (process.platform !== 'darwin') { - return - } + describe('screen.getMenuBarHeight()', () => { + if (process.platform !== 'darwin') return - it('returns an integer', function () { - var screenHeight = screen.getMenuBarHeight() + it('returns an integer', () => { + const screenHeight = screen.getMenuBarHeight() assert.equal(typeof screenHeight, 'number') }) }) From 1130ccf69b48ec6a57e66cde4a9a6dfd24b73f8a Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Thu, 26 Oct 2017 20:58:48 -0400 Subject: [PATCH 09/13] upgrade system pref spec --- spec/api-system-preferences-spec.js | 41 +++++++++++------------------ 1 file changed, 16 insertions(+), 25 deletions(-) diff --git a/spec/api-system-preferences-spec.js b/spec/api-system-preferences-spec.js index afcb5d1f9e..020d6ad5c0 100644 --- a/spec/api-system-preferences-spec.js +++ b/spec/api-system-preferences-spec.js @@ -2,41 +2,37 @@ const assert = require('assert') const {remote} = require('electron') const {systemPreferences} = remote -describe('systemPreferences module', function () { - describe('systemPreferences.getAccentColor', function () { - if (process.platform !== 'win32') { - return - } +describe('systemPreferences module', () => { + describe('systemPreferences.getAccentColor', () => { + if (process.platform !== 'win32') return - it('should return a non-empty string', function () { + it('should return a non-empty string', () => { let accentColor = systemPreferences.getAccentColor() assert.notEqual(accentColor, null) assert(accentColor.length > 0) }) }) - describe('systemPreferences.getColor(id)', function () { - if (process.platform !== 'win32') { - return - } + describe('systemPreferences.getColor(id)', () => { + if (process.platform !== 'win32') return - it('throws an error when the id is invalid', function () { - assert.throws(function () { + it('throws an error when the id is invalid', () => { + assert.throws(() => { systemPreferences.getColor('not-a-color') }, /Unknown color: not-a-color/) }) - it('returns a hex RGB color string', function () { + it('returns a hex RGB color string', () => { assert.equal(/^#[0-9A-F]{6}$/i.test(systemPreferences.getColor('window')), true) }) }) - describe('systemPreferences.getUserDefault(key, type)', function () { + describe('systemPreferences.getUserDefault(key, type)', () => { if (process.platform !== 'darwin') { return } - it('returns values for known user defaults', function () { + it('returns values for known user defaults', () => { const locale = systemPreferences.getUserDefault('AppleLocale', 'string') assert.equal(typeof locale, 'string') assert(locale.length > 0) @@ -46,7 +42,7 @@ describe('systemPreferences module', function () { assert(languages.length > 0) }) - it('returns values for unknown user defaults', function () { + it('returns values for unknown user defaults', () => { assert.equal(systemPreferences.getUserDefault('UserDefaultDoesNotExist', 'boolean'), false) assert.equal(systemPreferences.getUserDefault('UserDefaultDoesNotExist', 'integer'), 0) assert.equal(systemPreferences.getUserDefault('UserDefaultDoesNotExist', 'float'), 0) @@ -60,12 +56,9 @@ describe('systemPreferences module', function () { }) describe('systemPreferences.setUserDefault(key, type, value)', () => { - if (process.platform !== 'darwin') { - return - } + if (process.platform !== 'darwin') return const KEY = 'SystemPreferencesTest' - const TEST_CASES = [ ['string', 'abc'], ['boolean', true], @@ -101,9 +94,7 @@ describe('systemPreferences module', function () { }) describe('systemPreferences.setUserDefault(key, type, value)', () => { - if (process.platform !== 'darwin') { - return - } + if (process.platform !== 'darwin') return it('removes keys', () => { const KEY = 'SystemPreferencesTest' @@ -117,8 +108,8 @@ describe('systemPreferences module', function () { }) }) - describe('systemPreferences.isInvertedColorScheme()', function () { - it('returns a boolean', function () { + describe('systemPreferences.isInvertedColorScheme()', () => { + it('returns a boolean', () => { assert.equal(typeof systemPreferences.isInvertedColorScheme(), 'boolean') }) }) From 0317189213d24cd663732d2ea5f683b7be1896ff Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Thu, 26 Oct 2017 21:08:47 -0400 Subject: [PATCH 10/13] update touch bar spec --- spec/api-touch-bar-spec.js | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/spec/api-touch-bar-spec.js b/spec/api-touch-bar-spec.js index 6177e3cb85..18dd414f68 100644 --- a/spec/api-touch-bar-spec.js +++ b/spec/api-touch-bar-spec.js @@ -6,22 +6,22 @@ const {closeWindow} = require('./window-helpers') const {TouchBarButton, TouchBarColorPicker, TouchBarGroup} = TouchBar const {TouchBarLabel, TouchBarPopover, TouchBarScrubber, TouchBarSegmentedControl, TouchBarSlider, TouchBarSpacer} = TouchBar -describe('TouchBar module', function () { - it('throws an error when created without an options object', function () { +describe('TouchBar module', () => { + it('throws an error when created without an options object', () => { assert.throws(() => { const touchBar = new TouchBar() touchBar.toString() }, /Must specify options object as first argument/) }) - it('throws an error when created with invalid items', function () { + it('throws an error when created with invalid items', () => { assert.throws(() => { const touchBar = new TouchBar({items: [1, true, {}, []]}) touchBar.toString() }, /Each item must be an instance of TouchBarItem/) }) - it('throws an error when an invalid escape item is set', function () { + it('throws an error when an invalid escape item is set', () => { assert.throws(() => { const touchBar = new TouchBar({items: [], escapeItem: 'esc'}) touchBar.toString() @@ -33,19 +33,19 @@ describe('TouchBar module', function () { }, /Escape item must be an instance of TouchBarItem/) }) - describe('BrowserWindow behavior', function () { + describe('BrowserWindow behavior', () => { let window - beforeEach(function () { + beforeEach(() => { window = new BrowserWindow() }) - afterEach(function () { + afterEach(() => { window.setTouchBar(null) - return closeWindow(window).then(function () { window = null }) + return closeWindow(window).then(() => { window = null }) }) - it('can be added to and removed from a window', function () { + it('can be added to and removed from a window', () => { const label = new TouchBarLabel({label: 'bar'}) const touchBar = new TouchBar([ new TouchBarButton({label: 'foo', backgroundColor: '#F00', click: () => {}}), @@ -73,9 +73,7 @@ describe('TouchBar module', function () { showArrowButtons: true }) ]) - const escapeButton = new TouchBarButton({ - label: 'foo' - }) + const escapeButton = new TouchBarButton({label: 'foo'}) window.setTouchBar(touchBar) touchBar.escapeItem = escapeButton label.label = 'baz' @@ -85,7 +83,7 @@ describe('TouchBar module', function () { touchBar.escapeItem = null }) - it('calls the callback on the items when a window interaction event fires', function (done) { + it('calls the callback on the items when a window interaction event fires', (done) => { const button = new TouchBarButton({ label: 'bar', click: () => { @@ -97,7 +95,7 @@ describe('TouchBar module', function () { window.emit('-touch-bar-interaction', {}, button.id) }) - it('calls the callback on the escape item when a window interaction event fires', function (done) { + it('calls the callback on the escape item when a window interaction event fires', (done) => { const button = new TouchBarButton({ label: 'bar', click: () => { From abecde05724e5cbde413f14864659d6923988e75 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Thu, 26 Oct 2017 21:41:06 -0400 Subject: [PATCH 11/13] fix shortcut spec error --- spec/api-global-shortcut-spec.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/api-global-shortcut-spec.js b/spec/api-global-shortcut-spec.js index 3d200d6ad8..b89890903f 100644 --- a/spec/api-global-shortcut-spec.js +++ b/spec/api-global-shortcut-spec.js @@ -1,9 +1,9 @@ -const {globalShortcut, remote} = require('electron') +const {globalShortcut} = require('electron').remote + const assert = require('assert') +const isCI = require('electron').remote.getGlobal('isCi') -const isCI = remote.getGlobal('isCi') - -describe('globalShortcut module', () => { +describe.only('globalShortcut module', () => { if (isCI && process.platform === 'win32') return beforeEach(() => { From 7a3efd1543c63868ccf3cf9946045a31e5b47dc0 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Thu, 26 Oct 2017 21:41:29 -0400 Subject: [PATCH 12/13] stop leaving onlys there --- spec/api-global-shortcut-spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/api-global-shortcut-spec.js b/spec/api-global-shortcut-spec.js index b89890903f..d6204ace10 100644 --- a/spec/api-global-shortcut-spec.js +++ b/spec/api-global-shortcut-spec.js @@ -3,7 +3,7 @@ const {globalShortcut} = require('electron').remote const assert = require('assert') const isCI = require('electron').remote.getGlobal('isCi') -describe.only('globalShortcut module', () => { +describe('globalShortcut module', () => { if (isCI && process.platform === 'win32') return beforeEach(() => { From eed54a18c48928332466a455021aece4bffbc906 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Thu, 26 Oct 2017 22:09:38 -0400 Subject: [PATCH 13/13] fix comment typo --- spec/api-clipboard-spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/api-clipboard-spec.js b/spec/api-clipboard-spec.js index 2c50ef3821..e9a5c58fee 100644 --- a/spec/api-clipboard-spec.js +++ b/spec/api-clipboard-spec.js @@ -8,7 +8,7 @@ describe('clipboard module', () => { const fixtures = path.resolve(__dirname, 'fixtures') describe('clipboard.readImage()', () => { - it('returns NativeImage intance', () => { + it('returns NativeImage instance', () => { const p = path.join(fixtures, 'assets', 'logo.png') const i = nativeImage.createFromPath(p) clipboard.writeImage(p)