зеркало из https://github.com/electron/electron.git
test: tsify powerMonitor spec (#19963)
This commit is contained in:
Родитель
41d8247ffc
Коммит
99de0975c3
|
@ -129,9 +129,14 @@ async function runRemoteBasedElectronTests () {
|
|||
}
|
||||
|
||||
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, '../..'),
|
||||
stdio: 'inherit'
|
||||
})
|
||||
|
|
|
@ -29,3 +29,5 @@ declare namespace Electron {
|
|||
}
|
||||
class View {}
|
||||
}
|
||||
|
||||
declare module 'dbus-native';
|
||||
|
|
|
@ -6,20 +6,19 @@
|
|||
//
|
||||
// See https://pypi.python.org/pypi/python-dbusmock to read about dbusmock.
|
||||
|
||||
const { expect } = require('chai')
|
||||
const dbus = require('dbus-native')
|
||||
const Promise = require('bluebird')
|
||||
|
||||
const { remote } = require('electron')
|
||||
const { app } = remote
|
||||
import { expect } from 'chai'
|
||||
import * as dbus from 'dbus-native'
|
||||
import { app } from 'electron'
|
||||
import { ifdescribe } from './spec-helpers'
|
||||
import { promisify } from 'util';
|
||||
|
||||
const skip = process.platform !== 'linux' ||
|
||||
process.arch === 'ia32' ||
|
||||
process.arch.indexOf('arm') === 0 ||
|
||||
!process.env.DBUS_SESSION_BUS_ADDRESS;
|
||||
!process.env.DBUS_SESSION_BUS_ADDRESS
|
||||
|
||||
(skip ? describe.skip : describe)('Notification module (dbus)', () => {
|
||||
let mock, Notification, getCalls, reset
|
||||
ifdescribe(!skip)('Notification module (dbus)', () => {
|
||||
let mock: any, Notification, getCalls: any, reset: any
|
||||
const realAppName = app.name
|
||||
const realAppVersion = app.getVersion()
|
||||
const appName = 'api-notification-dbus-spec'
|
||||
|
@ -35,10 +34,10 @@ const skip = process.platform !== 'linux' ||
|
|||
const bus = dbus.sessionBus()
|
||||
console.log(`session bus: ${process.env.DBUS_SESSION_BUS_ADDRESS}`)
|
||||
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)
|
||||
getCalls = Promise.promisify(mock.GetCalls, { context: mock })
|
||||
reset = Promise.promisify(mock.Reset, { context: mock })
|
||||
getCalls = promisify(mock.GetCalls.bind(mock))
|
||||
reset = promisify(mock.Reset.bind(mock))
|
||||
})
|
||||
|
||||
after(async () => {
|
||||
|
@ -50,8 +49,8 @@ const skip = process.platform !== 'linux' ||
|
|||
})
|
||||
|
||||
describe(`Notification module using ${serviceName}`, () => {
|
||||
function onMethodCalled (done) {
|
||||
function cb (name) {
|
||||
function onMethodCalled (done: () => void) {
|
||||
function cb (name: string) {
|
||||
console.log(`onMethodCalled: ${name}`)
|
||||
if (name === 'Notify') {
|
||||
mock.removeListener('MethodCalled', cb)
|
||||
|
@ -62,8 +61,8 @@ const skip = process.platform !== 'linux' ||
|
|||
return cb
|
||||
}
|
||||
|
||||
function unmarshalDBusNotifyHints (dbusHints) {
|
||||
const o = {}
|
||||
function unmarshalDBusNotifyHints (dbusHints: any) {
|
||||
const o: Record<string, any> = {}
|
||||
for (const hint of dbusHints) {
|
||||
const key = hint[0]
|
||||
const value = hint[1][1][0]
|
||||
|
@ -72,7 +71,7 @@ const skip = process.platform !== 'linux' ||
|
|||
return o
|
||||
}
|
||||
|
||||
function unmarshalDBusNotifyArgs (dbusArgs) {
|
||||
function unmarshalDBusNotifyArgs (dbusArgs: any) {
|
||||
return {
|
||||
app_name: dbusArgs[0][1][0],
|
||||
replaces_id: dbusArgs[1][1][0],
|
||||
|
@ -87,7 +86,7 @@ const skip = process.platform !== 'linux' ||
|
|||
before(done => {
|
||||
mock.on('MethodCalled', onMethodCalled(done))
|
||||
// lazy load Notification after we listen to MethodCalled mock signal
|
||||
Notification = require('electron').remote.Notification
|
||||
Notification = require('electron').Notification
|
||||
const n = new Notification({
|
||||
title: 'title',
|
||||
subtitle: 'subtitle',
|
|
@ -6,37 +6,30 @@
|
|||
//
|
||||
// See https://pypi.python.org/pypi/python-dbusmock for more information about
|
||||
// python-dbusmock.
|
||||
const chai = require('chai')
|
||||
const dirtyChai = require('dirty-chai')
|
||||
const dbus = require('dbus-native')
|
||||
const Promise = require('bluebird')
|
||||
|
||||
const { expect } = chai
|
||||
chai.use(dirtyChai)
|
||||
|
||||
const skip = process.platform !== 'linux' || !process.env.DBUS_SYSTEM_BUS_ADDRESS
|
||||
import { expect } from 'chai'
|
||||
import * as dbus from 'dbus-native'
|
||||
import { ifdescribe } from './spec-helpers'
|
||||
import { promisify } from 'util'
|
||||
|
||||
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 () => {
|
||||
const systemBus = dbus.systemBus()
|
||||
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')
|
||||
getCalls = Promise.promisify(logindMock.GetCalls, { context: logindMock })
|
||||
emitSignal = Promise.promisify(logindMock.EmitSignal, { context: logindMock })
|
||||
reset = Promise.promisify(logindMock.Reset, { context: logindMock })
|
||||
getCalls = promisify(logindMock.GetCalls.bind(logindMock))
|
||||
emitSignal = promisify(logindMock.EmitSignal.bind(logindMock))
|
||||
reset = promisify(logindMock.Reset.bind(logindMock))
|
||||
})
|
||||
|
||||
after(async () => {
|
||||
await reset()
|
||||
})
|
||||
}
|
||||
|
||||
(skip ? describe.skip : describe)('when powerMonitor module is loaded with dbus mock', () => {
|
||||
function onceMethodCalled (done) {
|
||||
function onceMethodCalled (done: () => void) {
|
||||
function cb () {
|
||||
logindMock.removeListener('MethodCalled', cb)
|
||||
}
|
||||
|
@ -47,7 +40,7 @@ describe('powerMonitor', () => {
|
|||
before(done => {
|
||||
logindMock.on('MethodCalled', onceMethodCalled(done))
|
||||
// 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 () => {
|
||||
|
@ -123,11 +116,10 @@ describe('powerMonitor', () => {
|
|||
})
|
||||
|
||||
describe('when powerMonitor module is loaded', () => {
|
||||
let powerMonitor
|
||||
let powerMonitor: typeof Electron.powerMonitor
|
||||
before(() => {
|
||||
powerMonitor = require('electron').remote.powerMonitor
|
||||
powerMonitor = require('electron').powerMonitor
|
||||
})
|
||||
|
||||
describe('powerMonitor.getSystemIdleState', () => {
|
||||
it('gets current system idle state', () => {
|
||||
// this function is not mocked out, so we can test the result's
|
||||
|
@ -148,7 +140,7 @@ describe('powerMonitor', () => {
|
|||
}).to.throw(/conversion failure/)
|
||||
|
||||
expect(() => {
|
||||
powerMonitor.getSystemIdleState('a')
|
||||
powerMonitor.getSystemIdleState('a' as any)
|
||||
}).to.throw(/conversion failure/)
|
||||
})
|
||||
})
|
|
@ -8,7 +8,6 @@
|
|||
},
|
||||
"devDependencies": {
|
||||
"basic-auth": "^2.0.1",
|
||||
"bluebird": "^3.5.3",
|
||||
"chai": "^4.2.0",
|
||||
"chai-as-promised": "^7.1.1",
|
||||
"coffeescript": "^2.4.1",
|
||||
|
|
|
@ -126,11 +126,6 @@ bl@^1.0.0:
|
|||
readable-stream "^2.3.5"
|
||||
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:
|
||||
version "1.1.11"
|
||||
resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.11.tgz#3c7fcbf529d87226f3d2f52b966ff5271eb441dd"
|
||||
|
|
Загрузка…
Ссылка в новой задаче