This commit is contained in:
Jeremy Apthorp 2019-08-28 13:54:50 -07:00 коммит произвёл GitHub
Родитель 41d8247ffc
Коммит 99de0975c3
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
6 изменённых файлов: 41 добавлений и 49 удалений

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

@ -129,9 +129,14 @@ async function runRemoteBasedElectronTests () {
} }
async function runMainProcessElectronTests () { async function runMainProcessElectronTests () {
const exe = path.resolve(BASE, utils.getElectronExec()) let exe = path.resolve(BASE, utils.getElectronExec())
const runnerArgs = ['electron/spec-main', ...unknownArgs.slice(2)]
if (process.platform === 'linux') {
runnerArgs.unshift(path.resolve(__dirname, 'dbus_mock.py'), exe)
exe = 'python'
}
const { status } = childProcess.spawnSync(exe, ['electron/spec-main', ...unknownArgs.slice(2)], { const { status } = childProcess.spawnSync(exe, runnerArgs, {
cwd: path.resolve(__dirname, '../..'), cwd: path.resolve(__dirname, '../..'),
stdio: 'inherit' stdio: 'inherit'
}) })

2
spec-main/ambient.d.ts поставляемый
Просмотреть файл

@ -29,3 +29,5 @@ declare namespace Electron {
} }
class View {} class View {}
} }
declare module 'dbus-native';

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

@ -6,20 +6,19 @@
// //
// See https://pypi.python.org/pypi/python-dbusmock to read about dbusmock. // See https://pypi.python.org/pypi/python-dbusmock to read about dbusmock.
const { expect } = require('chai') import { expect } from 'chai'
const dbus = require('dbus-native') import * as dbus from 'dbus-native'
const Promise = require('bluebird') import { app } from 'electron'
import { ifdescribe } from './spec-helpers'
const { remote } = require('electron') import { promisify } from 'util';
const { app } = remote
const skip = process.platform !== 'linux' || const skip = process.platform !== 'linux' ||
process.arch === 'ia32' || process.arch === 'ia32' ||
process.arch.indexOf('arm') === 0 || process.arch.indexOf('arm') === 0 ||
!process.env.DBUS_SESSION_BUS_ADDRESS; !process.env.DBUS_SESSION_BUS_ADDRESS
(skip ? describe.skip : describe)('Notification module (dbus)', () => { ifdescribe(!skip)('Notification module (dbus)', () => {
let mock, Notification, getCalls, reset let mock: any, Notification, getCalls: any, reset: any
const realAppName = app.name const realAppName = app.name
const realAppVersion = app.getVersion() const realAppVersion = app.getVersion()
const appName = 'api-notification-dbus-spec' const appName = 'api-notification-dbus-spec'
@ -35,10 +34,10 @@ const skip = process.platform !== 'linux' ||
const bus = dbus.sessionBus() const bus = dbus.sessionBus()
console.log(`session bus: ${process.env.DBUS_SESSION_BUS_ADDRESS}`) console.log(`session bus: ${process.env.DBUS_SESSION_BUS_ADDRESS}`)
const service = bus.getService(serviceName) const service = bus.getService(serviceName)
const getInterface = Promise.promisify(service.getInterface, { context: service }) const getInterface = promisify(service.getInterface.bind(service))
mock = await getInterface(path, iface) mock = await getInterface(path, iface)
getCalls = Promise.promisify(mock.GetCalls, { context: mock }) getCalls = promisify(mock.GetCalls.bind(mock))
reset = Promise.promisify(mock.Reset, { context: mock }) reset = promisify(mock.Reset.bind(mock))
}) })
after(async () => { after(async () => {
@ -50,8 +49,8 @@ const skip = process.platform !== 'linux' ||
}) })
describe(`Notification module using ${serviceName}`, () => { describe(`Notification module using ${serviceName}`, () => {
function onMethodCalled (done) { function onMethodCalled (done: () => void) {
function cb (name) { function cb (name: string) {
console.log(`onMethodCalled: ${name}`) console.log(`onMethodCalled: ${name}`)
if (name === 'Notify') { if (name === 'Notify') {
mock.removeListener('MethodCalled', cb) mock.removeListener('MethodCalled', cb)
@ -62,8 +61,8 @@ const skip = process.platform !== 'linux' ||
return cb return cb
} }
function unmarshalDBusNotifyHints (dbusHints) { function unmarshalDBusNotifyHints (dbusHints: any) {
const o = {} const o: Record<string, any> = {}
for (const hint of dbusHints) { for (const hint of dbusHints) {
const key = hint[0] const key = hint[0]
const value = hint[1][1][0] const value = hint[1][1][0]
@ -72,7 +71,7 @@ const skip = process.platform !== 'linux' ||
return o return o
} }
function unmarshalDBusNotifyArgs (dbusArgs) { function unmarshalDBusNotifyArgs (dbusArgs: any) {
return { return {
app_name: dbusArgs[0][1][0], app_name: dbusArgs[0][1][0],
replaces_id: dbusArgs[1][1][0], replaces_id: dbusArgs[1][1][0],
@ -87,7 +86,7 @@ const skip = process.platform !== 'linux' ||
before(done => { before(done => {
mock.on('MethodCalled', onMethodCalled(done)) mock.on('MethodCalled', onMethodCalled(done))
// lazy load Notification after we listen to MethodCalled mock signal // lazy load Notification after we listen to MethodCalled mock signal
Notification = require('electron').remote.Notification Notification = require('electron').Notification
const n = new Notification({ const n = new Notification({
title: 'title', title: 'title',
subtitle: 'subtitle', subtitle: 'subtitle',

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

@ -6,37 +6,30 @@
// //
// See https://pypi.python.org/pypi/python-dbusmock for more information about // See https://pypi.python.org/pypi/python-dbusmock for more information about
// python-dbusmock. // python-dbusmock.
const chai = require('chai') import { expect } from 'chai'
const dirtyChai = require('dirty-chai') import * as dbus from 'dbus-native'
const dbus = require('dbus-native') import { ifdescribe } from './spec-helpers'
const Promise = require('bluebird') import { promisify } from 'util'
const { expect } = chai
chai.use(dirtyChai)
const skip = process.platform !== 'linux' || !process.env.DBUS_SYSTEM_BUS_ADDRESS
describe('powerMonitor', () => { describe('powerMonitor', () => {
let logindMock, dbusMockPowerMonitor, getCalls, emitSignal, reset let logindMock: any, dbusMockPowerMonitor: any, getCalls: any, emitSignal: any, reset: any
if (!skip) { ifdescribe(process.platform === 'linux' && process.env.DBUS_SYSTEM_BUS_ADDRESS != null)('when powerMonitor module is loaded with dbus mock', () => {
before(async () => { before(async () => {
const systemBus = dbus.systemBus() const systemBus = dbus.systemBus()
const loginService = systemBus.getService('org.freedesktop.login1') const loginService = systemBus.getService('org.freedesktop.login1')
const getInterface = Promise.promisify(loginService.getInterface, { context: loginService }) const getInterface = promisify(loginService.getInterface.bind(loginService))
logindMock = await getInterface('/org/freedesktop/login1', 'org.freedesktop.DBus.Mock') logindMock = await getInterface('/org/freedesktop/login1', 'org.freedesktop.DBus.Mock')
getCalls = Promise.promisify(logindMock.GetCalls, { context: logindMock }) getCalls = promisify(logindMock.GetCalls.bind(logindMock))
emitSignal = Promise.promisify(logindMock.EmitSignal, { context: logindMock }) emitSignal = promisify(logindMock.EmitSignal.bind(logindMock))
reset = Promise.promisify(logindMock.Reset, { context: logindMock }) reset = promisify(logindMock.Reset.bind(logindMock))
}) })
after(async () => { after(async () => {
await reset() await reset()
}) })
}
(skip ? describe.skip : describe)('when powerMonitor module is loaded with dbus mock', () => { function onceMethodCalled (done: () => void) {
function onceMethodCalled (done) {
function cb () { function cb () {
logindMock.removeListener('MethodCalled', cb) logindMock.removeListener('MethodCalled', cb)
} }
@ -47,7 +40,7 @@ describe('powerMonitor', () => {
before(done => { before(done => {
logindMock.on('MethodCalled', onceMethodCalled(done)) logindMock.on('MethodCalled', onceMethodCalled(done))
// lazy load powerMonitor after we listen to MethodCalled mock signal // lazy load powerMonitor after we listen to MethodCalled mock signal
dbusMockPowerMonitor = require('electron').remote.powerMonitor dbusMockPowerMonitor = require('electron').powerMonitor
}) })
it('should call Inhibit to delay suspend', async () => { it('should call Inhibit to delay suspend', async () => {
@ -123,11 +116,10 @@ describe('powerMonitor', () => {
}) })
describe('when powerMonitor module is loaded', () => { describe('when powerMonitor module is loaded', () => {
let powerMonitor let powerMonitor: typeof Electron.powerMonitor
before(() => { before(() => {
powerMonitor = require('electron').remote.powerMonitor powerMonitor = require('electron').powerMonitor
}) })
describe('powerMonitor.getSystemIdleState', () => { describe('powerMonitor.getSystemIdleState', () => {
it('gets current system idle state', () => { it('gets current system idle state', () => {
// this function is not mocked out, so we can test the result's // this function is not mocked out, so we can test the result's
@ -148,7 +140,7 @@ describe('powerMonitor', () => {
}).to.throw(/conversion failure/) }).to.throw(/conversion failure/)
expect(() => { expect(() => {
powerMonitor.getSystemIdleState('a') powerMonitor.getSystemIdleState('a' as any)
}).to.throw(/conversion failure/) }).to.throw(/conversion failure/)
}) })
}) })

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

@ -8,7 +8,6 @@
}, },
"devDependencies": { "devDependencies": {
"basic-auth": "^2.0.1", "basic-auth": "^2.0.1",
"bluebird": "^3.5.3",
"chai": "^4.2.0", "chai": "^4.2.0",
"chai-as-promised": "^7.1.1", "chai-as-promised": "^7.1.1",
"coffeescript": "^2.4.1", "coffeescript": "^2.4.1",

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

@ -126,11 +126,6 @@ bl@^1.0.0:
readable-stream "^2.3.5" readable-stream "^2.3.5"
safe-buffer "^5.1.1" safe-buffer "^5.1.1"
bluebird@^3.5.3:
version "3.5.4"
resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.5.4.tgz#d6cc661595de30d5b3af5fcedd3c0b3ef6ec5714"
integrity sha512-FG+nFEZChJrbQ9tIccIfZJBz3J7mLrAhxakAbnrJWn8d7aKOC+LWifa0G+p4ZqKp4y13T7juYvdhq9NzKdsrjw==
brace-expansion@^1.1.7: brace-expansion@^1.1.7:
version "1.1.11" version "1.1.11"
resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.11.tgz#3c7fcbf529d87226f3d2f52b966ff5271eb441dd" resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.11.tgz#3c7fcbf529d87226f3d2f52b966ff5271eb441dd"