This commit is contained in:
Samuel Attard 2019-03-13 15:09:28 -07:00
Родитель 259bc3a918
Коммит 46e5767527
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 191FEF027779CC6C
4 изменённых файлов: 22 добавлений и 68 удалений

Просмотреть файл

@ -5,6 +5,9 @@ const crypto = require('crypto')
const fs = require('fs')
const { hashElement } = require('folder-hash')
const path = require('path')
const args = require('minimist')(process.argv, {
string: ['only']
})
const utils = require('./lib/utils')
@ -14,9 +17,8 @@ const NPM_CMD = process.platform === 'win32' ? 'npm.cmd' : 'npm'
const specHashPath = path.resolve(__dirname, '../spec/.hash')
let only = null
const onlyArg = process.argv.find(arg => arg.startsWith('--only='))
if (onlyArg) {
only = onlyArg.substr(7).split(',')
if (args.only) {
only = args.only.split(',')
console.log('Only running:', only)
} else {
console.log('Will trigger all spec runners')
@ -96,13 +98,13 @@ async function runElectronTests () {
async function runRemoteBasedElectronTests () {
let exe = path.resolve(BASE, utils.getElectronExec())
const args = ['electron/spec', ...process.argv.slice(2).filter(arg => !arg.startsWith('--only='))]
const runnerArgs = ['electron/spec', ...args._]
if (process.platform === 'linux') {
args.unshift(path.resolve(__dirname, 'dbus_mock.py'), exe)
runnerArgs.unshift(path.resolve(__dirname, 'dbus_mock.py'), exe)
exe = 'python'
}
const { status } = childProcess.spawnSync(exe, args, {
const { status } = childProcess.spawnSync(exe, runnerArgs, {
cwd: path.resolve(__dirname, '../..'),
stdio: 'inherit'
})
@ -113,9 +115,8 @@ async function runRemoteBasedElectronTests () {
async function runMainProcessElectronTests () {
const exe = path.resolve(BASE, utils.getElectronExec())
const args = process.argv.slice(2).filter(arg => !arg.startsWith('--only='))
const { status } = childProcess.spawnSync(exe, ['electron/spec-main', ...args], {
const { status } = childProcess.spawnSync(exe, ['electron/spec-main', ...args._], {
cwd: path.resolve(__dirname, '../..'),
stdio: 'inherit'
})

Просмотреть файл

@ -209,7 +209,7 @@ describe('app module', () => {
it('passes arguments to the second-instance event', async () => {
const appPath = path.join(__dirname, 'fixtures', 'api', 'singleton')
const first = ChildProcess.spawn(remote.process.execPath, [appPath])
const first = cp.spawn(process.execPath, [appPath])
const firstExited = emittedOnce(first, 'exit')
// Wait for the first app to boot.
@ -219,16 +219,16 @@ describe('app module', () => {
}
const data2Promise = emittedOnce(firstStdoutLines, 'data')
const secondInstanceArgs = [remote.process.execPath, appPath, '--some-switch', 'some-arg']
const second = ChildProcess.spawn(secondInstanceArgs[0], secondInstanceArgs.slice(1))
const secondInstanceArgs = [process.execPath, appPath, '--some-switch', 'some-arg']
const second = cp.spawn(secondInstanceArgs[0], secondInstanceArgs.slice(1))
const [code2] = await emittedOnce(second, 'exit')
expect(code2).to.equal(1)
const [code1] = await firstExited
expect(code1).to.equal(0)
const data2 = (await data2Promise).toString('ascii')
const data2 = (await data2Promise)[0].toString('ascii')
const secondInstanceArgsReceived = JSON.parse(data2.toString('ascii'))
const expected = process.platform === 'win32'
? [remote.process.execPath, '--some-switch', '--allow-file-access-from-files', secondInstanceArgsReceived.find(x => x.includes('original-process-start-time')), appPath, 'some-arg']
? [process.execPath, '--some-switch', '--allow-file-access-from-files', secondInstanceArgsReceived.find(x => x.includes('original-process-start-time')), appPath, 'some-arg']
: secondInstanceArgs
expect(secondInstanceArgsReceived).to.eql(expected,
`expected ${JSON.stringify(expected)} but got ${data2.toString('ascii')}`)

Просмотреть файл

@ -1,42 +1,3 @@
/**
* @fileoverview A set of helper functions to make it easier to work
* with events in async/await manner.
*/
require('ts-node/register')
/**
* @param {!EventTarget} target
* @param {string} eventName
* @return {!Promise<!Event>}
*/
const waitForEvent = (target, eventName) => {
return new Promise(resolve => {
target.addEventListener(eventName, resolve, { once: true })
})
}
/**
* @param {!EventEmitter} emitter
* @param {string} eventName
* @return {!Promise<!Array>} With Event as the first item.
*/
const emittedOnce = (emitter, eventName) => {
return emittedNTimes(emitter, eventName, 1).then(([result]) => result)
}
const emittedNTimes = (emitter, eventName, times) => {
const events = []
return new Promise(resolve => {
const handler = (...args) => {
events.push(args)
if (events.length === times) {
emitter.removeListener(eventName, handler)
resolve(events)
}
}
emitter.on(eventName, handler)
})
}
exports.emittedOnce = emittedOnce
exports.emittedNTimes = emittedNTimes
exports.waitForEvent = waitForEvent
module.exports = require('../spec-main/window-helpers')

20
spec/package-lock.json сгенерированный
Просмотреть файл

@ -241,14 +241,12 @@
"console-control-strings": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/console-control-strings/-/console-control-strings-1.1.0.tgz",
"integrity": "sha1-PXz0Rk22RG6mRL9LOVB/mFEAjo4=",
"optional": true
"integrity": "sha1-PXz0Rk22RG6mRL9LOVB/mFEAjo4="
},
"core-util-is": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz",
"integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=",
"optional": true
"integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac="
},
"cross-spawn": {
"version": "6.0.5",
@ -682,8 +680,7 @@
"isarray": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz",
"integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=",
"optional": true
"integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE="
},
"isexe": {
"version": "2.0.0",
@ -789,8 +786,7 @@
"minimist": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz",
"integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=",
"optional": true
"integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ="
},
"mkdirp": {
"version": "0.5.1",
@ -1110,8 +1106,7 @@
"process-nextick-args": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.0.tgz",
"integrity": "sha512-MtEC1TqN0EU5nephaJ4rAtThHtC86dNN9qCuEhtshvpVBkAW5ZO7BASN9REnF9eoXGcRub+pFuKEpOHE+HbEMw==",
"optional": true
"integrity": "sha512-MtEC1TqN0EU5nephaJ4rAtThHtC86dNN9qCuEhtshvpVBkAW5ZO7BASN9REnF9eoXGcRub+pFuKEpOHE+HbEMw=="
},
"pump": {
"version": "2.0.1",
@ -1163,7 +1158,6 @@
"version": "2.3.6",
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.6.tgz",
"integrity": "sha512-tQtKA9WIAhBF3+VLAseyMqZeBjW0AHJoxOtYqSUZNJxauErmLbVm2FW1y+J/YA9dUrAC39ITejlZWhVIwawkKw==",
"optional": true,
"requires": {
"core-util-is": "~1.0.0",
"inherits": "~2.0.3",
@ -1373,7 +1367,6 @@
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz",
"integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==",
"optional": true,
"requires": {
"safe-buffer": "~5.1.0"
}
@ -1500,8 +1493,7 @@
"util-deprecate": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz",
"integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=",
"optional": true
"integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8="
},
"walkdir": {
"version": "0.3.2",