chore: finish replacing assert with expect in tests (#18215)

* spec: replace assert with expect in api-browser-view-spec.js

* spec: replace assert with expect in api-touch-bar-spec.js

* spec: replace assert with expect in api-web-frame-spec.js

* spec: replace assert with expect in api-web-contents-view-spec.js

* spec: replace assert with expect in security-warnings-spec.js

* spec: replace assert with expect in api-menu-item-spec.js

* spec: replace assert with expect in api-web-request-spec.js

* spec: replace assert with expect in api-remote-spec.js

* spec: replace assert with expect in api-session-spec.js

* spec: replace assert with expect in api-system-preferences-spec.js

* spec: replace assert with expect in api-browser-window-spec.js

* spec: replace assert with expect in webview-spec.js

* spec: replace assert with expect in api-net-spec.js

* spec: replace assert with expect in api-protocol-spec.js

* spec: replace assert with expect api-web-contents-spec.js

* spec: replace assert with expect in api-shell-spec.js

* spec: replace assert with expect in modules-spec.js

* spec: replace assert with expect in chromium-spec.js

* spec: replace assert with expect in api-crash-reporter-spec.js

* spec: replace assert with expect in asar-spec.js

* spec: rename assert-helpers to expect-helpers

* address PR feedback
This commit is contained in:
Milan Burda 2019-05-20 19:04:18 +02:00 committed by Charles Kerr
parent dbb8617214
commit 5a7b56b042
22 changed files with 1546 additions and 1591 deletions

View file

@ -1,4 +1,3 @@
const assert = require('assert')
const chai = require('chai')
const dirtyChai = require('dirty-chai')
const path = require('path')
@ -160,11 +159,11 @@ describe('<webview> tag', function () {
const message = await startLoadingWebViewAndWaitForMessage(webview, {
src: '../fixtures/pages/e.html'
})
assert.strictEqual(message, 'Window script is loaded before preload script')
expect(message).to.equal('Window script is loaded before preload script')
})
it('ignores empty values', () => {
assert.strictEqual(webview.src, '')
expect(webview.src).to.equal('')
for (const emptyValue of ['', null, undefined]) {
webview.src = emptyValue
@ -224,7 +223,7 @@ describe('<webview> tag', function () {
it('disables node integration on child windows when it is disabled on the webview', (done) => {
app.once('browser-window-created', (event, window) => {
assert.strictEqual(window.webContents.getWebPreferences().nodeIntegration, false)
expect(window.webContents.getWebPreferences().nodeIntegration).to.be.false()
done()
})
@ -251,7 +250,7 @@ describe('<webview> tag', function () {
webview.reload()
const { message } = await waitForEvent(webview, 'console-message')
assert.strictEqual(message, 'function')
expect(message).to.equal('function')
})
})
@ -353,8 +352,8 @@ describe('<webview> tag', function () {
webview.send('ping', message)
const { channel, args } = await waitForEvent(webview, 'ipc-message')
assert.strictEqual(channel, 'pong')
assert.deepStrictEqual(args, [message])
expect(channel).to.equal('pong')
expect(args).to.deep.equal([message])
})
it('works without script tag in page', async () => {
@ -388,11 +387,11 @@ describe('<webview> tag', function () {
})
it('ignores empty values', () => {
assert.strictEqual(webview.preload, '')
expect(webview.preload).to.equal('')
for (const emptyValue of ['', null, undefined]) {
webview.preload = emptyValue
assert.strictEqual(webview.preload, '')
expect(webview.preload).to.equal('')
}
})
})
@ -403,7 +402,7 @@ describe('<webview> tag', function () {
const server = http.createServer((req, res) => {
res.end()
server.close()
assert.strictEqual(req.headers.referer, referrer)
expect(req.headers.referer).to.equal(referrer)
done()
}).listen(0, '127.0.0.1', () => {
const port = server.address().port
@ -610,7 +609,7 @@ describe('<webview> tag', function () {
})
const [, data] = await emittedOnce(ipcMain, 'isolated-world')
assert.deepStrictEqual(data, {
expect(data).to.deep.equal({
preloadContext: {
preloadProperty: 'number',
pageProperty: 'undefined',
@ -641,8 +640,8 @@ describe('<webview> tag', function () {
})
const { url, frameName } = await waitForEvent(webview, 'new-window')
assert.strictEqual(url, 'http://host/')
assert.strictEqual(frameName, 'host')
expect(url).to.equal('http://host/')
expect(frameName).to.equal('host')
})
it('emits when link with target is called', async () => {
@ -651,8 +650,8 @@ describe('<webview> tag', function () {
})
const { url, frameName } = await waitForEvent(webview, 'new-window')
assert.strictEqual(url, 'http://host/')
assert.strictEqual(frameName, 'target')
expect(url).to.equal('http://host/')
expect(frameName).to.equal('target')
})
})
@ -664,8 +663,8 @@ describe('<webview> tag', function () {
})
const { channel, args } = await waitForEvent(webview, 'ipc-message')
assert.strictEqual(channel, 'channel')
assert.deepStrictEqual(args, ['arg1', 'arg2'])
expect(channel).to.equal('channel')
expect(args).to.deep.equal(['arg1', 'arg2'])
})
})
@ -676,8 +675,8 @@ describe('<webview> tag', function () {
})
const { title, explicitSet } = await waitForEvent(webview, 'page-title-set')
assert.strictEqual(title, 'test')
assert(explicitSet)
expect(title).to.equal('test')
expect(explicitSet).to.be.true()
})
})
@ -688,12 +687,11 @@ describe('<webview> tag', function () {
})
const { favicons } = await waitForEvent(webview, 'page-favicon-updated')
assert(favicons)
assert.strictEqual(favicons.length, 2)
expect(favicons).to.be.an('array').of.length(2)
if (process.platform === 'win32') {
assert(/^file:\/\/\/[A-Z]:\/favicon.png$/i.test(favicons[0]))
expect(favicons[0]).to.match(/^file:\/\/\/[A-Z]:\/favicon.png$/i)
} else {
assert.strictEqual(favicons[0], 'file:///favicon.png')
expect(favicons[0]).to.equal('file:///favicon.png')
}
})
})
@ -705,7 +703,7 @@ describe('<webview> tag', function () {
})
const { url } = await waitForEvent(webview, 'will-navigate')
assert.strictEqual(url, 'http://host/')
expect(url).to.equal('http://host/')
})
})
@ -722,7 +720,7 @@ describe('<webview> tag', function () {
loadWebView(webview, { src: pageUrl })
const { url } = await waitForEvent(webview, 'did-navigate')
assert.strictEqual(url, pageUrl)
expect(url).to.equal(pageUrl)
})
})
@ -737,7 +735,7 @@ describe('<webview> tag', function () {
})
loadWebView(webview, { src: pageUrl })
const event = await waitForEvent(webview, 'did-navigate-in-page')
assert.strictEqual(event.url, `${pageUrl}#test_content`)
expect(event.url).to.equal(`${pageUrl}#test_content`)
})
it('emits when window.history.replaceState is called', async () => {
@ -745,7 +743,7 @@ describe('<webview> tag', function () {
src: `file://${fixtures}/pages/webview-did-navigate-in-page-with-history.html`
})
const { url } = await waitForEvent(webview, 'did-navigate-in-page')
assert.strictEqual(url, 'http://host/')
expect(url).to.equal('http://host/')
})
it('emits when window.location.hash is changed', async () => {
@ -758,7 +756,7 @@ describe('<webview> tag', function () {
})
loadWebView(webview, { src: pageUrl })
const event = await waitForEvent(webview, 'did-navigate-in-page')
assert.strictEqual(event.url, `${pageUrl}#test`)
expect(event.url).to.equal(`${pageUrl}#test`)
})
})
@ -787,7 +785,7 @@ describe('<webview> tag', function () {
// Its WebContents should be a DevTools.
const devtools = webview2.getWebContents()
assert.ok(devtools.getURL().startsWith('chrome-devtools://devtools'))
expect(devtools.getURL().startsWith('chrome-devtools://devtools')).to.be.true()
const name = await devtools.executeJavaScript('InspectorFrontendHost.constructor.name')
document.body.removeChild(webview2)
@ -854,7 +852,7 @@ describe('<webview> tag', function () {
webview.reload()
const { channel } = await waitForOnbeforeunload
assert.strictEqual(channel, 'onbeforeunload')
expect(channel).to.equal('onbeforeunload')
})
})
@ -863,15 +861,15 @@ describe('<webview> tag', function () {
let loadCount = 1
const listener = (e) => {
if (loadCount === 1) {
assert.strictEqual(e.channel, 'history')
assert.strictEqual(e.args[0], 1)
assert(!webview.canGoBack())
assert(!webview.canGoForward())
expect(e.channel).to.equal('history')
expect(e.args[0]).to.equal(1)
expect(webview.canGoBack()).to.be.false()
expect(webview.canGoForward()).to.be.false()
} else if (loadCount === 2) {
assert.strictEqual(e.channel, 'history')
assert.strictEqual(e.args[0], 2)
assert(!webview.canGoBack())
assert(webview.canGoForward())
expect(e.channel).to.equal('history')
expect(e.args[0]).to.equal(2)
expect(webview.canGoBack()).to.be.false()
expect(webview.canGoForward()).to.be.true()
webview.removeEventListener('ipc-message', listener)
}
}
@ -880,15 +878,15 @@ describe('<webview> tag', function () {
if (loadCount === 1) {
webview.src = `file://${fixtures}/pages/base-page.html`
} else if (loadCount === 2) {
assert(webview.canGoBack())
assert(!webview.canGoForward())
expect(webview.canGoBack()).to.be.true()
expect(webview.canGoForward()).to.be.false()
webview.goBack()
} else if (loadCount === 3) {
webview.goForward()
} else if (loadCount === 4) {
assert(webview.canGoBack())
assert(!webview.canGoForward())
expect(webview.canGoBack()).to.be.true()
expect(webview.canGoForward()).to.be.false()
webview.removeEventListener('did-finish-load', loadListener)
done()
@ -915,12 +913,12 @@ describe('<webview> tag', function () {
})
const event = await waitForEvent(webview, 'ipc-message')
assert.strictEqual(event.channel, 'history')
assert.strictEqual(event.args[0], 2)
assert(webview.canGoBack())
expect(event.channel).to.equal('history')
expect(event.args[0]).to.equal(2)
expect(webview.canGoBack()).to.be.true()
webview.clearHistory()
assert(!webview.canGoBack())
expect(webview.canGoBack()).to.be.false()
})
})
@ -941,7 +939,7 @@ describe('<webview> tag', function () {
server.listen(0, '127.0.0.1', () => {
const port = server.address().port
webview.addEventListener('ipc-message', (e) => {
assert.strictEqual(e.channel, message)
expect(e.channel).to.equal(message)
done()
})
loadWebView(webview, {
@ -998,7 +996,7 @@ describe('<webview> tag', function () {
const expectedResult = '42'
const result = await webview.executeJavaScript(jsScript)
assert.strictEqual(result, expectedResult)
expect(result).to.equal(expectedResult)
})
})
@ -1018,8 +1016,8 @@ describe('<webview> tag', function () {
})
const { channel, args } = await waitForIpcMessage
assert.strictEqual(channel, 'keyup')
assert.deepStrictEqual(args, ['C', 'KeyC', 67, true, false])
expect(channel).to.equal('keyup')
expect(args).to.deep.equal(['C', 'KeyC', 67, true, false])
})
it('can send mouse event', async () => {
@ -1038,8 +1036,8 @@ describe('<webview> tag', function () {
})
const { channel, args } = await waitForIpcMessage
assert.strictEqual(channel, 'mouseup')
assert.deepStrictEqual(args, [10, 20, false, true])
expect(channel).to.equal('mouseup')
expect(args).to.deep.equal([10, 20, false, true])
})
})
@ -1068,11 +1066,11 @@ describe('<webview> tag', function () {
let requestId = null
const activeMatchOrdinal = []
const listener = (e) => {
assert.strictEqual(e.result.requestId, requestId)
assert.strictEqual(e.result.matches, 3)
expect(e.result.requestId).to.equal(requestId)
expect(e.result.matches).to.equal(3)
activeMatchOrdinal.push(e.result.activeMatchOrdinal)
if (e.result.activeMatchOrdinal === e.result.matches) {
assert.deepStrictEqual(activeMatchOrdinal, [1, 2, 3])
expect(activeMatchOrdinal).to.deep.equal([1, 2, 3])
webview.stopFindInPage('clearSelection')
done()
} else {
@ -1104,7 +1102,7 @@ describe('<webview> tag', function () {
describe('permission-request event', () => {
function setUpRequestHandler (webview, requestedPermission, completed) {
assert.ok(webview.partition)
expect(webview.partition).to.be.a('string').that.is.not.empty()
const listener = function (webContents, permission, callback) {
if (webContents.id === webview.getWebContentsId()) {
@ -1114,7 +1112,7 @@ describe('<webview> tag', function () {
return callback(true)
}
assert.strictEqual(permission, requestedPermission)
expect(permission).to.equal(requestedPermission)
callback(false)
if (completed) completed()
}
@ -1126,8 +1124,8 @@ describe('<webview> tag', function () {
if (isCI) return done()
webview.addEventListener('ipc-message', (e) => {
assert.strictEqual(e.channel, 'message')
assert.deepStrictEqual(e.args, ['PermissionDeniedError'])
expect(e.channel).to.equal('message')
expect(e.args).to.deep.equal(['PermissionDeniedError'])
done()
})
webview.src = `file://${fixtures}/pages/permissions/media.html`
@ -1139,8 +1137,8 @@ describe('<webview> tag', function () {
it('emits when using navigator.geolocation api', (done) => {
webview.addEventListener('ipc-message', (e) => {
assert.strictEqual(e.channel, 'message')
assert.deepStrictEqual(e.args, ['User denied Geolocation'])
expect(e.channel).to.equal('message')
expect(e.args).to.deep.equal(['User denied Geolocation'])
done()
})
webview.src = `file://${fixtures}/pages/permissions/geolocation.html`
@ -1152,8 +1150,8 @@ describe('<webview> tag', function () {
it('emits when using navigator.requestMIDIAccess without sysex api', (done) => {
webview.addEventListener('ipc-message', (e) => {
assert.strictEqual(e.channel, 'message')
assert.deepStrictEqual(e.args, ['SecurityError'])
expect(e.channel).to.equal('message')
expect(e.args).to.deep.equal(['SecurityError'])
done()
})
webview.src = `file://${fixtures}/pages/permissions/midi.html`
@ -1165,8 +1163,8 @@ describe('<webview> tag', function () {
it('emits when using navigator.requestMIDIAccess with sysex api', (done) => {
webview.addEventListener('ipc-message', (e) => {
assert.strictEqual(e.channel, 'message')
assert.deepStrictEqual(e.args, ['SecurityError'])
expect(e.channel).to.equal('message')
expect(e.args).to.deep.equal(['SecurityError'])
done()
})
webview.src = `file://${fixtures}/pages/permissions/midi-sysex.html`
@ -1185,8 +1183,8 @@ describe('<webview> tag', function () {
it('emits when using Notification.requestPermission', (done) => {
webview.addEventListener('ipc-message', (e) => {
assert.strictEqual(e.channel, 'message')
assert.deepStrictEqual(e.args, ['granted'])
expect(e.channel).to.equal('message')
expect(e.args).to.deep.equal(['granted'])
done()
})
webview.src = `file://${fixtures}/pages/permissions/notification.html`
@ -1194,7 +1192,7 @@ describe('<webview> tag', function () {
webview.setAttribute('nodeintegration', 'on')
session.fromPartition(webview.partition).setPermissionRequestHandler((webContents, permission, callback) => {
if (webContents.id === webview.getWebContentsId()) {
assert.strictEqual(permission, 'notifications')
expect(permission).to.equal('notifications')
setTimeout(() => { callback(true) }, 10)
}
})
@ -1217,7 +1215,7 @@ describe('<webview> tag', function () {
await loadWebView(webview, { src })
const webviewContents = webview.getWebContents()
assert(webviewContents)
expect(webviewContents).to.be.an('object')
expect(webviewContents.getURL()).to.equal(src)
})
})
@ -1252,8 +1250,7 @@ describe('<webview> tag', function () {
await loadWebView(webview, { src })
const data = await webview.printToPDF({})
assert.strictEqual(data instanceof Buffer, true)
assert.notStrictEqual(data.length, 0)
expect(data).to.be.an.instanceof(Buffer).that.is.not.empty()
})
})
@ -1274,16 +1271,16 @@ describe('<webview> tag', function () {
w.show()
const [, visibilityState, hidden] = await pongSignal2
assert(!hidden)
assert.strictEqual(visibilityState, 'visible')
expect(visibilityState).to.equal('visible')
expect(hidden).to.be.false()
})
it('inherits the parent window visibility state and receives visibilitychange events', async () => {
const w = await openTheWindow({ show: false })
w.loadFile(path.join(fixtures, 'pages', 'webview-visibilitychange.html'))
const [, visibilityState, hidden] = await emittedOnce(ipcMain, 'pong')
assert.strictEqual(visibilityState, 'hidden')
assert.strictEqual(hidden, true)
expect(visibilityState).to.equal('hidden')
expect(hidden).to.be.true()
// We have to start waiting for the event
// before we ask the webContents to resize.
@ -1291,8 +1288,8 @@ describe('<webview> tag', function () {
w.webContents.emit('-window-visibility-change', 'visible')
return getResponse.then(([, visibilityState, hidden]) => {
assert.strictEqual(visibilityState, 'visible')
assert.strictEqual(hidden, false)
expect(visibilityState).to.equal('visible')
expect(hidden).to.be.false()
})
})
})
@ -1343,7 +1340,7 @@ describe('<webview> tag', function () {
src: `file://${fixtures}/pages/a.html`
})
assert.strictEqual(message, 'undefined')
expect(message).to.equal('undefined')
})
})