Browse Source

[WIP] Upgrade more specs (#10945)

Finish upgrading specs to ES6
Shelley Vohr 7 years ago
parent
commit
e4214a6cbe
11 changed files with 1429 additions and 1626 deletions
  1. 113 142
      spec/api-app-spec.js
  2. 115 117
      spec/api-ipc-spec.js
  3. 46 46
      spec/api-menu-spec.js
  4. 183 191
      spec/api-net-spec.js
  5. 183 223
      spec/api-session-spec.js
  6. 61 67
      spec/api-web-contents-spec.js
  7. 121 180
      spec/api-web-request-spec.js
  8. 232 266
      spec/chromium-spec.js
  9. 35 37
      spec/modules-spec.js
  10. 102 110
      spec/node-spec.js
  11. 238 247
      spec/webview-spec.js

+ 113 - 142
spec/api-app-spec.js

@@ -11,17 +11,17 @@ const {app, BrowserWindow, ipcMain} = remote
 
 const isCI = remote.getGlobal('isCi')
 
-describe('electron module', function () {
-  it('does not expose internal modules to require', function () {
-    assert.throws(function () {
+describe('electron module', () => {
+  it('does not expose internal modules to require', () => {
+    assert.throws(() => {
       require('clipboard')
     }, /Cannot find module 'clipboard'/)
   })
 
-  describe('require("electron")', function () {
+  describe('require("electron")', () => {
     let window = null
 
-    beforeEach(function () {
+    beforeEach(() => {
       window = new BrowserWindow({
         show: false,
         width: 400,
@@ -29,24 +29,22 @@ describe('electron module', function () {
       })
     })
 
-    afterEach(function () {
-      return closeWindow(window).then(function () { window = null })
+    afterEach(() => {
+      return closeWindow(window).then(() => { window = null })
     })
 
-    it('always returns the internal electron module', function (done) {
-      ipcMain.once('answer', function () {
-        done()
-      })
-      window.loadURL('file://' + path.join(__dirname, 'fixtures', 'api', 'electron-module-app', 'index.html'))
+    it('always returns the internal electron module', (done) => {
+      ipcMain.once('answer', () => done())
+      window.loadURL(`file://${path.join(__dirname, 'fixtures', 'api', 'electron-module-app', 'index.html')}`)
     })
   })
 })
 
-describe('app module', function () {
+describe('app module', () => {
   let server, secureUrl
   const certPath = path.join(__dirname, 'fixtures', 'certificates')
 
-  before(function () {
+  before(() => {
     const options = {
       key: fs.readFileSync(path.join(certPath, 'server.key')),
       cert: fs.readFileSync(path.join(certPath, 'server.pem')),
@@ -58,7 +56,7 @@ describe('app module', function () {
       rejectUnauthorized: false
     }
 
-    server = https.createServer(options, function (req, res) {
+    server = https.createServer(options, (req, res) => {
       if (req.client.authorized) {
         res.writeHead(200)
         res.end('<title>authorized</title>')
@@ -68,24 +66,24 @@ describe('app module', function () {
       }
     })
 
-    server.listen(0, '127.0.0.1', function () {
+    server.listen(0, '127.0.0.1', () => {
       const port = server.address().port
       secureUrl = `https://127.0.0.1:${port}`
     })
   })
 
-  after(function () {
+  after(() => {
     server.close()
   })
 
-  describe('app.getVersion()', function () {
-    it('returns the version field of package.json', function () {
+  describe('app.getVersion()', () => {
+    it('returns the version field of package.json', () => {
       assert.equal(app.getVersion(), '0.1.0')
     })
   })
 
-  describe('app.setVersion(version)', function () {
-    it('overrides the version', function () {
+  describe('app.setVersion(version)', () => {
+    it('overrides the version', () => {
       assert.equal(app.getVersion(), '0.1.0')
       app.setVersion('test-version')
       assert.equal(app.getVersion(), 'test-version')
@@ -93,14 +91,14 @@ describe('app module', function () {
     })
   })
 
-  describe('app.getName()', function () {
-    it('returns the name field of package.json', function () {
+  describe('app.getName()', () => {
+    it('returns the name field of package.json', () => {
       assert.equal(app.getName(), 'Electron Test')
     })
   })
 
-  describe('app.setName(name)', function () {
-    it('overrides the name', function () {
+  describe('app.setName(name)', () => {
+    it('overrides the name', () => {
       assert.equal(app.getName(), 'Electron Test')
       app.setName('test-name')
       assert.equal(app.getName(), 'test-name')
@@ -108,36 +106,35 @@ describe('app module', function () {
     })
   })
 
-  describe('app.getLocale()', function () {
-    it('should not be empty', function () {
+  describe('app.getLocale()', () => {
+    it('should not be empty', () => {
       assert.notEqual(app.getLocale(), '')
     })
   })
 
-  describe('app.isInApplicationsFolder()', function () {
-    it('should be false during tests', function () {
+  describe('app.isInApplicationsFolder()', () => {
+    it('should be false during tests', () => {
       if (process.platform !== 'darwin') return
-
       assert.equal(app.isInApplicationsFolder(), false)
     })
   })
 
-  describe('app.exit(exitCode)', function () {
-    var appProcess = null
+  describe('app.exit(exitCode)', () => {
+    let appProcess = null
 
-    afterEach(function () {
+    afterEach(() => {
       if (appProcess != null) appProcess.kill()
     })
 
-    it('emits a process exit event with the code', function (done) {
-      var appPath = path.join(__dirname, 'fixtures', 'api', 'quit-app')
-      var electronPath = remote.getGlobal('process').execPath
-      var output = ''
+    it('emits a process exit event with the code', (done) => {
+      const appPath = path.join(__dirname, 'fixtures', 'api', 'quit-app')
+      const electronPath = remote.getGlobal('process').execPath
+      let output = ''
       appProcess = ChildProcess.spawn(electronPath, [appPath])
-      appProcess.stdout.on('data', function (data) {
+      appProcess.stdout.on('data', (data) => {
         output += data
       })
-      appProcess.on('close', function (code) {
+      appProcess.on('close', (code) => {
         if (process.platform !== 'win32') {
           assert.notEqual(output.indexOf('Exit event with code: 123'), -1)
         }
@@ -146,7 +143,7 @@ describe('app module', function () {
       })
     })
 
-    it('closes all windows', function (done) {
+    it('closes all windows', (done) => {
       var appPath = path.join(__dirname, 'fixtures', 'api', 'exit-closes-all-windows-app')
       var electronPath = remote.getGlobal('process').execPath
       appProcess = ChildProcess.spawn(electronPath, [appPath])
@@ -157,7 +154,7 @@ describe('app module', function () {
     })
   })
 
-  describe('app.makeSingleInstance', function () {
+  describe('app.makeSingleInstance', () => {
     it('prevents the second launch of app', function (done) {
       this.timeout(120000)
       const appPath = path.join(__dirname, 'fixtures', 'api', 'singleton')
@@ -178,11 +175,11 @@ describe('app module', function () {
     })
   })
 
-  describe('app.relaunch', function () {
+  describe('app.relaunch', () => {
     let server = null
     const socketPath = process.platform === 'win32' ? '\\\\.\\pipe\\electron-app-relaunch' : '/tmp/electron-app-relaunch'
 
-    beforeEach(function (done) {
+    beforeEach((done) => {
       fs.unlink(socketPath, () => {
         server = net.createServer()
         server.listen(socketPath)
@@ -190,14 +187,12 @@ describe('app module', function () {
       })
     })
 
-    afterEach(function (done) {
+    afterEach((done) => {
       server.close(() => {
         if (process.platform === 'win32') {
           done()
         } else {
-          fs.unlink(socketPath, () => {
-            done()
-          })
+          fs.unlink(socketPath, () => done())
         }
       })
     })
@@ -206,11 +201,9 @@ describe('app module', function () {
       this.timeout(120000)
 
       let state = 'none'
-      server.once('error', (error) => {
-        done(error)
-      })
+      server.once('error', (error) => done(error))
       server.on('connection', (client) => {
-        client.once('data', function (data) {
+        client.once('data', (data) => {
           if (String(data) === 'false' && state === 'none') {
             state = 'first-launch'
           } else if (String(data) === 'true' && state === 'first-launch') {
@@ -226,42 +219,36 @@ describe('app module', function () {
     })
   })
 
-  describe('app.setUserActivity(type, userInfo)', function () {
-    if (process.platform !== 'darwin') {
-      return
-    }
+  describe('app.setUserActivity(type, userInfo)', () => {
+    if (process.platform !== 'darwin') return
 
-    it('sets the current activity', function () {
+    it('sets the current activity', () => {
       app.setUserActivity('com.electron.testActivity', {testData: '123'})
       assert.equal(app.getCurrentActivityType(), 'com.electron.testActivity')
     })
   })
 
-  xdescribe('app.importCertificate', function () {
+  xdescribe('app.importCertificate', () => {
     if (process.platform !== 'linux') return
 
     var w = null
 
-    afterEach(function () {
-      return closeWindow(w).then(function () { w = null })
-    })
+    afterEach(() => closeWindow(w).then(() => { w = null }))
 
-    it('can import certificate into platform cert store', function (done) {
+    it('can import certificate into platform cert store', (done) => {
       let options = {
         certificate: path.join(certPath, 'client.p12'),
         password: 'electron'
       }
 
-      w = new BrowserWindow({
-        show: false
-      })
+      w = new BrowserWindow({ show: false })
 
-      w.webContents.on('did-finish-load', function () {
+      w.webContents.on('did-finish-load', () => {
         assert.equal(w.webContents.getTitle(), 'authorized')
         done()
       })
 
-      ipcRenderer.once('select-client-certificate', function (event, webContentsId, list) {
+      ipcRenderer.once('select-client-certificate', (event, webContentsId, list) => {
         assert.equal(webContentsId, w.webContents.id)
         assert.equal(list.length, 1)
         assert.equal(list[0].issuerName, 'Intermediate CA')
@@ -271,7 +258,7 @@ describe('app module', function () {
         event.sender.send('client-certificate-response', list[0])
       })
 
-      app.importCertificate(options, function (result) {
+      app.importCertificate(options, (result) => {
         assert(!result)
         ipcRenderer.sendSync('set-client-certificate-option', false)
         w.loadURL(secureUrl)
@@ -279,79 +266,69 @@ describe('app module', function () {
     })
   })
 
-  describe('BrowserWindow events', function () {
-    var w = null
+  describe('BrowserWindow events', () => {
+    let w = null
 
-    afterEach(function () {
-      return closeWindow(w).then(function () { w = null })
-    })
+    afterEach(() => closeWindow(w).then(() => { w = null }))
 
-    it('should emit browser-window-focus event when window is focused', function (done) {
-      app.once('browser-window-focus', function (e, window) {
+    it('should emit browser-window-focus event when window is focused', (done) => {
+      app.once('browser-window-focus', (e, window) => {
         assert.equal(w.id, window.id)
         done()
       })
-      w = new BrowserWindow({
-        show: false
-      })
+      w = new BrowserWindow({ show: false })
       w.emit('focus')
     })
 
-    it('should emit browser-window-blur event when window is blured', function (done) {
-      app.once('browser-window-blur', function (e, window) {
+    it('should emit browser-window-blur event when window is blured', (done) => {
+      app.once('browser-window-blur', (e, window) => {
         assert.equal(w.id, window.id)
         done()
       })
-      w = new BrowserWindow({
-        show: false
-      })
+      w = new BrowserWindow({ show: false })
       w.emit('blur')
     })
 
-    it('should emit browser-window-created event when window is created', function (done) {
-      app.once('browser-window-created', function (e, window) {
-        setImmediate(function () {
+    it('should emit browser-window-created event when window is created', (done) => {
+      app.once('browser-window-created', (e, window) => {
+        setImmediate(() => {
           assert.equal(w.id, window.id)
           done()
         })
       })
-      w = new BrowserWindow({
-        show: false
-      })
+      w = new BrowserWindow({ show: false })
     })
 
-    it('should emit web-contents-created event when a webContents is created', function (done) {
-      app.once('web-contents-created', function (e, webContents) {
-        setImmediate(function () {
+    it('should emit web-contents-created event when a webContents is created', (done) => {
+      app.once('web-contents-created', (e, webContents) => {
+        setImmediate(() => {
           assert.equal(w.webContents.id, webContents.id)
           done()
         })
       })
-      w = new BrowserWindow({
-        show: false
-      })
+      w = new BrowserWindow({ show: false })
     })
   })
 
-  describe('app.setBadgeCount API', function () {
+  describe('app.setBadgeCount API', () => {
     const shouldFail = process.platform === 'win32' ||
                        (process.platform === 'linux' && !app.isUnityRunning())
 
-    afterEach(function () {
+    afterEach(() => {
       app.setBadgeCount(0)
     })
 
-    it('returns false when failed', function () {
+    it('returns false when failed', () => {
       assert.equal(app.setBadgeCount(42), !shouldFail)
     })
 
-    it('should set a badge count', function () {
+    it('should set a badge count', () => {
       app.setBadgeCount(42)
       assert.equal(app.getBadgeCount(), shouldFail ? 0 : 42)
     })
   })
 
-  describe('app.get/setLoginItemSettings API', function () {
+  describe('app.get/setLoginItemSettings API', () => {
     if (process.platform === 'linux') return
 
     const updateExe = path.resolve(path.dirname(process.execPath), '..', 'Update.exe')
@@ -360,17 +337,17 @@ describe('app module', function () {
       '--process-start-args', `"--hidden"`
     ]
 
-    beforeEach(function () {
+    beforeEach(() => {
       app.setLoginItemSettings({openAtLogin: false})
       app.setLoginItemSettings({openAtLogin: false, path: updateExe, args: processStartArgs})
     })
 
-    afterEach(function () {
+    afterEach(() => {
       app.setLoginItemSettings({openAtLogin: false})
       app.setLoginItemSettings({openAtLogin: false, path: updateExe, args: processStartArgs})
     })
 
-    it('returns the login item status of the app', function () {
+    it('returns the login item status of the app', () => {
       app.setLoginItemSettings({openAtLogin: true})
       assert.deepEqual(app.getLoginItemSettings(), {
         openAtLogin: true,
@@ -409,35 +386,35 @@ describe('app module', function () {
     })
   })
 
-  describe('isAccessibilitySupportEnabled API', function () {
-    it('returns whether the Chrome has accessibility APIs enabled', function () {
+  describe('isAccessibilitySupportEnabled API', () => {
+    it('returns whether the Chrome has accessibility APIs enabled', () => {
       assert.equal(typeof app.isAccessibilitySupportEnabled(), 'boolean')
     })
   })
 
-  describe('getPath(name)', function () {
-    it('returns paths that exist', function () {
+  describe('getPath(name)', () => {
+    it('returns paths that exist', () => {
       assert.equal(fs.existsSync(app.getPath('exe')), true)
       assert.equal(fs.existsSync(app.getPath('home')), true)
       assert.equal(fs.existsSync(app.getPath('temp')), true)
     })
 
-    it('throws an error when the name is invalid', function () {
-      assert.throws(function () {
+    it('throws an error when the name is invalid', () => {
+      assert.throws(() => {
         app.getPath('does-not-exist')
       }, /Failed to get 'does-not-exist' path/)
     })
 
-    it('returns the overridden path', function () {
+    it('returns the overridden path', () => {
       app.setPath('music', __dirname)
       assert.equal(app.getPath('music'), __dirname)
     })
   })
 
-  xdescribe('select-client-certificate event', function () {
+  xdescribe('select-client-certificate event', () => {
     let w = null
 
-    beforeEach(function () {
+    beforeEach(() => {
       w = new BrowserWindow({
         show: false,
         webPreferences: {
@@ -446,12 +423,10 @@ describe('app module', function () {
       })
     })
 
-    afterEach(function () {
-      return closeWindow(w).then(function () { w = null })
-    })
+    afterEach(() => closeWindow(w).then(() => { w = null }))
 
-    it('can respond with empty certificate list', function (done) {
-      w.webContents.on('did-finish-load', function () {
+    it('can respond with empty certificate list', (done) => {
+      w.webContents.on('did-finish-load', () => {
         assert.equal(w.webContents.getTitle(), 'denied')
         server.close()
         done()
@@ -498,7 +473,7 @@ describe('app module', function () {
     })
   })
 
-  describe('getFileIcon() API', function () {
+  describe('getFileIcon() API', () => {
     // FIXME Get these specs running on Linux CI
     if (process.platform === 'linux' && isCI) return
 
@@ -509,16 +484,16 @@ describe('app module', function () {
       large: process.platform === 'win32' ? 32 : 48
     }
 
-    it('fetches a non-empty icon', function (done) {
-      app.getFileIcon(iconPath, function (err, icon) {
+    it('fetches a non-empty icon', (done) => {
+      app.getFileIcon(iconPath, (err, icon) => {
         assert.equal(err, null)
         assert.equal(icon.isEmpty(), false)
         done()
       })
     })
 
-    it('fetches normal icon size by default', function (done) {
-      app.getFileIcon(iconPath, function (err, icon) {
+    it('fetches normal icon size by default', (done) => {
+      app.getFileIcon(iconPath, (err, icon) => {
         const size = icon.getSize()
         assert.equal(err, null)
         assert.equal(size.height, sizes.normal)
@@ -527,9 +502,9 @@ describe('app module', function () {
       })
     })
 
-    describe('size option', function () {
-      it('fetches a small icon', function (done) {
-        app.getFileIcon(iconPath, { size: 'small' }, function (err, icon) {
+    describe('size option', () => {
+      it('fetches a small icon', (done) => {
+        app.getFileIcon(iconPath, { size: 'small' }, (err, icon) => {
           const size = icon.getSize()
           assert.equal(err, null)
           assert.equal(size.height, sizes.small)
@@ -538,7 +513,7 @@ describe('app module', function () {
         })
       })
 
-      it('fetches a normal icon', function (done) {
+      it('fetches a normal icon', (done) => {
         app.getFileIcon(iconPath, { size: 'normal' }, function (err, icon) {
           const size = icon.getSize()
           assert.equal(err, null)
@@ -548,7 +523,7 @@ describe('app module', function () {
         })
       })
 
-      it('fetches a large icon', function (done) {
+      it('fetches a large icon', (done) => {
         // macOS does not support large icons
         if (process.platform === 'darwin') return done()
 
@@ -563,8 +538,8 @@ describe('app module', function () {
     })
   })
 
-  describe('getAppMetrics() API', function () {
-    it('returns memory and cpu stats of all running electron processes', function () {
+  describe('getAppMetrics() API', () => {
+    it('returns memory and cpu stats of all running electron processes', () => {
       const appMetrics = app.getAppMetrics()
       assert.ok(appMetrics.length > 0, 'App memory info object is not > 0')
       const types = []
@@ -588,15 +563,15 @@ describe('app module', function () {
     })
   })
 
-  describe('getGPUFeatureStatus() API', function () {
-    it('returns the graphic features statuses', function () {
+  describe('getGPUFeatureStatus() API', () => {
+    it('returns the graphic features statuses', () => {
       const features = app.getGPUFeatureStatus()
       assert.equal(typeof features.webgl, 'string')
       assert.equal(typeof features.gpu_compositing, 'string')
     })
   })
 
-  describe('mixed sandbox option', function () {
+  describe('mixed sandbox option', () => {
     // FIXME Get these specs running on Linux
     if (process.platform === 'linux') return
 
@@ -604,7 +579,7 @@ describe('app module', function () {
     let server = null
     const socketPath = process.platform === 'win32' ? '\\\\.\\pipe\\electron-mixed-sandbox' : '/tmp/electron-mixed-sandbox'
 
-    beforeEach(function (done) {
+    beforeEach((done) => {
       fs.unlink(socketPath, () => {
         server = net.createServer()
         server.listen(socketPath)
@@ -612,18 +587,14 @@ describe('app module', function () {
       })
     })
 
-    afterEach(function (done) {
-      if (appProcess != null) {
-        appProcess.kill()
-      }
+    afterEach((done) => {
+      if (appProcess != null) appProcess.kill()
 
       server.close(() => {
         if (process.platform === 'win32') {
           done()
         } else {
-          fs.unlink(socketPath, () => {
-            done()
-          })
+          fs.unlink(socketPath, () => done())
         }
       })
     })
@@ -680,9 +651,9 @@ describe('app module', function () {
     })
   })
 
-  describe('disableDomainBlockingFor3DAPIs() API', function () {
-    it('throws when called after app is ready', function () {
-      assert.throws(function () {
+  describe('disableDomainBlockingFor3DAPIs() API', () => {
+    it('throws when called after app is ready', () => {
+      assert.throws(() => {
         app.disableDomainBlockingFor3DAPIs()
       }, /before app is ready/)
     })

+ 115 - 117
spec/api-ipc-spec.js

@@ -8,7 +8,7 @@ const {closeWindow} = require('./window-helpers')
 const {ipcRenderer, remote} = require('electron')
 const {ipcMain, webContents, BrowserWindow} = remote
 
-const comparePaths = function (path1, path2) {
+const comparePaths = (path1, path2) => {
   if (process.platform === 'win32') {
     path1 = path1.toLowerCase()
     path2 = path2.toLowerCase()
@@ -16,29 +16,27 @@ const comparePaths = function (path1, path2) {
   assert.equal(path1, path2)
 }
 
-describe('ipc module', function () {
-  var fixtures = path.join(__dirname, 'fixtures')
+describe('ipc module', () => {
+  const fixtures = path.join(__dirname, 'fixtures')
 
-  var w = null
+  let w = null
 
-  afterEach(function () {
-    return closeWindow(w).then(function () { w = null })
-  })
+  afterEach(() => closeWindow(w).then(() => { w = null }))
 
-  describe('remote.require', function () {
-    it('should returns same object for the same module', function () {
-      var dialog1 = remote.require('electron')
-      var dialog2 = remote.require('electron')
+  describe('remote.require', () => {
+    it('should returns same object for the same module', () => {
+      const dialog1 = remote.require('electron')
+      const dialog2 = remote.require('electron')
       assert.equal(dialog1, dialog2)
     })
 
-    it('should work when object contains id property', function () {
-      var a = remote.require(path.join(fixtures, 'module', 'id.js'))
+    it('should work when object contains id property', () => {
+      const a = remote.require(path.join(fixtures, 'module', 'id.js'))
       assert.equal(a.id, 1127)
     })
 
-    it('should work when object has no prototype', function () {
-      var a = remote.require(path.join(fixtures, 'module', 'no-prototype.js'))
+    it('should work when object has no prototype', () => {
+      const a = remote.require(path.join(fixtures, 'module', 'no-prototype.js'))
       assert.equal(a.foo.constructor.name, '')
       assert.equal(a.foo.bar, 'baz')
       assert.equal(a.foo.baz, false)
@@ -48,13 +46,13 @@ describe('ipc module', function () {
       assert.equal(a.getConstructorName(new (class {})()), '')
     })
 
-    it('should search module from the user app', function () {
+    it('should search module from the user app', () => {
       comparePaths(path.normalize(remote.process.mainModule.filename), path.resolve(__dirname, 'static', 'main.js'))
       comparePaths(path.normalize(remote.process.mainModule.paths[0]), path.resolve(__dirname, 'static', 'node_modules'))
     })
 
-    it('should work with function properties', function () {
-      var a = remote.require(path.join(fixtures, 'module', 'export-function-with-properties.js'))
+    it('should work with function properties', () => {
+      let a = remote.require(path.join(fixtures, 'module', 'export-function-with-properties.js'))
       assert.equal(typeof a, 'function')
       assert.equal(a.bar, 'baz')
 
@@ -75,36 +73,36 @@ describe('ipc module', function () {
       assert.equal(a.bar.baz, undefined)
     })
 
-    it('should work with static class members', function () {
-      var a = remote.require(path.join(fixtures, 'module', 'remote-static.js'))
+    it('should work with static class members', () => {
+      const a = remote.require(path.join(fixtures, 'module', 'remote-static.js'))
       assert.equal(typeof a.Foo, 'function')
       assert.equal(a.Foo.foo(), 3)
       assert.equal(a.Foo.bar, 'baz')
 
-      var foo = new a.Foo()
+      const foo = new a.Foo()
       assert.equal(foo.baz(), 123)
     })
 
-    it('includes the length of functions specified as arguments', function () {
-      var a = remote.require(path.join(fixtures, 'module', 'function-with-args.js'))
-      assert.equal(a(function (a, b, c, d, f) {}), 5)
+    it('includes the length of functions specified as arguments', () => {
+      const a = remote.require(path.join(fixtures, 'module', 'function-with-args.js'))
+      assert.equal(a((a, b, c, d, f) => {}), 5)
       assert.equal(a((a) => {}), 1)
       assert.equal(a((...args) => {}), 0)
     })
 
-    it('handles circular references in arrays and objects', function () {
-      var a = remote.require(path.join(fixtures, 'module', 'circular.js'))
+    it('handles circular references in arrays and objects', () => {
+      const a = remote.require(path.join(fixtures, 'module', 'circular.js'))
 
-      var arrayA = ['foo']
-      var arrayB = [arrayA, 'bar']
+      let arrayA = ['foo']
+      const arrayB = [arrayA, 'bar']
       arrayA.push(arrayB)
       assert.deepEqual(a.returnArgs(arrayA, arrayB), [
         ['foo', [null, 'bar']],
         [['foo', null], 'bar']
       ])
 
-      var objectA = {foo: 'bar'}
-      var objectB = {baz: objectA}
+      let objectA = {foo: 'bar'}
+      const objectB = {baz: objectA}
       objectA.objectB = objectB
       assert.deepEqual(a.returnArgs(objectA, objectB), [
         {foo: 'bar', objectB: {baz: null}},
@@ -145,35 +143,35 @@ describe('ipc module', function () {
     })
   })
 
-  describe('remote.createFunctionWithReturnValue', function () {
-    it('should be called in browser synchronously', function () {
-      var buf = new Buffer('test')
-      var call = remote.require(path.join(fixtures, 'module', 'call.js'))
-      var result = call.call(remote.createFunctionWithReturnValue(buf))
+  describe('remote.createFunctionWithReturnValue', () => {
+    it('should be called in browser synchronously', () => {
+      const buf = new Buffer('test')
+      const call = remote.require(path.join(fixtures, 'module', 'call.js'))
+      const result = call.call(remote.createFunctionWithReturnValue(buf))
       assert.equal(result.constructor.name, 'Buffer')
     })
   })
 
-  describe('remote modules', function () {
-    it('includes browser process modules as properties', function () {
+  describe('remote modules', () => {
+    it('includes browser process modules as properties', () => {
       assert.equal(typeof remote.app.getPath, 'function')
       assert.equal(typeof remote.webContents.getFocusedWebContents, 'function')
       assert.equal(typeof remote.clipboard.readText, 'function')
       assert.equal(typeof remote.shell.openExternal, 'function')
     })
 
-    it('returns toString() of original function via toString()', function () {
+    it('returns toString() of original function via toString()', () => {
       const {readText} = remote.clipboard
       assert(readText.toString().startsWith('function'))
 
-      var {functionWithToStringProperty} = remote.require(path.join(fixtures, 'module', 'to-string-non-function.js'))
+      const {functionWithToStringProperty} = remote.require(path.join(fixtures, 'module', 'to-string-non-function.js'))
       assert.equal(functionWithToStringProperty.toString, 'hello')
     })
   })
 
-  describe('remote object in renderer', function () {
-    it('can change its properties', function () {
-      var property = remote.require(path.join(fixtures, 'module', 'property.js'))
+  describe('remote object in renderer', () => {
+    it('can change its properties', () => {
+      const property = remote.require(path.join(fixtures, 'module', 'property.js'))
       assert.equal(property.property, 1127)
 
       property.property = null
@@ -188,70 +186,70 @@ describe('ipc module', function () {
       assert.equal(property.getFunctionProperty(), 'bar-browser')
       property.func.property = 'foo'  // revert back
 
-      var property2 = remote.require(path.join(fixtures, 'module', 'property.js'))
+      const property2 = remote.require(path.join(fixtures, 'module', 'property.js'))
       assert.equal(property2.property, 1007)
       property.property = 1127
     })
 
-    it('rethrows errors getting/setting properties', function () {
+    it('rethrows errors getting/setting properties', () => {
       const foo = remote.require(path.join(fixtures, 'module', 'error-properties.js'))
 
-      assert.throws(function () {
+      assert.throws(() => {
         foo.bar
       }, /getting error/)
 
-      assert.throws(function () {
+      assert.throws(() => {
         foo.bar = 'test'
       }, /setting error/)
     })
 
-    it('can set a remote property with a remote object', function () {
+    it('can set a remote property with a remote object', () => {
       const foo = remote.require(path.join(fixtures, 'module', 'remote-object-set.js'))
 
-      assert.doesNotThrow(function () {
+      assert.doesNotThrow(() => {
         foo.bar = remote.getCurrentWindow()
       })
     })
 
-    it('can construct an object from its member', function () {
-      var call = remote.require(path.join(fixtures, 'module', 'call.js'))
-      var obj = new call.constructor()
+    it('can construct an object from its member', () => {
+      const call = remote.require(path.join(fixtures, 'module', 'call.js'))
+      const obj = new call.constructor()
       assert.equal(obj.test, 'test')
     })
 
-    it('can reassign and delete its member functions', function () {
-      var remoteFunctions = remote.require(path.join(fixtures, 'module', 'function.js'))
+    it('can reassign and delete its member functions', () => {
+      const remoteFunctions = remote.require(path.join(fixtures, 'module', 'function.js'))
       assert.equal(remoteFunctions.aFunction(), 1127)
 
-      remoteFunctions.aFunction = function () { return 1234 }
+      remoteFunctions.aFunction = () => { return 1234 }
       assert.equal(remoteFunctions.aFunction(), 1234)
 
       assert.equal(delete remoteFunctions.aFunction, true)
     })
 
-    it('is referenced by its members', function () {
+    it('is referenced by its members', () => {
       let stringify = remote.getGlobal('JSON').stringify
       global.gc()
       stringify({})
     })
   })
 
-  describe('remote value in browser', function () {
+  describe('remote value in browser', () => {
     const print = path.join(fixtures, 'module', 'print_name.js')
     const printName = remote.require(print)
 
-    it('keeps its constructor name for objects', function () {
+    it('keeps its constructor name for objects', () => {
       const buf = new Buffer('test')
       assert.equal(printName.print(buf), 'Buffer')
     })
 
-    it('supports instanceof Date', function () {
+    it('supports instanceof Date', () => {
       const now = new Date()
       assert.equal(printName.print(now), 'Date')
       assert.deepEqual(printName.echo(now), now)
     })
 
-    it('supports instanceof Buffer', function () {
+    it('supports instanceof Buffer', () => {
       const buffer = Buffer.from('test')
       assert.ok(buffer.equals(printName.echo(buffer)))
 
@@ -262,7 +260,7 @@ describe('ipc module', function () {
       assert.ok(arrayWithBuffer[2].equals(printName.echo(arrayWithBuffer)[2]))
     })
 
-    it('supports TypedArray', function () {
+    it('supports TypedArray', () => {
       const values = [1, 2, 3, 4]
       assert.deepEqual(printName.typedArray(values), values)
 
@@ -271,93 +269,93 @@ describe('ipc module', function () {
     })
   })
 
-  describe('remote promise', function () {
-    it('can be used as promise in each side', function (done) {
-      var promise = remote.require(path.join(fixtures, 'module', 'promise.js'))
-      promise.twicePromise(Promise.resolve(1234)).then(function (value) {
+  describe('remote promise', () => {
+    it('can be used as promise in each side', (done) => {
+      const promise = remote.require(path.join(fixtures, 'module', 'promise.js'))
+      promise.twicePromise(Promise.resolve(1234)).then((value) => {
         assert.equal(value, 2468)
         done()
       })
     })
 
-    it('handles rejections via catch(onRejected)', function (done) {
-      var promise = remote.require(path.join(fixtures, 'module', 'rejected-promise.js'))
-      promise.reject(Promise.resolve(1234)).catch(function (error) {
+    it('handles rejections via catch(onRejected)', (done) => {
+      const promise = remote.require(path.join(fixtures, 'module', 'rejected-promise.js'))
+      promise.reject(Promise.resolve(1234)).catch((error) => {
         assert.equal(error.message, 'rejected')
         done()
       })
     })
 
-    it('handles rejections via then(onFulfilled, onRejected)', function (done) {
-      var promise = remote.require(path.join(fixtures, 'module', 'rejected-promise.js'))
-      promise.reject(Promise.resolve(1234)).then(function () {}, function (error) {
+    it('handles rejections via then(onFulfilled, onRejected)', (done) => {
+      const promise = remote.require(path.join(fixtures, 'module', 'rejected-promise.js'))
+      promise.reject(Promise.resolve(1234)).then(() => {}, (error) => {
         assert.equal(error.message, 'rejected')
         done()
       })
     })
 
-    it('does not emit unhandled rejection events in the main process', function (done) {
+    it('does not emit unhandled rejection events in the main process', (done) => {
       remote.process.once('unhandledRejection', function (reason) {
         done(reason)
       })
 
-      var promise = remote.require(path.join(fixtures, 'module', 'unhandled-rejection.js'))
-      promise.reject().then(function () {
+      const promise = remote.require(path.join(fixtures, 'module', 'unhandled-rejection.js'))
+      promise.reject().then(() => {
         done(new Error('Promise was not rejected'))
-      }).catch(function (error) {
+      }).catch((error) => {
         assert.equal(error.message, 'rejected')
         done()
       })
     })
 
-    it('emits unhandled rejection events in the renderer process', function (done) {
+    it('emits unhandled rejection events in the renderer process', (done) => {
       window.addEventListener('unhandledrejection', function (event) {
         event.preventDefault()
         assert.equal(event.reason.message, 'rejected')
         done()
       })
 
-      var promise = remote.require(path.join(fixtures, 'module', 'unhandled-rejection.js'))
-      promise.reject().then(function () {
+      const promise = remote.require(path.join(fixtures, 'module', 'unhandled-rejection.js'))
+      promise.reject().then(() => {
         done(new Error('Promise was not rejected'))
       })
     })
   })
 
-  describe('remote webContents', function () {
-    it('can return same object with different getters', function () {
-      var contents1 = remote.getCurrentWindow().webContents
-      var contents2 = remote.getCurrentWebContents()
+  describe('remote webContents', () => {
+    it('can return same object with different getters', () => {
+      const contents1 = remote.getCurrentWindow().webContents
+      const contents2 = remote.getCurrentWebContents()
       assert(contents1 === contents2)
     })
   })
 
-  describe('remote class', function () {
-    let cl = remote.require(path.join(fixtures, 'module', 'class.js'))
-    let base = cl.base
+  describe('remote class', () => {
+    const cl = remote.require(path.join(fixtures, 'module', 'class.js'))
+    const base = cl.base
     let derived = cl.derived
 
-    it('can get methods', function () {
+    it('can get methods', () => {
       assert.equal(base.method(), 'method')
     })
 
-    it('can get properties', function () {
+    it('can get properties', () => {
       assert.equal(base.readonly, 'readonly')
     })
 
-    it('can change properties', function () {
+    it('can change properties', () => {
       assert.equal(base.value, 'old')
       base.value = 'new'
       assert.equal(base.value, 'new')
       base.value = 'old'
     })
 
-    it('has unenumerable methods', function () {
+    it('has unenumerable methods', () => {
       assert(!base.hasOwnProperty('method'))
       assert(Object.getPrototypeOf(base).hasOwnProperty('method'))
     })
 
-    it('keeps prototype chain in derived class', function () {
+    it('keeps prototype chain in derived class', () => {
       assert.equal(derived.method(), 'method')
       assert.equal(derived.readonly, 'readonly')
       assert(!derived.hasOwnProperty('method'))
@@ -366,7 +364,7 @@ describe('ipc module', function () {
       assert(Object.getPrototypeOf(proto).hasOwnProperty('method'))
     })
 
-    it('is referenced by methods in prototype chain', function () {
+    it('is referenced by methods in prototype chain', () => {
       let method = derived.method
       derived = null
       global.gc()
@@ -374,9 +372,9 @@ describe('ipc module', function () {
     })
   })
 
-  describe('ipc.sender.send', function () {
-    it('should work when sending an object containing id property', function (done) {
-      var obj = {
+  describe('ipc.sender.send', () => {
+    it('should work when sending an object containing id property', (done) => {
+      const obj = {
         id: 1,
         name: 'ly'
       }
@@ -387,7 +385,7 @@ describe('ipc module', function () {
       ipcRenderer.send('message', obj)
     })
 
-    it('can send instances of Date', function (done) {
+    it('can send instances of Date', (done) => {
       const currentDate = new Date()
       ipcRenderer.once('message', function (event, value) {
         assert.equal(value, currentDate.toISOString())
@@ -396,7 +394,7 @@ describe('ipc module', function () {
       ipcRenderer.send('message', currentDate)
     })
 
-    it('can send instances of Buffer', function (done) {
+    it('can send instances of Buffer', (done) => {
       const buffer = Buffer.from('hello')
       ipcRenderer.once('message', function (event, message) {
         assert.ok(buffer.equals(message))
@@ -405,7 +403,7 @@ describe('ipc module', function () {
       ipcRenderer.send('message', buffer)
     })
 
-    it('can send objects with DOM class prototypes', function (done) {
+    it('can send objects with DOM class prototypes', (done) => {
       ipcRenderer.once('message', function (event, value) {
         assert.equal(value.protocol, 'file:')
         assert.equal(value.hostname, '')
@@ -414,7 +412,7 @@ describe('ipc module', function () {
       ipcRenderer.send('message', document.location)
     })
 
-    it('can send Electron API objects', function (done) {
+    it('can send Electron API objects', (done) => {
       const webContents = remote.getCurrentWebContents()
       ipcRenderer.once('message', function (event, value) {
         assert.deepEqual(value.browserWindowOptions, webContents.browserWindowOptions)
@@ -423,10 +421,10 @@ describe('ipc module', function () {
       ipcRenderer.send('message', webContents)
     })
 
-    it('does not crash on external objects (regression)', function (done) {
+    it('does not crash on external objects (regression)', (done) => {
       const request = http.request({port: 5000, hostname: '127.0.0.1', method: 'GET', path: '/'})
       const stream = request.agent.sockets['127.0.0.1:5000:'][0]._handle._externalStream
-      request.on('error', function () {})
+      request.on('error', () => {})
       ipcRenderer.once('message', function (event, requestValue, externalStreamValue) {
         assert.equal(requestValue.method, 'GET')
         assert.equal(requestValue.path, '/')
@@ -437,7 +435,7 @@ describe('ipc module', function () {
       ipcRenderer.send('message', request, stream)
     })
 
-    it('can send objects that both reference the same object', function (done) {
+    it('can send objects that both reference the same object', (done) => {
       const child = {hello: 'world'}
       const foo = {name: 'foo', child: child}
       const bar = {name: 'bar', child: child}
@@ -453,7 +451,7 @@ describe('ipc module', function () {
       ipcRenderer.send('message', array, foo, bar, child)
     })
 
-    it('inserts null for cyclic references', function (done) {
+    it('inserts null for cyclic references', (done) => {
       const array = [5]
       array.push(array)
 
@@ -473,17 +471,17 @@ describe('ipc module', function () {
     })
   })
 
-  describe('ipc.sendSync', function () {
-    afterEach(function () {
+  describe('ipc.sendSync', () => {
+    afterEach(() => {
       ipcMain.removeAllListeners('send-sync-message')
     })
 
-    it('can be replied by setting event.returnValue', function () {
-      var msg = ipcRenderer.sendSync('echo', 'test')
+    it('can be replied by setting event.returnValue', () => {
+      const msg = ipcRenderer.sendSync('echo', 'test')
       assert.equal(msg, 'test')
     })
 
-    it('does not crash when reply is not sent and browser is destroyed', function (done) {
+    it('does not crash when reply is not sent and browser is destroyed', (done) => {
       w = new BrowserWindow({
         show: false
       })
@@ -494,7 +492,7 @@ describe('ipc module', function () {
       w.loadURL('file://' + path.join(fixtures, 'api', 'send-sync-message.html'))
     })
 
-    it('does not crash when reply is sent by multiple listeners', function (done) {
+    it('does not crash when reply is sent by multiple listeners', (done) => {
       w = new BrowserWindow({
         show: false
       })
@@ -509,36 +507,36 @@ describe('ipc module', function () {
     })
   })
 
-  describe('ipcRenderer.sendTo', function () {
+  describe('ipcRenderer.sendTo', () => {
     let contents = null
-    beforeEach(function () {
+    beforeEach(() => {
       contents = webContents.create({})
     })
-    afterEach(function () {
+    afterEach(() => {
       ipcRenderer.removeAllListeners('pong')
       contents.destroy()
       contents = null
     })
 
-    it('sends message to WebContents', function (done) {
+    it('sends message to WebContents', (done) => {
       const webContentsId = remote.getCurrentWebContents().id
       ipcRenderer.once('pong', function (event, id) {
         assert.equal(webContentsId, id)
         done()
       })
-      contents.once('did-finish-load', function () {
+      contents.once('did-finish-load', () => {
         ipcRenderer.sendTo(contents.id, 'ping', webContentsId)
       })
       contents.loadURL('file://' + path.join(fixtures, 'pages', 'ping-pong.html'))
     })
   })
 
-  describe('remote listeners', function () {
-    it('can be added and removed correctly', function () {
+  describe('remote listeners', () => {
+    it('can be added and removed correctly', () => {
       w = new BrowserWindow({
         show: false
       })
-      var listener = function () {}
+      const listener = () => {}
       w.on('test', listener)
       assert.equal(w.listenerCount('test'), 1)
       w.removeListener('test', listener)
@@ -592,8 +590,8 @@ describe('ipc module', function () {
     assert.equal(ipcRenderer.listenerCount('test-event'), 0)
   })
 
-  describe('remote objects registry', function () {
-    it('does not dereference until the render view is deleted (regression)', function (done) {
+  describe('remote objects registry', () => {
+    it('does not dereference until the render view is deleted (regression)', (done) => {
       w = new BrowserWindow({
         show: false
       })

+ 46 - 46
spec/api-menu-spec.js

@@ -4,9 +4,9 @@ const {ipcRenderer, remote} = require('electron')
 const {BrowserWindow, Menu, MenuItem} = remote
 const {closeWindow} = require('./window-helpers')
 
-describe('menu module', function () {
-  describe('Menu.buildFromTemplate', function () {
-    it('should be able to attach extra fields', function () {
+describe('Menu module', () => {
+  describe('Menu.buildFromTemplate', () => {
+    it('should be able to attach extra fields', () => {
       const menu = Menu.buildFromTemplate([
         {
           label: 'text',
@@ -16,7 +16,7 @@ describe('menu module', function () {
       assert.equal(menu.items[0].extra, 'field')
     })
 
-    it('does not modify the specified template', function () {
+    it('does not modify the specified template', () => {
       const template = ipcRenderer.sendSync('eval', "var template = [{label: 'text', submenu: [{label: 'sub'}]}];\nrequire('electron').Menu.buildFromTemplate(template);\ntemplate;")
       assert.deepStrictEqual(template, [
         {
@@ -30,8 +30,8 @@ describe('menu module', function () {
       ])
     })
 
-    it('does not throw exceptions for undefined/null values', function () {
-      assert.doesNotThrow(function () {
+    it('does not throw exceptions for undefined/null values', () => {
+      assert.doesNotThrow(() => {
         Menu.buildFromTemplate([
           {
             label: 'text',
@@ -45,8 +45,8 @@ describe('menu module', function () {
       })
     })
 
-    describe('Menu.buildFromTemplate should reorder based on item position specifiers', function () {
-      it('should position before existing item', function () {
+    describe('Menu.buildFromTemplate should reorder based on item position specifiers', () => {
+      it('should position before existing item', () => {
         const menu = Menu.buildFromTemplate([
           {
             label: '2',
@@ -65,7 +65,7 @@ describe('menu module', function () {
         assert.equal(menu.items[2].label, '3')
       })
 
-      it('should position after existing item', function () {
+      it('should position after existing item', () => {
         const menu = Menu.buildFromTemplate([
           {
             label: '1',
@@ -84,7 +84,7 @@ describe('menu module', function () {
         assert.equal(menu.items[2].label, '3')
       })
 
-      it('should position at endof existing separator groups', function () {
+      it('should position at endof existing separator groups', () => {
         const menu = Menu.buildFromTemplate([
           {
             type: 'separator',
@@ -128,7 +128,7 @@ describe('menu module', function () {
         assert.equal(menu.items[7].label, 'c')
       })
 
-      it('should create separator group if endof does not reference existing separator group', function () {
+      it('should create separator group if endof does not reference existing separator group', () => {
         const menu = Menu.buildFromTemplate([
           {
             label: 'a',
@@ -166,7 +166,7 @@ describe('menu module', function () {
         assert.equal(menu.items[7].label, '3')
       })
 
-      it('should continue inserting items at next index when no specifier is present', function () {
+      it('should continue inserting items at next index when no specifier is present', () => {
         const menu = Menu.buildFromTemplate([
           {
             label: '4',
@@ -195,8 +195,8 @@ describe('menu module', function () {
     })
   })
 
-  describe('Menu.getMenuItemById', function () {
-    it('should return the item with the given id', function () {
+  describe('Menu.getMenuItemById', () => {
+    it('should return the item with the given id', () => {
       const menu = Menu.buildFromTemplate([
         {
           label: 'View',
@@ -218,8 +218,8 @@ describe('menu module', function () {
     })
   })
 
-  describe('Menu.insert', function () {
-    it('should store item in @items by its index', function () {
+  describe('Menu.insert', () => {
+    it('should store item in @items by its index', () => {
       const menu = Menu.buildFromTemplate([
         {
           label: '1'
@@ -240,8 +240,8 @@ describe('menu module', function () {
     })
   })
 
-  describe('Menu.append', function () {
-    it('should add the item to the end of the menu', function () {
+  describe('Menu.append', () => {
+    it('should add the item to the end of the menu', () => {
       const menu = Menu.buildFromTemplate([
         {
           label: '1'
@@ -261,7 +261,7 @@ describe('menu module', function () {
     })
   })
 
-  describe('Menu.popup', function () {
+  describe('Menu.popup', () => {
     let w = null
     let menu
 
@@ -279,18 +279,18 @@ describe('menu module', function () {
     })
 
     afterEach(() => {
-      return closeWindow(w).then(function () { w = null })
+      return closeWindow(w).then(() => { w = null })
     })
 
-    describe('when called with async: true', function () {
-      it('returns immediately', function () {
+    describe('when called with async: true', () => {
+      it('returns immediately', () => {
         menu.popup(w, {x: 100, y: 100, async: true})
         menu.closePopup(w)
       })
     })
   })
 
-  describe('Menu.setApplicationMenu', function () {
+  describe('Menu.setApplicationMenu', () => {
     const menu = Menu.buildFromTemplate([
       {
         label: '1'
@@ -302,7 +302,7 @@ describe('menu module', function () {
     assert.notEqual(Menu.getApplicationMenu(), null)
   })
 
-  describe('MenuItem.click', function () {
+  describe('MenuItem.click', () => {
     it('should be called with the item object passed', function (done) {
       const menu = Menu.buildFromTemplate([
         {
@@ -318,8 +318,8 @@ describe('menu module', function () {
     })
   })
 
-  describe('MenuItem with checked property', function () {
-    it('clicking an checkbox item should flip the checked property', function () {
+  describe('MenuItem with checked property', () => {
+    it('clicking an checkbox item should flip the checked property', () => {
       const menu = Menu.buildFromTemplate([
         {
           label: 'text',
@@ -331,7 +331,7 @@ describe('menu module', function () {
       assert.equal(menu.items[0].checked, true)
     })
 
-    it('clicking an radio item should always make checked property true', function () {
+    it('clicking an radio item should always make checked property true', () => {
       const menu = Menu.buildFromTemplate([
         {
           label: 'text',
@@ -344,7 +344,7 @@ describe('menu module', function () {
       assert.equal(menu.items[0].checked, true)
     })
 
-    it('at least have one item checked in each group', function () {
+    it('at least have one item checked in each group', () => {
       const template = []
       for (let i = 0; i <= 10; i++) {
         template.push({
@@ -365,7 +365,7 @@ describe('menu module', function () {
       assert.equal(menu.items[12].checked, true)
     })
 
-    it('should assign groupId automatically', function () {
+    it('should assign groupId automatically', () => {
       const template = []
       for (let i = 0; i <= 10; i++) {
         template.push({
@@ -390,7 +390,7 @@ describe('menu module', function () {
       }
     })
 
-    it("setting 'checked' should flip other items' 'checked' property", function () {
+    it("setting 'checked' should flip other items' 'checked' property", () => {
       const template = []
       for (let i = 0; i <= 10; i++) {
         template.push({
@@ -435,8 +435,8 @@ describe('menu module', function () {
     })
   })
 
-  describe('MenuItem command id', function () {
-    it('cannot be overwritten', function () {
+  describe('MenuItem command id', () => {
+    it('cannot be overwritten', () => {
       const item = new MenuItem({label: 'item'})
 
       const commandId = item.commandId
@@ -446,8 +446,8 @@ describe('menu module', function () {
     })
   })
 
-  describe('MenuItem with invalid type', function () {
-    it('throws an exception', function () {
+  describe('MenuItem with invalid type', () => {
+    it('throws an exception', () => {
       assert.throws(() => {
         Menu.buildFromTemplate([
           {
@@ -459,8 +459,8 @@ describe('menu module', function () {
     })
   })
 
-  describe('MenuItem with submenu type and missing submenu', function () {
-    it('throws an exception', function () {
+  describe('MenuItem with submenu type and missing submenu', () => {
+    it('throws an exception', () => {
       assert.throws(() => {
         Menu.buildFromTemplate([
           {
@@ -472,8 +472,8 @@ describe('menu module', function () {
     })
   })
 
-  describe('MenuItem role', function () {
-    it('includes a default label and accelerator', function () {
+  describe('MenuItem role', () => {
+    it('includes a default label and accelerator', () => {
       let item = new MenuItem({role: 'close'})
       assert.equal(item.label, process.platform === 'darwin' ? 'Close Window' : 'Close')
       assert.equal(item.accelerator, undefined)
@@ -506,8 +506,8 @@ describe('menu module', function () {
     })
   })
 
-  describe('MenuItem editMenu', function () {
-    it('includes a default submenu layout when submenu is empty', function () {
+  describe('MenuItem editMenu', () => {
+    it('includes a default submenu layout when submenu is empty', () => {
       const item = new MenuItem({role: 'editMenu'})
       assert.equal(item.label, 'Edit')
       assert.equal(item.submenu.items[0].role, 'undo')
@@ -530,15 +530,15 @@ describe('menu module', function () {
       }
     })
 
-    it('overrides default layout when submenu is specified', function () {
+    it('overrides default layout when submenu is specified', () => {
       const item = new MenuItem({role: 'editMenu', submenu: [{role: 'close'}]})
       assert.equal(item.label, 'Edit')
       assert.equal(item.submenu.items[0].role, 'close')
     })
   })
 
-  describe('MenuItem windowMenu', function () {
-    it('includes a default submenu layout when submenu is empty', function () {
+  describe('MenuItem windowMenu', () => {
+    it('includes a default submenu layout when submenu is empty', () => {
       const item = new MenuItem({role: 'windowMenu'})
       assert.equal(item.label, 'Window')
       assert.equal(item.submenu.items[0].role, 'minimize')
@@ -550,15 +550,15 @@ describe('menu module', function () {
       }
     })
 
-    it('overrides default layout when submenu is specified', function () {
+    it('overrides default layout when submenu is specified', () => {
       const item = new MenuItem({role: 'windowMenu', submenu: [{role: 'copy'}]})
       assert.equal(item.label, 'Window')
       assert.equal(item.submenu.items[0].role, 'copy')
     })
   })
 
-  describe('MenuItem with custom properties in constructor', function () {
-    it('preserves the custom properties', function () {
+  describe('MenuItem with custom properties in constructor', () => {
+    it('preserves the custom properties', () => {
       const template = [{
         label: 'menu 1',
         customProp: 'foo',

File diff suppressed because it is too large
+ 183 - 191
spec/api-net-spec.js


+ 183 - 223
spec/api-session-spec.js

@@ -10,13 +10,13 @@ const {closeWindow} = require('./window-helpers')
 const {ipcRenderer, remote} = require('electron')
 const {ipcMain, session, BrowserWindow, net} = remote
 
-describe('session module', function () {
-  var fixtures = path.resolve(__dirname, 'fixtures')
-  var w = null
-  var webview = null
-  var url = 'http://127.0.0.1'
+describe('session module', () => {
+  let fixtures = path.resolve(__dirname, 'fixtures')
+  let w = null
+  let webview = null
+  const url = 'http://127.0.0.1'
 
-  beforeEach(function () {
+  beforeEach(() => {
     w = new BrowserWindow({
       show: false,
       width: 400,
@@ -24,7 +24,7 @@ describe('session module', function () {
     })
   })
 
-  afterEach(function () {
+  afterEach(() => {
     if (webview != null) {
       if (!document.body.contains(webview)) {
         document.body.appendChild(webview)
@@ -32,21 +32,21 @@ describe('session module', function () {
       webview.remove()
     }
 
-    return closeWindow(w).then(function () { w = null })
+    return closeWindow(w).then(() => { w = null })
   })
 
-  describe('session.defaultSession', function () {
-    it('returns the default session', function () {
+  describe('session.defaultSession', () => {
+    it('returns the default session', () => {
       assert.equal(session.defaultSession, session.fromPartition(''))
     })
   })
 
-  describe('session.fromPartition(partition, options)', function () {
-    it('returns existing session with same partition', function () {
+  describe('session.fromPartition(partition, options)', () => {
+    it('returns existing session with same partition', () => {
       assert.equal(session.fromPartition('test'), session.fromPartition('test'))
     })
 
-    it('created session is ref-counted', function () {
+    it('created session is ref-counted', () => {
       const partition = 'test2'
       const userAgent = 'test-agent'
       const ses1 = session.fromPartition(partition)
@@ -58,104 +58,83 @@ describe('session module', function () {
     })
   })
 
-  describe('ses.cookies', function () {
-    it('should get cookies', function (done) {
-      var server = http.createServer(function (req, res) {
+  describe('ses.cookies', () => {
+    it('should get cookies', (done) => {
+      const server = http.createServer((req, res) => {
         res.setHeader('Set-Cookie', ['0=0'])
         res.end('finished')
         server.close()
       })
-      server.listen(0, '127.0.0.1', function () {
-        var port = server.address().port
-        w.loadURL(url + ':' + port)
-        w.webContents.on('did-finish-load', function () {
-          w.webContents.session.cookies.get({
-            url: url
-          }, function (error, list) {
-            var cookie, i, len
-            if (error) {
-              return done(error)
-            }
-            for (i = 0, len = list.length; i < len; i++) {
-              cookie = list[i]
+      server.listen(0, '127.0.0.1', () => {
+        const port = server.address().port
+        w.loadURL(`${url}:${port}`)
+        w.webContents.on('did-finish-load', () => {
+          w.webContents.session.cookies.get({url}, (error, list) => {
+            if (error) return done(error)
+            for (let i = 0; i < list.length; i++) {
+              const cookie = list[i]
               if (cookie.name === '0') {
                 if (cookie.value === '0') {
                   return done()
                 } else {
-                  return done('cookie value is ' + cookie.value + ' while expecting 0')
+                  return done(`cookie value is ${cookie.value} while expecting 0`)
                 }
               }
             }
-            done('Can not find cookie')
+            done('Can\'t find cookie')
           })
         })
       })
     })
 
-    it('calls back with an error when setting a cookie with missing required fields', function (done) {
+    it('calls back with an error when setting a cookie with missing required fields', (done) => {
       session.defaultSession.cookies.set({
         url: '',
         name: '1',
         value: '1'
-      }, function (error) {
+      }, (error) => {
         assert.equal(error.message, 'Setting cookie failed')
         done()
       })
     })
 
-    it('should over-write the existent cookie', function (done) {
+    it('should over-write the existent cookie', (done) => {
       session.defaultSession.cookies.set({
-        url: url,
+        url,
         name: '1',
         value: '1'
-      }, function (error) {
-        if (error) {
-          return done(error)
-        }
-        session.defaultSession.cookies.get({
-          url: url
-        }, function (error, list) {
-          var cookie, i, len
-          if (error) {
-            return done(error)
-          }
-          for (i = 0, len = list.length; i < len; i++) {
-            cookie = list[i]
+      }, (error) => {
+        if (error) return done(error)
+        session.defaultSession.cookies.get({url}, (error, list) => {
+          if (error) return done(error)
+          for (let i = 0; i < list.length; i++) {
+            const cookie = list[i]
             if (cookie.name === '1') {
               if (cookie.value === '1') {
                 return done()
               } else {
-                return done('cookie value is ' + cookie.value + ' while expecting 1')
+                return done(`cookie value is ${cookie.value} while expecting 1`)
               }
             }
           }
-          done('Can not find cookie')
+          done('Can\'t find cookie')
         })
       })
     })
 
-    it('should remove cookies', function (done) {
+    it('should remove cookies', (done) => {
       session.defaultSession.cookies.set({
         url: url,
         name: '2',
         value: '2'
-      }, function (error) {
-        if (error) {
-          return done(error)
-        }
-        session.defaultSession.cookies.remove(url, '2', function () {
-          session.defaultSession.cookies.get({
-            url: url
-          }, function (error, list) {
-            var cookie, i, len
-            if (error) {
-              return done(error)
-            }
-            for (i = 0, len = list.length; i < len; i++) {
-              cookie = list[i]
-              if (cookie.name === '2') {
-                return done('Cookie not deleted')
-              }
+      }, (error) => {
+        if (error) return done(error)
+        session.defaultSession.cookies.remove(url, '2', () => {
+          session.defaultSession.cookies.get({url}, (error, list) => {
+            if (error) return done(error)
+            for (let i = 0; i < list.length; i++) {
+              const cookie = list[i]
+              if (cookie.name === '2') return done('Cookie not deleted')
             }
             done()
           })
@@ -163,23 +142,17 @@ describe('session module', function () {
       })
     })
 
-    it('should set cookie for standard scheme', function (done) {
+    it('should set cookie for standard scheme', (done) => {
       const standardScheme = remote.getGlobal('standardScheme')
       const origin = standardScheme + '://fake-host'
       session.defaultSession.cookies.set({
         url: origin,
         name: 'custom',
         value: '1'
-      }, function (error) {
-        if (error) {
-          return done(error)
-        }
-        session.defaultSession.cookies.get({
-          url: origin
-        }, function (error, list) {
-          if (error) {
-            return done(error)
-          }
+      }, (error) => {
+        if (error) return done(error)
+        session.defaultSession.cookies.get({url: origin}, (error, list) => {
+          if (error) return done(error)
           assert.equal(list.length, 1)
           assert.equal(list[0].name, 'custom')
           assert.equal(list[0].value, '1')
@@ -189,16 +162,16 @@ describe('session module', function () {
       })
     })
 
-    it('emits a changed event when a cookie is added or removed', function (done) {
+    it('emits a changed event when a cookie is added or removed', (done) => {
       const {cookies} = session.fromPartition('cookies-changed')
 
-      cookies.once('changed', function (event, cookie, cause, removed) {
+      cookies.once('changed', (event, cookie, cause, removed) => {
         assert.equal(cookie.name, 'foo')
         assert.equal(cookie.value, 'bar')
         assert.equal(cause, 'explicit')
         assert.equal(removed, false)
 
-        cookies.once('changed', function (event, cookie, cause, removed) {
+        cookies.once('changed', (event, cookie, cause, removed) => {
           assert.equal(cookie.name, 'foo')
           assert.equal(cookie.value, 'bar')
           assert.equal(cause, 'explicit')
@@ -206,7 +179,7 @@ describe('session module', function () {
           done()
         })
 
-        cookies.remove(url, 'foo', function (error) {
+        cookies.remove(url, 'foo', (error) => {
           if (error) return done(error)
         })
       })
@@ -215,13 +188,13 @@ describe('session module', function () {
         url: url,
         name: 'foo',
         value: 'bar'
-      }, function (error) {
+      }, (error) => {
         if (error) return done(error)
       })
     })
 
-    describe('ses.cookies.flushStore(callback)', function () {
-      it('flushes the cookies to disk and invokes the callback when done', function (done) {
+    describe('ses.cookies.flushStore(callback)', () => {
+      it('flushes the cookies to disk and invokes the callback when done', (done) => {
         session.defaultSession.cookies.set({
           url: url,
           name: 'foo',
@@ -236,30 +209,30 @@ describe('session module', function () {
     })
   })
 
-  describe('ses.clearStorageData(options)', function () {
+  describe('ses.clearStorageData(options)', () => {
     fixtures = path.resolve(__dirname, 'fixtures')
-    it('clears localstorage data', function (done) {
-      ipcMain.on('count', function (event, count) {
+    it('clears localstorage data', (done) => {
+      ipcMain.on('count', (event, count) => {
         ipcMain.removeAllListeners('count')
         assert.equal(count, 0)
         done()
       })
       w.loadURL('file://' + path.join(fixtures, 'api', 'localstorage.html'))
-      w.webContents.on('did-finish-load', function () {
-        var options = {
+      w.webContents.on('did-finish-load', () => {
+        const options = {
           origin: 'file://',
           storages: ['localstorage'],
           quotas: ['persistent']
         }
-        w.webContents.session.clearStorageData(options, function () {
+        w.webContents.session.clearStorageData(options, () => {
           w.webContents.send('getcount')
         })
       })
     })
   })
 
-  describe('will-download event', function () {
-    beforeEach(function () {
+  describe('will-download event', () => {
+    beforeEach(() => {
       if (w != null) w.destroy()
       w = new BrowserWindow({
         show: false,
@@ -268,10 +241,10 @@ describe('session module', function () {
       })
     })
 
-    it('can cancel default download behavior', function (done) {
+    it('can cancel default download behavior', (done) => {
       const mockFile = new Buffer(1024)
       const contentDisposition = 'inline; filename="mockFile.txt"'
-      const downloadServer = http.createServer(function (req, res) {
+      const downloadServer = http.createServer((req, res) => {
         res.writeHead(200, {
           'Content-Length': mockFile.length,
           'Content-Type': 'application/plain',
@@ -281,13 +254,13 @@ describe('session module', function () {
         downloadServer.close()
       })
 
-      downloadServer.listen(0, '127.0.0.1', function () {
+      downloadServer.listen(0, '127.0.0.1', () => {
         const port = downloadServer.address().port
-        const url = 'http://127.0.0.1:' + port + '/'
+        const url = `http://127.0.0.1:${port}/`
 
         ipcRenderer.sendSync('set-download-option', false, true)
         w.loadURL(url)
-        ipcRenderer.once('download-error', function (event, downloadUrl, filename, error) {
+        ipcRenderer.once('download-error', (event, downloadUrl, filename, error) => {
           assert.equal(downloadUrl, url)
           assert.equal(filename, 'mockFile.txt')
           assert.equal(error, 'Object has been destroyed')
@@ -297,14 +270,12 @@ describe('session module', function () {
     })
   })
 
-  describe('DownloadItem', function () {
-    var mockPDF = new Buffer(1024 * 1024 * 5)
-    var contentDisposition = 'inline; filename="mock.pdf"'
-    var downloadFilePath = path.join(fixtures, 'mock.pdf')
-    var downloadServer = http.createServer(function (req, res) {
-      if (req.url === '/?testFilename') {
-        contentDisposition = 'inline'
-      }
+  describe('DownloadItem', () => {
+    const mockPDF = new Buffer(1024 * 1024 * 5)
+    let contentDisposition = 'inline; filename="mock.pdf"'
+    const downloadFilePath = path.join(fixtures, 'mock.pdf')
+    const downloadServer = http.createServer((req, res) => {
+      if (req.url === '/?testFilename') contentDisposition = 'inline'
       res.writeHead(200, {
         'Content-Length': mockPDF.length,
         'Content-Type': 'application/pdf',
@@ -313,13 +284,13 @@ describe('session module', function () {
       res.end(mockPDF)
       downloadServer.close()
     })
-    var assertDownload = function (event, state, url, mimeType,
+    const assertDownload = (event, state, url, mimeType,
                                    receivedBytes, totalBytes, disposition,
-                                   filename, port, savePath) {
+                                   filename, port, savePath) => {
       assert.equal(state, 'completed')
       assert.equal(filename, 'mock.pdf')
       assert.equal(savePath, path.join(__dirname, 'fixtures', 'mock.pdf'))
-      assert.equal(url, 'http://127.0.0.1:' + port + '/')
+      assert.equal(url, `http://127.0.0.1:${port}/`)
       assert.equal(mimeType, 'application/pdf')
       assert.equal(receivedBytes, mockPDF.length)
       assert.equal(totalBytes, mockPDF.length)
@@ -328,15 +299,15 @@ describe('session module', function () {
       fs.unlinkSync(downloadFilePath)
     }
 
-    it('can download using WebContents.downloadURL', function (done) {
-      downloadServer.listen(0, '127.0.0.1', function () {
-        var port = downloadServer.address().port
+    it('can download using WebContents.downloadURL', (done) => {
+      downloadServer.listen(0, '127.0.0.1', () => {
+        const port = downloadServer.address().port
         ipcRenderer.sendSync('set-download-option', false, false)
-        w.webContents.downloadURL(url + ':' + port)
-        ipcRenderer.once('download-done', function (event, state, url,
+        w.webContents.downloadURL(`${url}:${port}`)
+        ipcRenderer.once('download-done', (event, state, url,
                                                     mimeType, receivedBytes,
                                                     totalBytes, disposition,
-                                                    filename, savePath) {
+                                                    filename, savePath) => {
           assertDownload(event, state, url, mimeType, receivedBytes,
                          totalBytes, disposition, filename, port, savePath)
           done()
@@ -344,19 +315,19 @@ describe('session module', function () {
       })
     })
 
-    it('can download using WebView.downloadURL', function (done) {
-      downloadServer.listen(0, '127.0.0.1', function () {
-        var port = downloadServer.address().port
+    it('can download using WebView.downloadURL', (done) => {
+      downloadServer.listen(0, '127.0.0.1', () => {
+        const port = downloadServer.address().port
         ipcRenderer.sendSync('set-download-option', false, false)
         webview = new WebView()
-        webview.src = 'file://' + fixtures + '/api/blank.html'
-        webview.addEventListener('did-finish-load', function () {
-          webview.downloadURL(url + ':' + port + '/')
+        webview.src = `file://${fixtures}/api/blank.html`
+        webview.addEventListener('did-finish-load', () => {
+          webview.downloadURL(`${url}:${port}/`)
         })
-        ipcRenderer.once('download-done', function (event, state, url,
+        ipcRenderer.once('download-done', (event, state, url,
                                                     mimeType, receivedBytes,
                                                     totalBytes, disposition,
-                                                    filename, savePath) {
+                                                    filename, savePath) => {
           assertDownload(event, state, url, mimeType, receivedBytes,
                          totalBytes, disposition, filename, port, savePath)
           document.body.removeChild(webview)
@@ -366,15 +337,15 @@ describe('session module', function () {
       })
     })
 
-    it('can cancel download', function (done) {
-      downloadServer.listen(0, '127.0.0.1', function () {
-        var port = downloadServer.address().port
+    it('can cancel download', (done) => {
+      downloadServer.listen(0, '127.0.0.1', () => {
+        const port = downloadServer.address().port
         ipcRenderer.sendSync('set-download-option', true, false)
-        w.webContents.downloadURL(url + ':' + port + '/')
-        ipcRenderer.once('download-done', function (event, state, url,
+        w.webContents.downloadURL(`${url}:${port}/`)
+        ipcRenderer.once('download-done', (event, state, url,
                                                     mimeType, receivedBytes,
                                                     totalBytes, disposition,
-                                                    filename) {
+                                                    filename) => {
           assert.equal(state, 'cancelled')
           assert.equal(filename, 'mock.pdf')
           assert.equal(mimeType, 'application/pdf')
@@ -386,18 +357,17 @@ describe('session module', function () {
       })
     })
 
-    it('can generate a default filename', function (done) {
-      // Somehow this test always fail on appveyor.
+    it('can generate a default filename', (done) => {
       if (process.env.APPVEYOR === 'True') return done()
 
-      downloadServer.listen(0, '127.0.0.1', function () {
-        var port = downloadServer.address().port
+      downloadServer.listen(0, '127.0.0.1', () => {
+        const port = downloadServer.address().port
         ipcRenderer.sendSync('set-download-option', true, false)
-        w.webContents.downloadURL(url + ':' + port + '/?testFilename')
-        ipcRenderer.once('download-done', function (event, state, url,
+        w.webContents.downloadURL(`${url}:${port}/?testFilename`)
+        ipcRenderer.once('download-done', (event, state, url,
                                                     mimeType, receivedBytes,
                                                     totalBytes, disposition,
-                                                    filename) {
+                                                    filename) => {
           assert.equal(state, 'cancelled')
           assert.equal(filename, 'download.pdf')
           assert.equal(mimeType, 'application/pdf')
@@ -409,28 +379,28 @@ describe('session module', function () {
       })
     })
 
-    describe('when a save path is specified and the URL is unavailable', function () {
-      it('does not display a save dialog and reports the done state as interrupted', function (done) {
+    describe('when a save path is specified and the URL is unavailable', () => {
+      it('does not display a save dialog and reports the done state as interrupted', (done) => {
         ipcRenderer.sendSync('set-download-option', false, false)
         ipcRenderer.once('download-done', (event, state) => {
           assert.equal(state, 'interrupted')
           done()
         })
-        w.webContents.downloadURL('file://' + path.join(__dirname, 'does-not-exist.txt'))
+        w.webContents.downloadURL(`file://${path.join(__dirname, 'does-not-exist.txt')}`)
       })
     })
   })
 
-  describe('ses.protocol', function () {
+  describe('ses.protocol', () => {
     const partitionName = 'temp'
     const protocolName = 'sp'
     const partitionProtocol = session.fromPartition(partitionName).protocol
     const protocol = session.defaultSession.protocol
-    const handler = function (ignoredError, callback) {
+    const handler = (ignoredError, callback) => {
       callback({data: 'test', mimeType: 'text/html'})
     }
 
-    beforeEach(function (done) {
+    beforeEach((done) => {
       if (w != null) w.destroy()
       w = new BrowserWindow({
         show: false,
@@ -438,53 +408,49 @@ describe('session module', function () {
           partition: partitionName
         }
       })
-      partitionProtocol.registerStringProtocol(protocolName, handler, function (error) {
+      partitionProtocol.registerStringProtocol(protocolName, handler, (error) => {
         done(error != null ? error : undefined)
       })
     })
 
-    afterEach(function (done) {
+    afterEach((done) => {
       partitionProtocol.unregisterProtocol(protocolName, () => done())
     })
 
-    it('does not affect defaultSession', function (done) {
-      protocol.isProtocolHandled(protocolName, function (result) {
+    it('does not affect defaultSession', (done) => {
+      protocol.isProtocolHandled(protocolName, (result) => {
         assert.equal(result, false)
-        partitionProtocol.isProtocolHandled(protocolName, function (result) {
+        partitionProtocol.isProtocolHandled(protocolName, (result) => {
           assert.equal(result, true)
           done()
         })
       })
     })
 
-    xit('handles requests from partition', function (done) {
-      w.webContents.on('did-finish-load', function () {
-        done()
-      })
+    xit('handles requests from partition', (done) => {
+      w.webContents.on('did-finish-load', () => done())
       w.loadURL(`${protocolName}://fake-host`)
     })
   })
 
-  describe('ses.setProxy(options, callback)', function () {
-    it('allows configuring proxy settings', function (done) {
-      const config = {
-        proxyRules: 'http=myproxy:80'
-      }
-      session.defaultSession.setProxy(config, function () {
-        session.defaultSession.resolveProxy('http://localhost', function (proxy) {
+  describe('ses.setProxy(options, callback)', () => {
+    it('allows configuring proxy settings', (done) => {
+      const config = {proxyRules: 'http=myproxy:80'}
+      session.defaultSession.setProxy(config, () => {
+        session.defaultSession.resolveProxy('http://localhost', (proxy) => {
           assert.equal(proxy, 'PROXY myproxy:80')
           done()
         })
       })
     })
 
-    it('allows bypassing proxy settings', function (done) {
+    it('allows bypassing proxy settings', (done) => {
       const config = {
         proxyRules: 'http=myproxy:80',
         proxyBypassRules: '<local>'
       }
-      session.defaultSession.setProxy(config, function () {
-        session.defaultSession.resolveProxy('http://localhost', function (proxy) {
+      session.defaultSession.setProxy(config, () => {
+        session.defaultSession.resolveProxy('http://localhost', (proxy) => {
           assert.equal(proxy, 'DIRECT')
           done()
         })
@@ -492,17 +458,17 @@ describe('session module', function () {
     })
   })
 
-  describe('ses.getBlobData(identifier, callback)', function () {
-    it('returns blob data for uuid', function (done) {
+  describe('ses.getBlobData(identifier, callback)', () => {
+    it('returns blob data for uuid', (done) => {
       const scheme = 'temp'
       const protocol = session.defaultSession.protocol
-      const url = scheme + '://host'
-      before(function () {
+      const url = `${scheme}://host`
+      before(() => {
         if (w != null) w.destroy()
         w = new BrowserWindow({show: false})
       })
 
-      after(function (done) {
+      after((done) => {
         protocol.unregisterProtocol(scheme, () => {
           closeWindow(w).then(() => {
             w = null
@@ -525,30 +491,30 @@ describe('session module', function () {
                        </script>
                        </html>`
 
-      protocol.registerStringProtocol(scheme, function (request, callback) {
+      protocol.registerStringProtocol(scheme, (request, callback) => {
         if (request.method === 'GET') {
           callback({data: content, mimeType: 'text/html'})
         } else if (request.method === 'POST') {
           let uuid = request.uploadData[1].blobUUID
           assert(uuid)
-          session.defaultSession.getBlobData(uuid, function (result) {
+          session.defaultSession.getBlobData(uuid, (result) => {
             assert.equal(result.toString(), postData)
             done()
           })
         }
-      }, function (error) {
+      }, (error) => {
         if (error) return done(error)
         w.loadURL(url)
       })
     })
   })
 
-  describe('ses.setCertificateVerifyProc(callback)', function () {
-    var server = null
+  describe('ses.setCertificateVerifyProc(callback)', () => {
+    let server = null
 
-    beforeEach(function (done) {
-      var certPath = path.join(__dirname, 'fixtures', 'certificates')
-      var options = {
+    beforeEach((done) => {
+      const certPath = path.join(__dirname, 'fixtures', 'certificates')
+      const options = {
         key: fs.readFileSync(path.join(certPath, 'server.key')),
         cert: fs.readFileSync(path.join(certPath, 'server.pem')),
         ca: [
@@ -559,54 +525,54 @@ describe('session module', function () {
         rejectUnauthorized: false
       }
 
-      server = https.createServer(options, function (req, res) {
+      server = https.createServer(options, (req, res) => {
         res.writeHead(200)
         res.end('<title>hello</title>')
       })
       server.listen(0, '127.0.0.1', done)
     })
 
-    afterEach(function () {
+    afterEach(() => {
       session.defaultSession.setCertificateVerifyProc(null)
       server.close()
     })
 
-    it('accepts the request when the callback is called with 0', function (done) {
-      session.defaultSession.setCertificateVerifyProc(function ({hostname, certificate, verificationResult, errorCode}, callback) {
+    it('accepts the request when the callback is called with 0', (done) => {
+      session.defaultSession.setCertificateVerifyProc(({hostname, certificate, verificationResult, errorCode}, callback) => {
         assert(['net::ERR_CERT_AUTHORITY_INVALID', 'net::ERR_CERT_COMMON_NAME_INVALID'].includes(verificationResult), verificationResult)
         assert([-202, -200].includes(errorCode), errorCode)
         callback(0)
       })
 
-      w.webContents.once('did-finish-load', function () {
+      w.webContents.once('did-finish-load', () => {
         assert.equal(w.webContents.getTitle(), 'hello')
         done()
       })
       w.loadURL(`https://127.0.0.1:${server.address().port}`)
     })
 
-    describe('deprecated function signature', function () {
-      it('supports accepting the request', function (done) {
-        session.defaultSession.setCertificateVerifyProc(function (hostname, certificate, callback) {
+    describe('deprecated function signature', () => {
+      it('supports accepting the request', (done) => {
+        session.defaultSession.setCertificateVerifyProc((hostname, certificate, callback) => {
           assert.equal(hostname, '127.0.0.1')
           callback(true)
         })
 
-        w.webContents.once('did-finish-load', function () {
+        w.webContents.once('did-finish-load', () => {
           assert.equal(w.webContents.getTitle(), 'hello')
           done()
         })
         w.loadURL(`https://127.0.0.1:${server.address().port}`)
       })
 
-      it('supports rejecting the request', function (done) {
-        session.defaultSession.setCertificateVerifyProc(function (hostname, certificate, callback) {
+      it('supports rejecting the request', (done) => {
+        session.defaultSession.setCertificateVerifyProc((hostname, certificate, callback) => {
           assert.equal(hostname, '127.0.0.1')
           callback(false)
         })
 
-        var url = `https://127.0.0.1:${server.address().port}`
-        w.webContents.once('did-finish-load', function () {
+        const url = `https://127.0.0.1:${server.address().port}`
+        w.webContents.once('did-finish-load', () => {
           assert.equal(w.webContents.getTitle(), url)
           done()
         })
@@ -614,8 +580,8 @@ describe('session module', function () {
       })
     })
 
-    it('rejects the request when the callback is called with -2', function (done) {
-      session.defaultSession.setCertificateVerifyProc(function ({hostname, certificate, verificationResult}, callback) {
+    it('rejects the request when the callback is called with -2', (done) => {
+      session.defaultSession.setCertificateVerifyProc(({hostname, certificate, verificationResult}, callback) => {
         assert.equal(hostname, '127.0.0.1')
         assert.equal(certificate.issuerName, 'Intermediate CA')
         assert.equal(certificate.subjectName, 'localhost')
@@ -630,8 +596,8 @@ describe('session module', function () {
         callback(-2)
       })
 
-      var url = `https://127.0.0.1:${server.address().port}`
-      w.webContents.once('did-finish-load', function () {
+      const url = `https://127.0.0.1:${server.address().port}`
+      w.webContents.once('did-finish-load', () => {
         assert.equal(w.webContents.getTitle(), url)
         done()
       })
@@ -639,8 +605,8 @@ describe('session module', function () {
     })
   })
 
-  describe('ses.createInterruptedDownload(options)', function () {
-    it('can create an interrupted download item', function (done) {
+  describe('ses.createInterruptedDownload(options)', () => {
+    it('can create an interrupted download item', (done) => {
       ipcRenderer.sendSync('set-download-option', true, false)
       const filePath = path.join(__dirname, 'fixtures', 'mock.pdf')
       const options = {
@@ -651,10 +617,10 @@ describe('session module', function () {
         length: 5242880
       }
       w.webContents.session.createInterruptedDownload(options)
-      ipcRenderer.once('download-created', function (event, state, urlChain,
+      ipcRenderer.once('download-created', (event, state, urlChain,
                                                      mimeType, receivedBytes,
                                                      totalBytes, filename,
-                                                     savePath) {
+                                                     savePath) => {
         assert.equal(state, 'interrupted')
         assert.deepEqual(urlChain, ['http://127.0.0.1/'])
         assert.equal(mimeType, 'application/pdf')
@@ -665,26 +631,22 @@ describe('session module', function () {
       })
     })
 
-    it('can be resumed', function (done) {
+    it('can be resumed', (done) => {
       const fixtures = path.join(__dirname, 'fixtures')
       const downloadFilePath = path.join(fixtures, 'logo.png')
-      const rangeServer = http.createServer(function (req, res) {
-        let options = {
-          root: fixtures
-        }
+      const rangeServer = http.createServer((req, res) => {
+        let options = { root: fixtures }
         send(req, req.url, options)
-        .on('error', function (error) {
-          done(error)
-        }).pipe(res)
+        .on('error', (error) => { done(error) }).pipe(res)
       })
       ipcRenderer.sendSync('set-download-option', true, false, downloadFilePath)
-      rangeServer.listen(0, '127.0.0.1', function () {
+      rangeServer.listen(0, '127.0.0.1', () => {
         const port = rangeServer.address().port
         const downloadUrl = `http://127.0.0.1:${port}/assets/logo.png`
-        const callback = function (event, state, url, mimeType,
+        const callback = (event, state, url, mimeType,
                                    receivedBytes, totalBytes, disposition,
                                    filename, savePath, urlChain,
-                                   lastModifiedTime, eTag) {
+                                   lastModifiedTime, eTag) => {
           if (state === 'cancelled') {
             const options = {
               path: savePath,
@@ -718,11 +680,11 @@ describe('session module', function () {
     })
   })
 
-  describe('ses.clearAuthCache(options[, callback])', function () {
-    it('can clear http auth info from cache', function (done) {
+  describe('ses.clearAuthCache(options[, callback])', () => {
+    it('can clear http auth info from cache', (done) => {
       const ses = session.fromPartition('auth-cache')
-      const server = http.createServer(function (req, res) {
-        var credentials = auth(req)
+      const server = http.createServer((req, res) => {
+        const credentials = auth(req)
         if (!credentials || credentials.name !== 'test' || credentials.pass !== 'test') {
           res.statusCode = 401
           res.setHeader('WWW-Authenticate', 'Basic realm="Restricted"')
@@ -731,7 +693,7 @@ describe('session module', function () {
           res.end('authenticated')
         }
       })
-      server.listen(0, '127.0.0.1', function () {
+      server.listen(0, '127.0.0.1', () => {
         const port = server.address().port
         function issueLoginRequest (attempt = 1) {
           if (attempt > 2) {
@@ -742,27 +704,25 @@ describe('session module', function () {
             url: `http://127.0.0.1:${port}`,
             session: ses
           })
-          request.on('login', function (info, callback) {
-            attempt++
+          request.on('login', (info, callback) => {
+            attempt += 1
             assert.equal(info.scheme, 'basic')
             assert.equal(info.realm, 'Restricted')
             callback('test', 'test')
           })
-          request.on('response', function (response) {
+          request.on('response', (response) => {
             let data = ''
             response.pause()
-            response.on('data', function (chunk) {
+            response.on('data', (chunk) => {
               data += chunk
             })
-            response.on('end', function () {
+            response.on('end', () => {
               assert.equal(data, 'authenticated')
-              ses.clearAuthCache({type: 'password'}, function () {
+              ses.clearAuthCache({type: 'password'}, () => {
                 issueLoginRequest(attempt)
               })
             })
-            response.on('error', function (error) {
-              done(error)
-            })
+            response.on('error', (error) => { done(error) })
             response.resume()
           })
           // Internal api to bypass cache for testing.
@@ -782,12 +742,12 @@ describe('session module', function () {
       })
 
       webview = new WebView()
-      webview.addEventListener('ipc-message', function (e) {
+      webview.addEventListener('ipc-message', (e) => {
         assert.equal(e.channel, 'message')
         assert.deepEqual(e.args, ['SecurityError'])
         done()
       })
-      webview.src = 'file://' + fixtures + '/pages/permissions/midi-sysex.html'
+      webview.src = `file://${fixtures}/pages/permissions/midi-sysex.html`
       webview.partition = 'permissionTest'
       webview.setAttribute('nodeintegration', 'on')
       document.body.appendChild(webview)

+ 61 - 67
spec/api-web-contents-spec.js

@@ -10,11 +10,11 @@ const {BrowserWindow, webContents, ipcMain, session} = remote
 
 const isCi = remote.getGlobal('isCi')
 
-describe('webContents module', function () {
+describe('webContents module', () => {
   const fixtures = path.resolve(__dirname, 'fixtures')
   let w
 
-  beforeEach(function () {
+  beforeEach(() => {
     w = new BrowserWindow({
       show: false,
       width: 400,
@@ -25,14 +25,12 @@ describe('webContents module', function () {
     })
   })
 
-  afterEach(function () {
-    return closeWindow(w).then(function () { w = null })
-  })
+  afterEach(() => closeWindow(w).then(() => { w = null }))
 
-  describe('getAllWebContents() API', function () {
-    it('returns an array of web contents', function (done) {
-      w.webContents.on('devtools-opened', function () {
-        const all = webContents.getAllWebContents().sort(function (a, b) {
+  describe('getAllWebContents() API', () => {
+    it('returns an array of web contents', (done) => {
+      w.webContents.on('devtools-opened', () => {
+        const all = webContents.getAllWebContents().sort((a, b) => {
           return a.getId() - b.getId()
         })
 
@@ -44,24 +42,24 @@ describe('webContents module', function () {
         done()
       })
 
-      w.loadURL('file://' + path.join(fixtures, 'pages', 'webview-zoom-factor.html'))
+      w.loadURL(`file://${path.join(fixtures, 'pages', 'webview-zoom-factor.html')}`)
       w.webContents.openDevTools()
     })
   })
 
-  describe('getFocusedWebContents() API', function () {
-    it('returns the focused web contents', function (done) {
+  describe('getFocusedWebContents() API', () => {
+    it('returns the focused web contents', (done) => {
       if (isCi) return done()
 
       const specWebContents = remote.getCurrentWebContents()
       assert.equal(specWebContents.getId(), webContents.getFocusedWebContents().getId())
 
-      specWebContents.once('devtools-opened', function () {
+      specWebContents.once('devtools-opened', () => {
         assert.equal(specWebContents.devToolsWebContents.getId(), webContents.getFocusedWebContents().getId())
         specWebContents.closeDevTools()
       })
 
-      specWebContents.once('devtools-closed', function () {
+      specWebContents.once('devtools-closed', () => {
         assert.equal(specWebContents.getId(), webContents.getFocusedWebContents().getId())
         done()
       })
@@ -69,18 +67,18 @@ describe('webContents module', function () {
       specWebContents.openDevTools()
     })
 
-    it('does not crash when called on a detached dev tools window', function (done) {
+    it('does not crash when called on a detached dev tools window', (done) => {
       const specWebContents = w.webContents
 
-      specWebContents.once('devtools-opened', function () {
-        assert.doesNotThrow(function () {
+      specWebContents.once('devtools-opened', () => {
+        assert.doesNotThrow(() => {
           webContents.getFocusedWebContents()
         })
         specWebContents.closeDevTools()
       })
 
-      specWebContents.once('devtools-closed', function () {
-        assert.doesNotThrow(function () {
+      specWebContents.once('devtools-closed', () => {
+        assert.doesNotThrow(() => {
           webContents.getFocusedWebContents()
         })
         done()
@@ -91,9 +89,9 @@ describe('webContents module', function () {
     })
   })
 
-  describe('isFocused() API', function () {
-    it('returns false when the window is hidden', function () {
-      BrowserWindow.getAllWindows().forEach(function (window) {
+  describe('isFocused() API', () => {
+    it('returns false when the window is hidden', () => {
+      BrowserWindow.getAllWindows().forEach((window) => {
         assert.equal(!window.isVisible() && window.webContents.isFocused(), false)
       })
     })
@@ -101,7 +99,7 @@ describe('webContents module', function () {
 
   describe('before-input-event event', () => {
     it('can prevent document keyboard events', (done) => {
-      w.loadURL('file://' + path.join(__dirname, 'fixtures', 'pages', 'key-events.html'))
+      w.loadURL(`file://${path.join(__dirname, 'fixtures', 'pages', 'key-events.html')}`)
       w.webContents.once('did-finish-load', () => {
         ipcMain.once('keydown', (event, key) => {
           assert.equal(key, 'b')
@@ -115,7 +113,7 @@ describe('webContents module', function () {
     })
 
     it('has the correct properties', (done) => {
-      w.loadURL('file://' + path.join(__dirname, 'fixtures', 'pages', 'base-page.html'))
+      w.loadURL(`file://${path.join(__dirname, 'fixtures', 'pages', 'base-page.html')}`)
       w.webContents.once('did-finish-load', () => {
         const testBeforeInput = (opts) => {
           return new Promise((resolve, reject) => {
@@ -199,16 +197,14 @@ describe('webContents module', function () {
     })
   })
 
-  describe('sendInputEvent(event)', function () {
-    beforeEach(function (done) {
-      w.loadURL('file://' + path.join(__dirname, 'fixtures', 'pages', 'key-events.html'))
-      w.webContents.once('did-finish-load', function () {
-        done()
-      })
+  describe('sendInputEvent(event)', () => {
+    beforeEach((done) => {
+      w.loadURL(`file://${path.join(__dirname, 'fixtures', 'pages', 'key-events.html')}`)
+      w.webContents.once('did-finish-load', () => done())
     })
 
-    it('can send keydown events', function (done) {
-      ipcMain.once('keydown', function (event, key, code, keyCode, shiftKey, ctrlKey, altKey) {
+    it('can send keydown events', (done) => {
+      ipcMain.once('keydown', (event, key, code, keyCode, shiftKey, ctrlKey, altKey) => {
         assert.equal(key, 'a')
         assert.equal(code, 'KeyA')
         assert.equal(keyCode, 65)
@@ -220,8 +216,8 @@ describe('webContents module', function () {
       w.webContents.sendInputEvent({type: 'keyDown', keyCode: 'A'})
     })
 
-    it('can send keydown events with modifiers', function (done) {
-      ipcMain.once('keydown', function (event, key, code, keyCode, shiftKey, ctrlKey, altKey) {
+    it('can send keydown events with modifiers', (done) => {
+      ipcMain.once('keydown', (event, key, code, keyCode, shiftKey, ctrlKey, altKey) => {
         assert.equal(key, 'Z')
         assert.equal(code, 'KeyZ')
         assert.equal(keyCode, 90)
@@ -233,8 +229,8 @@ describe('webContents module', function () {
       w.webContents.sendInputEvent({type: 'keyDown', keyCode: 'Z', modifiers: ['shift', 'ctrl']})
     })
 
-    it('can send keydown events with special keys', function (done) {
-      ipcMain.once('keydown', function (event, key, code, keyCode, shiftKey, ctrlKey, altKey) {
+    it('can send keydown events with special keys', (done) => {
+      ipcMain.once('keydown', (event, key, code, keyCode, shiftKey, ctrlKey, altKey) => {
         assert.equal(key, 'Tab')
         assert.equal(code, 'Tab')
         assert.equal(keyCode, 9)
@@ -246,8 +242,8 @@ describe('webContents module', function () {
       w.webContents.sendInputEvent({type: 'keyDown', keyCode: 'Tab', modifiers: ['alt']})
     })
 
-    it('can send char events', function (done) {
-      ipcMain.once('keypress', function (event, key, code, keyCode, shiftKey, ctrlKey, altKey) {
+    it('can send char events', (done) => {
+      ipcMain.once('keypress', (event, key, code, keyCode, shiftKey, ctrlKey, altKey) => {
         assert.equal(key, 'a')
         assert.equal(code, 'KeyA')
         assert.equal(keyCode, 65)
@@ -260,8 +256,8 @@ describe('webContents module', function () {
       w.webContents.sendInputEvent({type: 'char', keyCode: 'A'})
     })
 
-    it('can send char events with modifiers', function (done) {
-      ipcMain.once('keypress', function (event, key, code, keyCode, shiftKey, ctrlKey, altKey) {
+    it('can send char events with modifiers', (done) => {
+      ipcMain.once('keypress', (event, key, code, keyCode, shiftKey, ctrlKey, altKey) => {
         assert.equal(key, 'Z')
         assert.equal(code, 'KeyZ')
         assert.equal(keyCode, 90)
@@ -275,7 +271,7 @@ describe('webContents module', function () {
     })
   })
 
-  it('supports inserting CSS', function (done) {
+  it('supports inserting CSS', (done) => {
     w.loadURL('about:blank')
     w.webContents.insertCSS('body { background-repeat: round; }')
     w.webContents.executeJavaScript('window.getComputedStyle(document.body).getPropertyValue("background-repeat")', (result) => {
@@ -284,9 +280,9 @@ describe('webContents module', function () {
     })
   })
 
-  it('supports inspecting an element in the devtools', function (done) {
+  it('supports inspecting an element in the devtools', (done) => {
     w.loadURL('about:blank')
-    w.webContents.once('devtools-opened', function () {
+    w.webContents.once('devtools-opened', () => {
       done()
     })
     w.webContents.inspectElement(10, 10)
@@ -310,22 +306,22 @@ describe('webContents module', function () {
     })
   })
 
-  describe('focus()', function () {
-    describe('when the web contents is hidden', function () {
-      it('does not blur the focused window', function (done) {
+  describe('focus()', () => {
+    describe('when the web contents is hidden', () => {
+      it('does not blur the focused window', (done) => {
         ipcMain.once('answer', (event, parentFocused, childFocused) => {
           assert.equal(parentFocused, true)
           assert.equal(childFocused, false)
           done()
         })
         w.show()
-        w.loadURL('file://' + path.join(__dirname, 'fixtures', 'pages', 'focus-web-contents.html'))
+        w.loadURL(`file://${path.join(__dirname, 'fixtures', 'pages', 'focus-web-contents.html')}`)
       })
     })
   })
 
-  describe('getOSProcessId()', function () {
-    it('returns a valid procress id', function (done) {
+  describe('getOSProcessId()', () => {
+    it('returns a valid procress id', (done) => {
       assert.strictEqual(w.webContents.getOSProcessId(), 0)
 
       w.webContents.once('did-finish-load', () => {
@@ -386,9 +382,7 @@ describe('webContents module', function () {
       let finalNavigation = false
       ipcMain.on('set-zoom', (e, host) => {
         const zoomLevel = hostZoomMap[host]
-        if (!finalNavigation) {
-          w.webContents.setZoomLevel(zoomLevel)
-        }
+        if (!finalNavigation) w.webContents.setZoomLevel(zoomLevel)
         e.sender.send(`${host}-zoom-set`)
       })
       ipcMain.on('host1-zoom-level', (e, zoomLevel) => {
@@ -467,12 +461,12 @@ describe('webContents module', function () {
     })
 
     it('can persist when it contains iframe', (done) => {
-      const server = http.createServer(function (req, res) {
+      const server = http.createServer((req, res) => {
         setTimeout(() => {
           res.end()
         }, 200)
       })
-      server.listen(0, '127.0.0.1', function () {
+      server.listen(0, '127.0.0.1', () => {
         const url = 'http://127.0.0.1:' + server.address().port
         const content = `<iframe src=${url}></iframe>`
         w.webContents.on('did-frame-finish-load', (e, isMainFrame) => {
@@ -557,12 +551,12 @@ describe('webContents module', function () {
     })
   })
 
-  describe('will-prevent-unload event', function () {
-    it('does not emit if beforeunload returns undefined', function (done) {
-      w.once('closed', function () {
+  describe('will-prevent-unload event', () => {
+    it('does not emit if beforeunload returns undefined', (done) => {
+      w.once('closed', () => {
         done()
       })
-      w.webContents.on('will-prevent-unload', function (e) {
+      w.webContents.on('will-prevent-unload', (e) => {
         assert.fail('should not have fired')
       })
       w.loadURL('file://' + path.join(fixtures, 'api', 'close-beforeunload-undefined.html'))
@@ -575,15 +569,15 @@ describe('webContents module', function () {
       w.loadURL('file://' + path.join(fixtures, 'api', 'close-beforeunload-false.html'))
     })
 
-    it('supports calling preventDefault on will-prevent-unload events', function (done) {
+    it('supports calling preventDefault on will-prevent-unload events', (done) => {
       ipcRenderer.send('prevent-next-will-prevent-unload', w.webContents.id)
       w.once('closed', () => done())
       w.loadURL('file://' + path.join(fixtures, 'api', 'close-beforeunload-false.html'))
     })
   })
 
-  describe('setIgnoreMenuShortcuts(ignore)', function () {
-    it('does not throw', function () {
+  describe('setIgnoreMenuShortcuts(ignore)', () => {
+    it('does not throw', () => {
       assert.equal(w.webContents.setIgnoreMenuShortcuts(true), undefined)
       assert.equal(w.webContents.setIgnoreMenuShortcuts(false), undefined)
     })
@@ -594,7 +588,7 @@ describe('webContents module', function () {
   xdescribe('destroy()', () => {
     let server
 
-    before(function (done) {
+    before((done) => {
       server = http.createServer((request, response) => {
         switch (request.url) {
           case '/404':
@@ -619,7 +613,7 @@ describe('webContents module', function () {
       })
     })
 
-    after(function () {
+    after(() => {
       server.close()
       server = null
     })
@@ -659,18 +653,18 @@ describe('webContents module', function () {
 
   describe('did-change-theme-color event', () => {
     it('is triggered with correct theme color', (done) => {
-      var count = 0
+      let count = 0
       w.webContents.on('did-change-theme-color', (e, color) => {
         if (count === 0) {
-          count++
+          count += 1
           assert.equal(color, '#FFEEDD')
-          w.loadURL('file://' + path.join(__dirname, 'fixtures', 'pages', 'base-page.html'))
+          w.loadURL(`file://${path.join(__dirname, 'fixtures', 'pages', 'base-page.html')}`)
         } else if (count === 1) {
           assert.equal(color, null)
           done()
         }
       })
-      w.loadURL('file://' + path.join(__dirname, 'fixtures', 'pages', 'theme-color.html'))
+      w.loadURL(`file://${path.join(__dirname, 'fixtures', 'pages', 'theme-color.html')}`)
     })
   })
 })

+ 121 - 180
spec/api-web-request-spec.js

@@ -4,89 +4,79 @@ const qs = require('querystring')
 const remote = require('electron').remote
 const session = remote.session
 
-describe('webRequest module', function () {
-  var ses = session.defaultSession
-  var server = http.createServer(function (req, res) {
+describe('webRequest module', () => {
+  const ses = session.defaultSession
+  const server = http.createServer((req, res) => {
     if (req.url === '/serverRedirect') {
       res.statusCode = 301
       res.setHeader('Location', 'http://' + req.rawHeaders[1])
       res.end()
     } else {
       res.setHeader('Custom', ['Header'])
-      var content = req.url
+      let content = req.url
       if (req.headers.accept === '*/*;test/header') {
         content += 'header/received'
       }
       res.end(content)
     }
   })
-  var defaultURL = null
+  let defaultURL = null
 
-  before(function (done) {
-    server.listen(0, '127.0.0.1', function () {
-      var port = server.address().port
+  before((done) => {
+    server.listen(0, '127.0.0.1', () => {
+      const port = server.address().port
       defaultURL = 'http://127.0.0.1:' + port + '/'
       done()
     })
   })
 
-  after(function () {
+  after(() => {
     server.close()
   })
 
-  describe('webRequest.onBeforeRequest', function () {
-    afterEach(function () {
+  describe('webRequest.onBeforeRequest', () => {
+    afterEach(() => {
       ses.webRequest.onBeforeRequest(null)
     })
 
-    it('can cancel the request', function (done) {
-      ses.webRequest.onBeforeRequest(function (details, callback) {
+    it('can cancel the request', (done) => {
+      ses.webRequest.onBeforeRequest((details, callback) => {
         callback({
           cancel: true
         })
       })
       $.ajax({
         url: defaultURL,
-        success: function () {
+        success: () => {
           done('unexpected success')
         },
-        error: function () {
+        error: () => {
           done()
         }
       })
     })
 
-    it('can filter URLs', function (done) {
-      var filter = {
-        urls: [defaultURL + 'filter/*']
-      }
-      ses.webRequest.onBeforeRequest(filter, function (details, callback) {
-        callback({
-          cancel: true
-        })
+    it('can filter URLs', (done) => {
+      const filter = { urls: [defaultURL + 'filter/*'] }
+      ses.webRequest.onBeforeRequest(filter, (details, callback) => {
+        callback({cancel: true})
       })
       $.ajax({
-        url: defaultURL + 'nofilter/test',
-        success: function (data) {
+        url: `${defaultURL}nofilter/test`,
+        success: (data) => {
           assert.equal(data, '/nofilter/test')
           $.ajax({
-            url: defaultURL + 'filter/test',
-            success: function () {
-              done('unexpected success')
-            },
-            error: function () {
-              done()
-            }
+            url: `${defaultURL}filter/test`,
+            success: () => done('unexpected success'),
+            error: () => done()
           })
         },
-        error: function (xhr, errorType) {
-          done(errorType)
-        }
+        error: (xhr, errorType) => done(errorType)
       })
     })
 
-    it('receives details object', function (done) {
-      ses.webRequest.onBeforeRequest(function (details, callback) {
+    it('receives details object', (done) => {
+      ses.webRequest.onBeforeRequest((details, callback) => {
         assert.equal(typeof details.id, 'number')
         assert.equal(typeof details.timestamp, 'number')
         assert.equal(typeof details.webContentsId, 'number')
@@ -98,162 +88,138 @@ describe('webRequest module', function () {
       })
       $.ajax({
         url: defaultURL,
-        success: function (data) {
+        success: (data) => {
           assert.equal(data, '/')
           done()
         },
-        error: function (xhr, errorType) {
-          done(errorType)
-        }
+        error: (xhr, errorType) => done(errorType)
       })
     })
 
-    it('receives post data in details object', function (done) {
-      var postData = {
+    it('receives post data in details object', (done) => {
+      const postData = {
         name: 'post test',
         type: 'string'
       }
-      ses.webRequest.onBeforeRequest(function (details, callback) {
+      ses.webRequest.onBeforeRequest((details, callback) => {
         assert.equal(details.url, defaultURL)
         assert.equal(details.method, 'POST')
         assert.equal(details.uploadData.length, 1)
-        var data = qs.parse(details.uploadData[0].bytes.toString())
+        const data = qs.parse(details.uploadData[0].bytes.toString())
         assert.deepEqual(data, postData)
-        callback({
-          cancel: true
-        })
+        callback({ cancel: true })
       })
       $.ajax({
         url: defaultURL,
         type: 'POST',
         data: postData,
-        success: function () {},
-        error: function () {
-          done()
-        }
+        success: () => {},
+        error: () => done()
       })
     })
 
-    it('can redirect the request', function (done) {
-      ses.webRequest.onBeforeRequest(function (details, callback) {
+    it('can redirect the request', (done) => {
+      ses.webRequest.onBeforeRequest((details, callback) => {
         if (details.url === defaultURL) {
-          callback({
-            redirectURL: defaultURL + 'redirect'
-          })
+          callback({ redirectURL: `${defaultURL}redirect` })
         } else {
           callback({})
         }
       })
       $.ajax({
         url: defaultURL,
-        success: function (data) {
+        success: (data) => {
           assert.equal(data, '/redirect')
           done()
         },
-        error: function (xhr, errorType) {
-          done(errorType)
-        }
+        error: (xhr, errorType) => done(errorType)
       })
     })
   })
 
-  describe('webRequest.onBeforeSendHeaders', function () {
-    afterEach(function () {
+  describe('webRequest.onBeforeSendHeaders', () => {
+    afterEach(() => {
       ses.webRequest.onBeforeSendHeaders(null)
     })
 
-    it('receives details object', function (done) {
-      ses.webRequest.onBeforeSendHeaders(function (details, callback) {
+    it('receives details object', (done) => {
+      ses.webRequest.onBeforeSendHeaders((details, callback) => {
         assert.equal(typeof details.requestHeaders, 'object')
         assert.equal(details.requestHeaders['Foo.Bar'], 'baz')
         callback({})
       })
       $.ajax({
         url: defaultURL,
-        headers: {
-          'Foo.Bar': 'baz'
-        },
-        success: function (data) {
+        headers: { 'Foo.Bar': 'baz' },
+        success: (data) => {
           assert.equal(data, '/')
           done()
         },
-        error: function (xhr, errorType) {
-          done(errorType)
-        }
+        error: (xhr, errorType) => done(errorType)
       })
     })
 
-    it('can change the request headers', function (done) {
-      ses.webRequest.onBeforeSendHeaders(function (details, callback) {
-        var requestHeaders = details.requestHeaders
+    it('can change the request headers', (done) => {
+      ses.webRequest.onBeforeSendHeaders((details, callback) => {
+        const requestHeaders = details.requestHeaders
         requestHeaders.Accept = '*/*;test/header'
-        callback({
-          requestHeaders: requestHeaders
-        })
+        callback({ requestHeaders: requestHeaders })
       })
       $.ajax({
         url: defaultURL,
-        success: function (data) {
+        success: (data) => {
           assert.equal(data, '/header/received')
           done()
         },
-        error: function (xhr, errorType) {
-          done(errorType)
-        }
+        error: (xhr, errorType) => done(errorType)
       })
     })
 
-    it('resets the whole headers', function (done) {
-      var requestHeaders = {
+    it('resets the whole headers', (done) => {
+      const requestHeaders = {
         Test: 'header'
       }
-      ses.webRequest.onBeforeSendHeaders(function (details, callback) {
-        callback({
-          requestHeaders: requestHeaders
-        })
+      ses.webRequest.onBeforeSendHeaders((details, callback) => {
+        callback({ requestHeaders: requestHeaders })
       })
-      ses.webRequest.onSendHeaders(function (details) {
+      ses.webRequest.onSendHeaders((details) => {
         assert.deepEqual(details.requestHeaders, requestHeaders)
         done()
       })
       $.ajax({
         url: defaultURL,
-        error: function (xhr, errorType) {
-          done(errorType)
-        }
+        error: (xhr, errorType) => done(errorType)
       })
     })
   })
 
-  describe('webRequest.onSendHeaders', function () {
-    afterEach(function () {
+  describe('webRequest.onSendHeaders', () => {
+    afterEach(() => {
       ses.webRequest.onSendHeaders(null)
     })
 
-    it('receives details object', function (done) {
-      ses.webRequest.onSendHeaders(function (details) {
+    it('receives details object', (done) => {
+      ses.webRequest.onSendHeaders((details) => {
         assert.equal(typeof details.requestHeaders, 'object')
       })
       $.ajax({
         url: defaultURL,
-        success: function (data) {
+        success: (data) => {
           assert.equal(data, '/')
           done()
         },
-        error: function (xhr, errorType) {
-          done(errorType)
-        }
+        error: (xhr, errorType) => done(errorType)
       })
     })
   })
 
-  describe('webRequest.onHeadersReceived', function () {
-    afterEach(function () {
+  describe('webRequest.onHeadersReceived', () => {
+    afterEach(() => {
       ses.webRequest.onHeadersReceived(null)
     })
 
-    it('receives details object', function (done) {
-      ses.webRequest.onHeadersReceived(function (details, callback) {
+    it('receives details object', (done) => {
+      ses.webRequest.onHeadersReceived((details, callback) => {
         assert.equal(details.statusLine, 'HTTP/1.1 200 OK')
         assert.equal(details.statusCode, 200)
         assert.equal(details.responseHeaders['Custom'], 'Header')
@@ -261,76 +227,64 @@ describe('webRequest module', function () {
       })
       $.ajax({
         url: defaultURL,
-        success: function (data) {
+        success: (data) => {
           assert.equal(data, '/')
           done()
         },
-        error: function (xhr, errorType) {
-          done(errorType)
-        }
+        error: (xhr, errorType) => done(errorType)
       })
     })
 
-    it('can change the response header', function (done) {
-      ses.webRequest.onHeadersReceived(function (details, callback) {
-        var responseHeaders = details.responseHeaders
+    it('can change the response header', (done) => {
+      ses.webRequest.onHeadersReceived((details, callback) => {
+        const responseHeaders = details.responseHeaders
         responseHeaders['Custom'] = ['Changed']
-        callback({
-          responseHeaders: responseHeaders
-        })
+        callback({ responseHeaders: responseHeaders })
       })
       $.ajax({
         url: defaultURL,
-        success: function (data, status, xhr) {
+        success: (data, status, xhr) => {
           assert.equal(xhr.getResponseHeader('Custom'), 'Changed')
           assert.equal(data, '/')
           done()
         },
-        error: function (xhr, errorType) {
-          done(errorType)
-        }
+        error: (xhr, errorType) => done(errorType)
       })
     })
 
-    it('does not change header by default', function (done) {
-      ses.webRequest.onHeadersReceived(function (details, callback) {
+    it('does not change header by default', (done) => {
+      ses.webRequest.onHeadersReceived((details, callback) => {
         callback({})
       })
       $.ajax({
         url: defaultURL,
-        success: function (data, status, xhr) {
+        success: (data, status, xhr) => {
           assert.equal(xhr.getResponseHeader('Custom'), 'Header')
           assert.equal(data, '/')
           done()
         },
-        error: function (xhr, errorType) {
-          done(errorType)
-        }
+        error: (xhr, errorType) => done(errorType)
       })
     })
 
-    it('follows server redirect', function (done) {
-      ses.webRequest.onHeadersReceived(function (details, callback) {
-        var responseHeaders = details.responseHeaders
-        callback({
-          responseHeaders: responseHeaders
-        })
+    it('follows server redirect', (done) => {
+      ses.webRequest.onHeadersReceived((details, callback) => {
+        const responseHeaders = details.responseHeaders
+        callback({ responseHeaders: responseHeaders })
       })
       $.ajax({
         url: defaultURL + 'serverRedirect',
-        success: function (data, status, xhr) {
+        success: (data, status, xhr) => {
           assert.equal(xhr.getResponseHeader('Custom'), 'Header')
           done()
         },
-        error: function (xhr, errorType) {
-          done(errorType)
-        }
+        error: (xhr, errorType) => done(errorType)
       })
     })
 
-    it('can change the header status', function (done) {
-      ses.webRequest.onHeadersReceived(function (details, callback) {
-        var responseHeaders = details.responseHeaders
+    it('can change the header status', (done) => {
+      ses.webRequest.onHeadersReceived((details, callback) => {
+        const responseHeaders = details.responseHeaders
         callback({
           responseHeaders: responseHeaders,
           statusLine: 'HTTP/1.1 404 Not Found'
@@ -338,9 +292,8 @@ describe('webRequest module', function () {
       })
       $.ajax({
         url: defaultURL,
-        success: function (data, status, xhr) {
-        },
-        error: function (xhr, errorType) {
+        success: (data, status, xhr) => {},
+        error: (xhr, errorType) => {
           assert.equal(xhr.getResponseHeader('Custom'), 'Header')
           done()
         }
@@ -348,13 +301,13 @@ describe('webRequest module', function () {
     })
   })
 
-  describe('webRequest.onResponseStarted', function () {
-    afterEach(function () {
+  describe('webRequest.onResponseStarted', () => {
+    afterEach(() => {
       ses.webRequest.onResponseStarted(null)
     })
 
-    it('receives details object', function (done) {
-      ses.webRequest.onResponseStarted(function (details) {
+    it('receives details object', (done) => {
+      ses.webRequest.onResponseStarted((details) => {
         assert.equal(typeof details.fromCache, 'boolean')
         assert.equal(details.statusLine, 'HTTP/1.1 200 OK')
         assert.equal(details.statusCode, 200)
@@ -362,36 +315,32 @@ describe('webRequest module', function () {
       })
       $.ajax({
         url: defaultURL,
-        success: function (data, status, xhr) {
+        success: (data, status, xhr) => {
           assert.equal(xhr.getResponseHeader('Custom'), 'Header')
           assert.equal(data, '/')
           done()
         },
-        error: function (xhr, errorType) {
-          done(errorType)
-        }
+        error: (xhr, errorType) => done(errorType)
       })
     })
   })
 
-  describe('webRequest.onBeforeRedirect', function () {
-    afterEach(function () {
+  describe('webRequest.onBeforeRedirect', () => {
+    afterEach(() => {
       ses.webRequest.onBeforeRedirect(null)
       ses.webRequest.onBeforeRequest(null)
     })
 
-    it('receives details object', function (done) {
-      var redirectURL = defaultURL + 'redirect'
-      ses.webRequest.onBeforeRequest(function (details, callback) {
+    it('receives details object', (done) => {
+      const redirectURL = defaultURL + 'redirect'
+      ses.webRequest.onBeforeRequest((details, callback) => {
         if (details.url === defaultURL) {
-          callback({
-            redirectURL: redirectURL
-          })
+          callback({ redirectURL: redirectURL })
         } else {
           callback({})
         }
       })
-      ses.webRequest.onBeforeRedirect(function (details) {
+      ses.webRequest.onBeforeRedirect((details) => {
         assert.equal(typeof details.fromCache, 'boolean')
         assert.equal(details.statusLine, 'HTTP/1.1 307 Internal Redirect')
         assert.equal(details.statusCode, 307)
@@ -399,62 +348,54 @@ describe('webRequest module', function () {
       })
       $.ajax({
         url: defaultURL,
-        success: function (data) {
+        success: (data) => {
           assert.equal(data, '/redirect')
           done()
         },
-        error: function (xhr, errorType) {
-          done(errorType)
-        }
+        error: (xhr, errorType) => done(errorType)
       })
     })
   })
 
-  describe('webRequest.onCompleted', function () {
-    afterEach(function () {
+  describe('webRequest.onCompleted', () => {
+    afterEach(() => {
       ses.webRequest.onCompleted(null)
     })
 
-    it('receives details object', function (done) {
-      ses.webRequest.onCompleted(function (details) {
+    it('receives details object', (done) => {
+      ses.webRequest.onCompleted((details) => {
         assert.equal(typeof details.fromCache, 'boolean')
         assert.equal(details.statusLine, 'HTTP/1.1 200 OK')
         assert.equal(details.statusCode, 200)
       })
       $.ajax({
         url: defaultURL,
-        success: function (data) {
+        success: (data) => {
           assert.equal(data, '/')
           done()
         },
-        error: function (xhr, errorType) {
-          done(errorType)
-        }
+        error: (xhr, errorType) => done(errorType)
       })
     })
   })
 
-  describe('webRequest.onErrorOccurred', function () {
-    afterEach(function () {
+  describe('webRequest.onErrorOccurred', () => {
+    afterEach(() => {
       ses.webRequest.onErrorOccurred(null)
       ses.webRequest.onBeforeRequest(null)
     })
 
-    it('receives details object', function (done) {
-      ses.webRequest.onBeforeRequest(function (details, callback) {
-        callback({
-          cancel: true
-        })
+    it('receives details object', (done) => {
+      ses.webRequest.onBeforeRequest((details, callback) => {
+        callback({ cancel: true })
       })
-      ses.webRequest.onErrorOccurred(function (details) {
+      ses.webRequest.onErrorOccurred((details) => {
         assert.equal(details.error, 'net::ERR_BLOCKED_BY_CLIENT')
         done()
       })
       $.ajax({
         url: defaultURL,
-        success: function () {
-          done('unexpected success')
-        }
+        success: () => done('unexpected success')
       })
     })
   })

File diff suppressed because it is too large
+ 232 - 266
spec/chromium-spec.js


+ 35 - 37
spec/modules-spec.js

@@ -7,45 +7,45 @@ const {closeWindow} = require('./window-helpers')
 
 const nativeModulesEnabled = remote.getGlobal('nativeModulesEnabled')
 
-describe('modules support', function () {
-  var fixtures = path.join(__dirname, 'fixtures')
+describe('modules support', () => {
+  const fixtures = path.join(__dirname, 'fixtures')
 
-  describe('third-party module', function () {
-    describe('runas', function () {
+  describe('third-party module', () => {
+    describe('runas', () => {
       if (!nativeModulesEnabled) return
 
-      it('can be required in renderer', function () {
+      it('can be required in renderer', () => {
         require('runas')
       })
 
-      it('can be required in node binary', function (done) {
-        var runas = path.join(fixtures, 'module', 'runas.js')
-        var child = require('child_process').fork(runas)
-        child.on('message', function (msg) {
+      it('can be required in node binary', (done) => {
+        const runas = path.join(fixtures, 'module', 'runas.js')
+        const child = require('child_process').fork(runas)
+        child.on('message', (msg) => {
           assert.equal(msg, 'ok')
           done()
         })
       })
     })
 
-    describe('ffi', function () {
+    describe('ffi', () => {
       if (!nativeModulesEnabled) return
       if (process.platform === 'win32') return
 
-      it('does not crash', function () {
-        var ffi = require('ffi')
-        var libm = ffi.Library('libm', {
+      it('does not crash', () => {
+        const ffi = require('ffi')
+        const libm = ffi.Library('libm', {
           ceil: ['double', ['double']]
         })
         assert.equal(libm.ceil(1.5), 2)
       })
     })
 
-    describe('q', function () {
-      var Q = require('q')
-      describe('Q.when', function () {
-        it('emits the fullfil callback', function (done) {
-          Q(true).then(function (val) {
+    describe('q', () => {
+      const Q = require('q')
+      describe('Q.when', () => {
+        it('emits the fullfil callback', (done) => {
+          Q(true).then((val) => {
             assert.equal(val, true)
             done()
           })
@@ -53,9 +53,9 @@ describe('modules support', function () {
       })
     })
 
-    describe('coffee-script', function () {
-      it('can be registered and used to require .coffee files', function () {
-        assert.doesNotThrow(function () {
+    describe('coffee-script', () => {
+      it('can be registered and used to require .coffee files', () => {
+        assert.doesNotThrow(() => {
           require('coffee-script').register()
         })
         assert.strictEqual(require('./fixtures/module/test.coffee'), true)
@@ -63,36 +63,36 @@ describe('modules support', function () {
     })
   })
 
-  describe('global variables', function () {
-    describe('process', function () {
-      it('can be declared in a module', function () {
+  describe('global variables', () => {
+    describe('process', () => {
+      it('can be declared in a module', () => {
         assert.strictEqual(require('./fixtures/module/declare-process'), 'declared process')
       })
     })
 
-    describe('global', function () {
-      it('can be declared in a module', function () {
+    describe('global', () => {
+      it('can be declared in a module', () => {
         assert.strictEqual(require('./fixtures/module/declare-global'), 'declared global')
       })
     })
 
-    describe('Buffer', function () {
-      it('can be declared in a module', function () {
+    describe('Buffer', () => {
+      it('can be declared in a module', () => {
         assert.strictEqual(require('./fixtures/module/declare-buffer'), 'declared Buffer')
       })
     })
   })
 
-  describe('Module._nodeModulePaths', function () {
-    describe('when the path is inside the resources path', function () {
-      it('does not include paths outside of the resources path', function () {
+  describe('Module._nodeModulePaths', () => {
+    describe('when the path is inside the resources path', () => {
+      it('does not include paths outside of the resources path', () => {
         let modulePath = process.resourcesPath
         assert.deepEqual(Module._nodeModulePaths(modulePath), [
           path.join(process.resourcesPath, 'node_modules')
         ])
 
         modulePath = process.resourcesPath + '-foo'
-        let nodeModulePaths = Module._nodeModulePaths(modulePath)
+        const nodeModulePaths = Module._nodeModulePaths(modulePath)
         assert(nodeModulePaths.includes(path.join(modulePath, 'node_modules')))
         assert(nodeModulePaths.includes(path.join(modulePath, '..', 'node_modules')))
 
@@ -124,8 +124,8 @@ describe('modules support', function () {
       })
     })
 
-    describe('when the path is outside the resources path', function () {
-      it('includes paths outside of the resources path', function () {
+    describe('when the path is outside the resources path', () => {
+      it('includes paths outside of the resources path', () => {
         let modulePath = path.resolve('/foo')
         assert.deepEqual(Module._nodeModulePaths(modulePath), [
           path.join(modulePath, 'node_modules'),
@@ -140,9 +140,7 @@ describe('modules support', function () {
       let w
 
       beforeEach(() => {
-        w = new BrowserWindow({
-          show: false
-        })
+        w = new BrowserWindow({show: false})
       })
 
       afterEach(async () => {

+ 102 - 110
spec/node-spec.js

@@ -7,80 +7,80 @@ const {ipcRenderer, remote} = require('electron')
 
 const isCI = remote.getGlobal('isCi')
 
-describe('node feature', function () {
-  var fixtures = path.join(__dirname, 'fixtures')
-
-  describe('child_process', function () {
-    describe('child_process.fork', function () {
-      it('works in current process', function (done) {
-        var child = ChildProcess.fork(path.join(fixtures, 'module', 'ping.js'))
-        child.on('message', function (msg) {
+describe('node feature', () => {
+  const fixtures = path.join(__dirname, 'fixtures')
+
+  describe('child_process', () => {
+    describe('child_process.fork', () => {
+      it('works in current process', (done) => {
+        const child = ChildProcess.fork(path.join(fixtures, 'module', 'ping.js'))
+        child.on('message', (msg) => {
           assert.equal(msg, 'message')
           done()
         })
         child.send('message')
       })
 
-      it('preserves args', function (done) {
-        var args = ['--expose_gc', '-test', '1']
-        var child = ChildProcess.fork(path.join(fixtures, 'module', 'process_args.js'), args)
-        child.on('message', function (msg) {
+      it('preserves args', (done) => {
+        const args = ['--expose_gc', '-test', '1']
+        const child = ChildProcess.fork(path.join(fixtures, 'module', 'process_args.js'), args)
+        child.on('message', (msg) => {
           assert.deepEqual(args, msg.slice(2))
           done()
         })
         child.send('message')
       })
 
-      it('works in forked process', function (done) {
-        var child = ChildProcess.fork(path.join(fixtures, 'module', 'fork_ping.js'))
-        child.on('message', function (msg) {
+      it('works in forked process', (done) => {
+        const child = ChildProcess.fork(path.join(fixtures, 'module', 'fork_ping.js'))
+        child.on('message', (msg) => {
           assert.equal(msg, 'message')
           done()
         })
         child.send('message')
       })
 
-      it('works in forked process when options.env is specifed', function (done) {
-        var child = ChildProcess.fork(path.join(fixtures, 'module', 'fork_ping.js'), [], {
+      it('works in forked process when options.env is specifed', (done) => {
+        const child = ChildProcess.fork(path.join(fixtures, 'module', 'fork_ping.js'), [], {
           path: process.env['PATH']
         })
-        child.on('message', function (msg) {
+        child.on('message', (msg) => {
           assert.equal(msg, 'message')
           done()
         })
         child.send('message')
       })
 
-      it('works in browser process', function (done) {
-        var fork = remote.require('child_process').fork
-        var child = fork(path.join(fixtures, 'module', 'ping.js'))
-        child.on('message', function (msg) {
+      it('works in browser process', (done) => {
+        const fork = remote.require('child_process').fork
+        const child = fork(path.join(fixtures, 'module', 'ping.js'))
+        child.on('message', (msg) => {
           assert.equal(msg, 'message')
           done()
         })
         child.send('message')
       })
 
-      it('has String::localeCompare working in script', function (done) {
-        var child = ChildProcess.fork(path.join(fixtures, 'module', 'locale-compare.js'))
-        child.on('message', function (msg) {
+      it('has String::localeCompare working in script', (done) => {
+        const child = ChildProcess.fork(path.join(fixtures, 'module', 'locale-compare.js'))
+        child.on('message', (msg) => {
           assert.deepEqual(msg, [0, -1, 1])
           done()
         })
         child.send('message')
       })
 
-      it('has setImmediate working in script', function (done) {
-        var child = ChildProcess.fork(path.join(fixtures, 'module', 'set-immediate.js'))
-        child.on('message', function (msg) {
+      it('has setImmediate working in script', (done) => {
+        const child = ChildProcess.fork(path.join(fixtures, 'module', 'set-immediate.js'))
+        child.on('message', (msg) => {
           assert.equal(msg, 'ok')
           done()
         })
         child.send('message')
       })
 
-      it('pipes stdio', function (done) {
-        let child = ChildProcess.fork(path.join(fixtures, 'module', 'process-stdout.js'), {silent: true})
+      it('pipes stdio', (done) => {
+        const child = ChildProcess.fork(path.join(fixtures, 'module', 'process-stdout.js'), {silent: true})
         let data = ''
         child.stdout.on('data', (chunk) => {
           data += String(chunk)
@@ -92,7 +92,7 @@ describe('node feature', function () {
         })
       })
 
-      it('works when sending a message to a process forked with the --eval argument', function (done) {
+      it('works when sending a message to a process forked with the --eval argument', (done) => {
         const source = "process.on('message', (message) => { process.send(message) })"
         const forked = ChildProcess.fork('--eval', [source])
         forked.once('message', (message) => {
@@ -103,16 +103,14 @@ describe('node feature', function () {
       })
     })
 
-    describe('child_process.spawn', function () {
+    describe('child_process.spawn', () => {
       let child
 
-      afterEach(function () {
-        if (child != null) {
-          child.kill()
-        }
+      afterEach(() => {
+        if (child != null) child.kill()
       })
 
-      it('supports spawning Electron as a node process via the ELECTRON_RUN_AS_NODE env var', function (done) {
+      it('supports spawning Electron as a node process via the ELECTRON_RUN_AS_NODE env var', (done) => {
         child = ChildProcess.spawn(process.execPath, [path.join(__dirname, 'fixtures', 'module', 'run-as-node.js')], {
           env: {
             ELECTRON_RUN_AS_NODE: true
@@ -120,10 +118,10 @@ describe('node feature', function () {
         })
 
         let output = ''
-        child.stdout.on('data', function (data) {
+        child.stdout.on('data', (data) => {
           output += data
         })
-        child.stdout.on('close', function () {
+        child.stdout.on('close', () => {
           assert.deepEqual(JSON.parse(output), {
             processLog: process.platform === 'win32' ? 'function' : 'undefined',
             processType: 'undefined',
@@ -133,7 +131,7 @@ describe('node feature', function () {
         })
       })
 
-      it('supports starting the v8 inspector with --inspect/--inspect-brk', function (done) {
+      it('supports starting the v8 inspector with --inspect/--inspect-brk', (done) => {
         child = ChildProcess.spawn(process.execPath, ['--inspect-brk', path.join(__dirname, 'fixtures', 'module', 'run-as-node.js')], {
           env: {
             ELECTRON_RUN_AS_NODE: true
@@ -141,36 +139,31 @@ describe('node feature', function () {
         })
 
         let output = ''
-        child.stderr.on('data', function (data) {
+        child.stderr.on('data', (data) => {
           output += data
-
-          if (output.trim().startsWith('Debugger listening on ws://')) {
-            done()
-          }
+          if (output.trim().startsWith('Debugger listening on ws://')) done()
         })
 
-        child.stdout.on('data', function (data) {
+        child.stdout.on('data', (data) => {
           done(new Error(`Unexpected output: ${data.toString()}`))
         })
       })
     })
   })
 
-  describe('contexts', function () {
-    describe('setTimeout in fs callback', function () {
-      if (process.env.TRAVIS === 'true') {
-        return
-      }
+  describe('contexts', () => {
+    describe('setTimeout in fs callback', () => {
+      if (process.env.TRAVIS === 'true') return
 
-      it('does not crash', function (done) {
-        fs.readFile(__filename, function () {
+      it('does not crash', (done) => {
+        fs.readFile(__filename, () => {
           setTimeout(done, 0)
         })
       })
     })
 
-    describe('error thrown in renderer process node context', function () {
-      it('gets emitted as a process uncaughtException event', function (done) {
+    describe('error thrown in renderer process node context', () => {
+      it('gets emitted as a process uncaughtException event', (done) => {
         const error = new Error('boo!')
         const listeners = process.listeners('uncaughtException')
         process.removeAllListeners('uncaughtException')
@@ -188,30 +181,31 @@ describe('node feature', function () {
       })
     })
 
-    describe('error thrown in main process node context', function () {
-      it('gets emitted as a process uncaughtException event', function () {
+    describe('error thrown in main process node context', () => {
+      it('gets emitted as a process uncaughtException event', () => {
         const error = ipcRenderer.sendSync('handle-uncaught-exception', 'hello')
         assert.equal(error, 'hello')
       })
     })
 
-    describe('promise rejection in main process node context', function () {
-      it('gets emitted as a process unhandledRejection event', function () {
+    describe('promise rejection in main process node context', () => {
+      it('gets emitted as a process unhandledRejection event', () => {
         const error = ipcRenderer.sendSync('handle-unhandled-rejection', 'hello')
         assert.equal(error, 'hello')
       })
     })
 
-    describe('setTimeout called under Chromium event loop in browser process', function () {
-      it('can be scheduled in time', function (done) {
+    describe('setTimeout called under Chromium event loop in browser process', () => {
+      it('can be scheduled in time', (done) => {
         remote.getGlobal('setTimeout')(done, 0)
       })
     })
 
-    describe('setInterval called under Chromium event loop in browser process', function () {
-      it('can be scheduled in time', function (done) {
-        var clear, interval
-        clear = function () {
+    describe('setInterval called under Chromium event loop in browser process', () => {
+      it('can be scheduled in time', (done) => {
+        let clear
+        let interval
+        clear = () => {
           remote.getGlobal('clearInterval')(interval)
           done()
         }
@@ -220,29 +214,29 @@ describe('node feature', function () {
     })
   })
 
-  describe('message loop', function () {
-    describe('process.nextTick', function () {
-      it('emits the callback', function (done) {
+  describe('message loop', () => {
+    describe('process.nextTick', () => {
+      it('emits the callback', (done) => {
         process.nextTick(done)
       })
 
-      it('works in nested calls', function (done) {
-        process.nextTick(function () {
-          process.nextTick(function () {
+      it('works in nested calls', (done) => {
+        process.nextTick(() => {
+          process.nextTick(() => {
             process.nextTick(done)
           })
         })
       })
     })
 
-    describe('setImmediate', function () {
-      it('emits the callback', function (done) {
+    describe('setImmediate', () => {
+      it('emits the callback', (done) => {
         setImmediate(done)
       })
 
-      it('works in nested calls', function (done) {
-        setImmediate(function () {
-          setImmediate(function () {
+      it('works in nested calls', (done) => {
+        setImmediate(() => {
+          setImmediate(() => {
             setImmediate(done)
           })
         })
@@ -250,19 +244,17 @@ describe('node feature', function () {
     })
   })
 
-  describe('net.connect', function () {
-    if (process.platform !== 'darwin') {
-      return
-    }
+  describe('net.connect', () => {
+    if (process.platform !== 'darwin') return
 
-    it('emit error when connect to a socket path without listeners', function (done) {
-      var socketPath = path.join(os.tmpdir(), 'atom-shell-test.sock')
-      var script = path.join(fixtures, 'module', 'create_socket.js')
-      var child = ChildProcess.fork(script, [socketPath])
-      child.on('exit', function (code) {
+    it('emit error when connect to a socket path without listeners', (done) => {
+      const socketPath = path.join(os.tmpdir(), 'atom-shell-test.sock')
+      const script = path.join(fixtures, 'module', 'create_socket.js')
+      const child = ChildProcess.fork(script, [socketPath])
+      child.on('exit', (code) => {
         assert.equal(code, 0)
-        var client = require('net').connect(socketPath)
-        client.on('error', function (error) {
+        const client = require('net').connect(socketPath)
+        client.on('error', (error) => {
           assert.equal(error.code, 'ECONNREFUSED')
           done()
         })
@@ -270,45 +262,45 @@ describe('node feature', function () {
     })
   })
 
-  describe('Buffer', function () {
-    it('can be created from WebKit external string', function () {
-      var p = document.createElement('p')
+  describe('Buffer', () => {
+    it('can be created from WebKit external string', () => {
+      const p = document.createElement('p')
       p.innerText = '闲云潭影日悠悠,物换星移几度秋'
-      var b = new Buffer(p.innerText)
+      const b = new Buffer(p.innerText)
       assert.equal(b.toString(), '闲云潭影日悠悠,物换星移几度秋')
       assert.equal(Buffer.byteLength(p.innerText), 45)
     })
 
-    it('correctly parses external one-byte UTF8 string', function () {
-      var p = document.createElement('p')
+    it('correctly parses external one-byte UTF8 string', () => {
+      const p = document.createElement('p')
       p.innerText = 'Jøhänñéß'
-      var b = new Buffer(p.innerText)
+      const b = new Buffer(p.innerText)
       assert.equal(b.toString(), 'Jøhänñéß')
       assert.equal(Buffer.byteLength(p.innerText), 13)
     })
 
-    it('does not crash when creating large Buffers', function () {
-      var buffer = new Buffer(new Array(4096).join(' '))
+    it('does not crash when creating large Buffers', () => {
+      let buffer = new Buffer(new Array(4096).join(' '))
       assert.equal(buffer.length, 4095)
       buffer = new Buffer(new Array(4097).join(' '))
       assert.equal(buffer.length, 4096)
     })
   })
 
-  describe('process.stdout', function () {
-    it('does not throw an exception when accessed', function () {
-      assert.doesNotThrow(function () {
+  describe('process.stdout', () => {
+    it('does not throw an exception when accessed', () => {
+      assert.doesNotThrow(() => {
         process.stdout
       })
     })
 
-    it('does not throw an exception when calling write()', function () {
-      assert.doesNotThrow(function () {
+    it('does not throw an exception when calling write()', () => {
+      assert.doesNotThrow(() => {
         process.stdout.write('test')
       })
     })
 
-    it('should have isTTY defined on Mac and Linux', function () {
+    it('should have isTTY defined on Mac and Linux', () => {
       if (isCI) return
 
       if (process.platform === 'win32') {
@@ -319,26 +311,26 @@ describe('node feature', function () {
     })
   })
 
-  describe('process.stdin', function () {
-    it('does not throw an exception when accessed', function () {
-      assert.doesNotThrow(function () {
+  describe('process.stdin', () => {
+    it('does not throw an exception when accessed', () => {
+      assert.doesNotThrow(() => {
         process.stdin
       })
     })
 
-    it('returns null when read from', function () {
+    it('returns null when read from', () => {
       assert.equal(process.stdin.read(), null)
     })
   })
 
-  describe('process.version', function () {
-    it('should not have -pre', function () {
+  describe('process.version', () => {
+    it('should not have -pre', () => {
       assert(!process.version.endsWith('-pre'))
     })
   })
 
-  describe('vm.createContext', function () {
-    it('should not crash', function () {
+  describe('vm.createContext', () => {
+    it('should not crash', () => {
       require('vm').runInNewContext('')
     })
   })

File diff suppressed because it is too large
+ 238 - 247
spec/webview-spec.js


Some files were not shown because too many files changed in this diff