test: fix flaky before-input-event test (#16027)

This commit is contained in:
Jeremy Apthorp 2018-12-11 17:01:48 -08:00 committed by GitHub
parent 48abef27d8
commit 1152fecb75
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -292,12 +292,12 @@ describe('webContents module', () => {
w.loadFile(path.join(fixtures, 'pages', 'key-events.html')) w.loadFile(path.join(fixtures, 'pages', 'key-events.html'))
}) })
it('has the correct properties', (done) => { it('has the correct properties', async () => {
w.loadFile(path.join(fixtures, 'pages', 'base-page.html')) await w.loadFile(path.join(fixtures, 'pages', 'base-page.html'))
w.webContents.once('did-finish-load', () => {
const testBeforeInput = (opts) => { const testBeforeInput = (opts) => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
w.webContents.once('before-input-event', (event, input) => { w.webContents.once('before-input-event', (event, input) => {
try {
assert.strictEqual(input.type, opts.type) assert.strictEqual(input.type, opts.type)
assert.strictEqual(input.key, opts.key) assert.strictEqual(input.key, opts.key)
assert.strictEqual(input.code, opts.code) assert.strictEqual(input.code, opts.code)
@ -307,6 +307,9 @@ describe('webContents module', () => {
assert.strictEqual(input.alt, opts.alt) assert.strictEqual(input.alt, opts.alt)
assert.strictEqual(input.meta, opts.meta) assert.strictEqual(input.meta, opts.meta)
resolve() resolve()
} catch (e) {
reject(e)
}
}) })
const modifiers = [] const modifiers = []
@ -324,8 +327,7 @@ describe('webContents module', () => {
}) })
} }
Promise.resolve().then(() => { await testBeforeInput({
return testBeforeInput({
type: 'keyDown', type: 'keyDown',
key: 'A', key: 'A',
code: 'KeyA', code: 'KeyA',
@ -336,8 +338,7 @@ describe('webContents module', () => {
meta: true, meta: true,
isAutoRepeat: true isAutoRepeat: true
}) })
}).then(() => { await testBeforeInput({
return testBeforeInput({
type: 'keyUp', type: 'keyUp',
key: '.', key: '.',
code: 'Period', code: 'Period',
@ -348,8 +349,7 @@ describe('webContents module', () => {
meta: false, meta: false,
isAutoRepeat: false isAutoRepeat: false
}) })
}).then(() => { await testBeforeInput({
return testBeforeInput({
type: 'keyUp', type: 'keyUp',
key: '!', key: '!',
code: 'Digit1', code: 'Digit1',
@ -360,8 +360,7 @@ describe('webContents module', () => {
meta: true, meta: true,
isAutoRepeat: false isAutoRepeat: false
}) })
}).then(() => { await testBeforeInput({
return testBeforeInput({
type: 'keyUp', type: 'keyUp',
key: 'Tab', key: 'Tab',
code: 'Tab', code: 'Tab',
@ -372,8 +371,6 @@ describe('webContents module', () => {
meta: false, meta: false,
isAutoRepeat: true isAutoRepeat: true
}) })
}).then(done).catch(done)
})
}) })
}) })