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 fs = require('fs')
const { hashElement } = require('folder-hash') const { hashElement } = require('folder-hash')
const path = require('path') const path = require('path')
const args = require('minimist')(process.argv, {
string: ['only']
})
const utils = require('./lib/utils') 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') const specHashPath = path.resolve(__dirname, '../spec/.hash')
let only = null let only = null
const onlyArg = process.argv.find(arg => arg.startsWith('--only=')) if (args.only) {
if (onlyArg) { only = args.only.split(',')
only = onlyArg.substr(7).split(',')
console.log('Only running:', only) console.log('Only running:', only)
} else { } else {
console.log('Will trigger all spec runners') console.log('Will trigger all spec runners')
@ -96,13 +98,13 @@ async function runElectronTests () {
async function runRemoteBasedElectronTests () { async function runRemoteBasedElectronTests () {
let exe = path.resolve(BASE, utils.getElectronExec()) 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') { if (process.platform === 'linux') {
args.unshift(path.resolve(__dirname, 'dbus_mock.py'), exe) runnerArgs.unshift(path.resolve(__dirname, 'dbus_mock.py'), exe)
exe = 'python' exe = 'python'
} }
const { status } = childProcess.spawnSync(exe, args, { const { status } = childProcess.spawnSync(exe, runnerArgs, {
cwd: path.resolve(__dirname, '../..'), cwd: path.resolve(__dirname, '../..'),
stdio: 'inherit' stdio: 'inherit'
}) })
@ -113,9 +115,8 @@ async function runRemoteBasedElectronTests () {
async function runMainProcessElectronTests () { async function runMainProcessElectronTests () {
const exe = path.resolve(BASE, utils.getElectronExec()) 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, '../..'), cwd: path.resolve(__dirname, '../..'),
stdio: 'inherit' stdio: 'inherit'
}) })

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

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

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

@ -1,42 +1,3 @@
/** require('ts-node/register')
* @fileoverview A set of helper functions to make it easier to work
* with events in async/await manner.
*/
/** module.exports = require('../spec-main/window-helpers')
* @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

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

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