[WIP] Upgrade more specs (#10945)

Finish upgrading specs to ES6
This commit is contained in:
Shelley Vohr 2017-10-27 16:45:58 -04:00 committed by GitHub
parent 04cce89fdc
commit e4214a6cbe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 1712 additions and 1945 deletions

View file

@ -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('node feature', () => {
const 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('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('')
})
})