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,6 +1,6 @@
const assert = require('assert')
const chai = require('chai')
const dirtyChai = require('dirty-chai')
const childProcess = require('child_process')
const { expect } = require('chai')
const fs = require('fs')
const http = require('http')
const multiparty = require('multiparty')
@ -12,6 +12,9 @@ const { closeWindow } = require('./window-helpers')
const { remote } = require('electron')
const { app, BrowserWindow, crashReporter } = remote
const { expect } = chai
chai.use(dirtyChai)
describe('crashReporter module', () => {
if (process.mas || process.env.DISABLE_CRASH_REPORTER_TESTS) return
@ -118,7 +121,7 @@ describe('crashReporter module', () => {
const testDone = (uploaded) => {
if (uploaded) return done(new Error('Uploaded crash report'))
if (process.platform === 'darwin') crashReporter.setUploadToServer(true)
assert(fs.existsSync(dumpFile))
expect(fs.existsSync(dumpFile)).to.be.true()
done()
}
@ -129,7 +132,7 @@ describe('crashReporter module', () => {
const dumps = files.filter((file) => /\.dmp$/.test(file) && !existingDumpFiles.has(file))
if (!dumps.length) return
assert.strictEqual(1, dumps.length)
expect(dumps).to.have.lengthOf(1)
dumpFile = path.join(crashesDir, dumps[0])
clearInterval(pollInterval)
// dump file should not be deleted when not uploading, so we wait
@ -210,21 +213,21 @@ describe('crashReporter module', () => {
it('returns the product name if one is specified', () => {
const name = crashReporter.getProductName()
const expectedName = (process.platform === 'darwin') ? 'Electron Test' : 'Zombies'
assert.strictEqual(name, expectedName)
expect(name).to.equal(expectedName)
})
})
describe('start(options)', () => {
it('requires that the companyName and submitURL options be specified', () => {
assert.throws(() => {
expect(() => {
crashReporter.start({ companyName: 'Missing submitURL' })
}, /submitURL is a required option to crashReporter\.start/)
assert.throws(() => {
}).to.throw('submitURL is a required option to crashReporter.start')
expect(() => {
crashReporter.start({ submitURL: 'Missing companyName' })
}, /companyName is a required option to crashReporter\.start/)
}).to.throw('companyName is a required option to crashReporter.start')
})
it('can be called multiple times', () => {
assert.doesNotThrow(() => {
expect(() => {
crashReporter.start({
companyName: 'Umbrella Corporation',
submitURL: 'http://127.0.0.1/crashes'
@ -234,7 +237,7 @@ describe('crashReporter module', () => {
companyName: 'Umbrella Corporation 2',
submitURL: 'http://127.0.0.1/more-crashes'
})
})
}).to.not.throw()
})
})
@ -247,14 +250,14 @@ describe('crashReporter module', () => {
} else {
dir = `${app.getPath('temp')}/Electron Test Crashes`
}
assert.strictEqual(crashesDir, dir)
expect(crashesDir).to.equal(dir)
})
})
describe('getUploadedReports', () => {
it('returns an array of reports', () => {
const reports = crashReporter.getUploadedReports()
assert(typeof reports === 'object')
expect(reports).to.be.an('array')
})
})
@ -278,7 +281,7 @@ describe('crashReporter module', () => {
? { report: cur, timestamp: timestamp }
: acc
}, { timestamp: -Infinity })
assert(newestReport, 'Hey!')
expect(newestReport).to.be.an('object')
expect(lastReport.date.getTime()).to.be.equal(
newestReport.date.getTime(),
@ -288,7 +291,7 @@ describe('crashReporter module', () => {
describe('getUploadToServer()', () => {
it('throws an error when called from the renderer process', () => {
assert.throws(() => require('electron').crashReporter.getUploadToServer())
expect(() => require('electron').crashReporter.getUploadToServer()).to.throw()
})
it('returns true when uploadToServer is set to true', function () {
if (process.platform !== 'darwin') {
@ -302,7 +305,7 @@ describe('crashReporter module', () => {
submitURL: 'http://127.0.0.1/crashes',
uploadToServer: true
})
assert.strictEqual(crashReporter.getUploadToServer(), true)
expect(crashReporter.getUploadToServer()).to.be.true()
})
it('returns false when uploadToServer is set to false', function () {
if (process.platform !== 'darwin') {
@ -317,13 +320,13 @@ describe('crashReporter module', () => {
uploadToServer: true
})
crashReporter.setUploadToServer(false)
assert.strictEqual(crashReporter.getUploadToServer(), false)
expect(crashReporter.getUploadToServer()).to.be.false()
})
})
describe('setUploadToServer(uploadToServer)', () => {
it('throws an error when called from the renderer process', () => {
assert.throws(() => require('electron').crashReporter.setUploadToServer('arg'))
expect(() => require('electron').crashReporter.setUploadToServer('arg')).to.throw()
})
it('sets uploadToServer false when called with false', function () {
if (process.platform !== 'darwin') {
@ -338,7 +341,7 @@ describe('crashReporter module', () => {
uploadToServer: true
})
crashReporter.setUploadToServer(false)
assert.strictEqual(crashReporter.getUploadToServer(), false)
expect(crashReporter.getUploadToServer()).to.be.false()
})
it('sets uploadToServer true when called with true', function () {
if (process.platform !== 'darwin') {
@ -353,7 +356,7 @@ describe('crashReporter module', () => {
uploadToServer: false
})
crashReporter.setUploadToServer(true)
assert.strictEqual(crashReporter.getUploadToServer(), true)
expect(crashReporter.getUploadToServer()).to.be.true()
})
})
@ -365,7 +368,7 @@ describe('crashReporter module', () => {
})
const parameters = crashReporter.getParameters()
assert(typeof parameters === 'object')
expect(parameters).to.be.an('object')
})
it('adds a parameter to current parameters', function () {
if (process.platform !== 'darwin') {
@ -380,7 +383,7 @@ describe('crashReporter module', () => {
})
crashReporter.addExtraParameter('hello', 'world')
assert('hello' in crashReporter.getParameters())
expect(crashReporter.getParameters()).to.have.a.property('hello')
})
it('removes a parameter from current parameters', function () {
if (process.platform !== 'darwin') {
@ -395,10 +398,10 @@ describe('crashReporter module', () => {
})
crashReporter.addExtraParameter('hello', 'world')
assert('hello' in crashReporter.getParameters())
expect(crashReporter.getParameters()).to.have.a.property('hello')
crashReporter.removeExtraParameter('hello')
assert(!('hello' in crashReporter.getParameters()))
expect(crashReporter.getParameters()).to.not.have.a.property('hello')
})
})
})
@ -428,23 +431,23 @@ const startServer = ({ callback, processType, done }) => {
if (error) throw error
if (called) return
called = true
assert.deepStrictEqual(String(fields.prod), 'Electron')
assert.strictEqual(String(fields.ver), process.versions.electron)
assert.strictEqual(String(fields.process_type), processType)
assert.strictEqual(String(fields.platform), process.platform)
assert.strictEqual(String(fields.extra1), 'extra1')
assert.strictEqual(String(fields.extra2), 'extra2')
assert.strictEqual(fields.extra3, undefined)
assert.strictEqual(String(fields._productName), 'Zombies')
assert.strictEqual(String(fields._companyName), 'Umbrella Corporation')
assert.strictEqual(String(fields._version), app.getVersion())
expect(String(fields.prod)).to.equal('Electron')
expect(String(fields.ver)).to.equal(process.versions.electron)
expect(String(fields.process_type)).to.equal(processType)
expect(String(fields.platform)).to.equal(process.platform)
expect(String(fields.extra1)).to.equal('extra1')
expect(String(fields.extra2)).to.equal('extra2')
expect(fields.extra3).to.be.undefined()
expect(String(fields._productName)).to.equal('Zombies')
expect(String(fields._companyName)).to.equal('Umbrella Corporation')
expect(String(fields._version)).to.equal(app.getVersion())
const reportId = 'abc-123-def-456-abc-789-abc-123-abcd'
res.end(reportId, () => {
waitForCrashReport().then(() => {
assert.strictEqual(crashReporter.getLastCrashReport().id, reportId)
assert.notStrictEqual(crashReporter.getUploadedReports().length, 0)
assert.strictEqual(crashReporter.getUploadedReports()[0].id, reportId)
expect(crashReporter.getLastCrashReport().id).to.equal(reportId)
expect(crashReporter.getUploadedReports()).to.be.an('array').that.is.not.empty()
expect(crashReporter.getUploadedReports()[0].id).to.equal(reportId)
req.socket.destroy()
done()
}, done)