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:
parent
dbb8617214
commit
5a7b56b042
22 changed files with 1546 additions and 1591 deletions
|
@ -1,4 +1,6 @@
|
|||
const assert = require('assert')
|
||||
const chai = require('chai')
|
||||
const dirtyChai = require('dirty-chai')
|
||||
|
||||
const Module = require('module')
|
||||
const path = require('path')
|
||||
const fs = require('fs')
|
||||
|
@ -7,6 +9,9 @@ const { BrowserWindow } = remote
|
|||
const { closeWindow } = require('./window-helpers')
|
||||
const features = process.electronBinding('features')
|
||||
|
||||
const { expect } = chai
|
||||
chai.use(dirtyChai)
|
||||
|
||||
const nativeModulesEnabled = remote.getGlobal('nativeModulesEnabled')
|
||||
|
||||
describe('modules support', () => {
|
||||
|
@ -27,7 +32,7 @@ describe('modules support', () => {
|
|||
const echo = path.join(fixtures, 'module', 'echo.js')
|
||||
const child = require('child_process').fork(echo)
|
||||
child.on('message', (msg) => {
|
||||
assert.strictEqual(msg, 'ok')
|
||||
expect(msg).to.equal('ok')
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
@ -39,9 +44,9 @@ describe('modules support', () => {
|
|||
fs.copyFileSync(execPath, testExecPath)
|
||||
try {
|
||||
const fixture = path.join(fixtures, 'module', 'echo-renamed.js')
|
||||
assert.ok(fs.existsSync(fixture))
|
||||
expect(fs.existsSync(fixture)).to.be.true()
|
||||
const child = require('child_process').spawnSync(testExecPath, [fixture])
|
||||
assert.strictEqual(child.status, 0)
|
||||
expect(child.status).to.equal(0)
|
||||
} finally {
|
||||
fs.unlinkSync(testExecPath)
|
||||
}
|
||||
|
@ -65,7 +70,7 @@ describe('modules support', () => {
|
|||
const libm = ffi.Library('libm', {
|
||||
ceil: ['double', ['double']]
|
||||
})
|
||||
assert.strictEqual(libm.ceil(1.5), 2)
|
||||
expect(libm.ceil(1.5)).to.equal(2)
|
||||
})
|
||||
})
|
||||
|
||||
|
@ -74,7 +79,7 @@ describe('modules support', () => {
|
|||
describe('Q.when', () => {
|
||||
it('emits the fullfil callback', (done) => {
|
||||
Q(true).then((val) => {
|
||||
assert.strictEqual(val, true)
|
||||
expect(val).to.be.true()
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
@ -83,10 +88,10 @@ describe('modules support', () => {
|
|||
|
||||
describe('coffeescript', () => {
|
||||
it('can be registered and used to require .coffee files', () => {
|
||||
assert.doesNotThrow(() => {
|
||||
expect(() => {
|
||||
require('coffeescript').register()
|
||||
})
|
||||
assert.strictEqual(require('./fixtures/module/test.coffee'), true)
|
||||
}).to.not.throw()
|
||||
expect(require('./fixtures/module/test.coffee')).to.be.true()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@ -94,19 +99,19 @@ describe('modules support', () => {
|
|||
describe('global variables', () => {
|
||||
describe('process', () => {
|
||||
it('can be declared in a module', () => {
|
||||
assert.strictEqual(require('./fixtures/module/declare-process'), 'declared process')
|
||||
expect(require('./fixtures/module/declare-process')).to.equal('declared process')
|
||||
})
|
||||
})
|
||||
|
||||
describe('global', () => {
|
||||
it('can be declared in a module', () => {
|
||||
assert.strictEqual(require('./fixtures/module/declare-global'), 'declared global')
|
||||
expect(require('./fixtures/module/declare-global')).to.equal('declared global')
|
||||
})
|
||||
})
|
||||
|
||||
describe('Buffer', () => {
|
||||
it('can be declared in a module', () => {
|
||||
assert.strictEqual(require('./fixtures/module/declare-buffer'), 'declared Buffer')
|
||||
expect(require('./fixtures/module/declare-buffer')).to.equal('declared Buffer')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@ -115,36 +120,36 @@ describe('modules support', () => {
|
|||
describe('when the path is inside the resources path', () => {
|
||||
it('does not include paths outside of the resources path', () => {
|
||||
let modulePath = process.resourcesPath
|
||||
assert.deepStrictEqual(Module._nodeModulePaths(modulePath), [
|
||||
expect(Module._nodeModulePaths(modulePath)).to.deep.equal([
|
||||
path.join(process.resourcesPath, 'node_modules')
|
||||
])
|
||||
|
||||
modulePath = process.resourcesPath + '-foo'
|
||||
const nodeModulePaths = Module._nodeModulePaths(modulePath)
|
||||
assert(nodeModulePaths.includes(path.join(modulePath, 'node_modules')))
|
||||
assert(nodeModulePaths.includes(path.join(modulePath, '..', 'node_modules')))
|
||||
expect(nodeModulePaths).to.include(path.join(modulePath, 'node_modules'))
|
||||
expect(nodeModulePaths).to.include(path.join(modulePath, '..', 'node_modules'))
|
||||
|
||||
modulePath = path.join(process.resourcesPath, 'foo')
|
||||
assert.deepStrictEqual(Module._nodeModulePaths(modulePath), [
|
||||
expect(Module._nodeModulePaths(modulePath)).to.deep.equal([
|
||||
path.join(process.resourcesPath, 'foo', 'node_modules'),
|
||||
path.join(process.resourcesPath, 'node_modules')
|
||||
])
|
||||
|
||||
modulePath = path.join(process.resourcesPath, 'node_modules', 'foo')
|
||||
assert.deepStrictEqual(Module._nodeModulePaths(modulePath), [
|
||||
expect(Module._nodeModulePaths(modulePath)).to.deep.equal([
|
||||
path.join(process.resourcesPath, 'node_modules', 'foo', 'node_modules'),
|
||||
path.join(process.resourcesPath, 'node_modules')
|
||||
])
|
||||
|
||||
modulePath = path.join(process.resourcesPath, 'node_modules', 'foo', 'bar')
|
||||
assert.deepStrictEqual(Module._nodeModulePaths(modulePath), [
|
||||
expect(Module._nodeModulePaths(modulePath)).to.deep.equal([
|
||||
path.join(process.resourcesPath, 'node_modules', 'foo', 'bar', 'node_modules'),
|
||||
path.join(process.resourcesPath, 'node_modules', 'foo', 'node_modules'),
|
||||
path.join(process.resourcesPath, 'node_modules')
|
||||
])
|
||||
|
||||
modulePath = path.join(process.resourcesPath, 'node_modules', 'foo', 'node_modules', 'bar')
|
||||
assert.deepStrictEqual(Module._nodeModulePaths(modulePath), [
|
||||
expect(Module._nodeModulePaths(modulePath)).to.deep.equal([
|
||||
path.join(process.resourcesPath, 'node_modules', 'foo', 'node_modules', 'bar', 'node_modules'),
|
||||
path.join(process.resourcesPath, 'node_modules', 'foo', 'node_modules'),
|
||||
path.join(process.resourcesPath, 'node_modules')
|
||||
|
@ -155,7 +160,7 @@ describe('modules support', () => {
|
|||
describe('when the path is outside the resources path', () => {
|
||||
it('includes paths outside of the resources path', () => {
|
||||
const modulePath = path.resolve('/foo')
|
||||
assert.deepStrictEqual(Module._nodeModulePaths(modulePath), [
|
||||
expect(Module._nodeModulePaths(modulePath)).to.deep.equal([
|
||||
path.join(modulePath, 'node_modules'),
|
||||
path.resolve('/node_modules')
|
||||
])
|
||||
|
@ -184,7 +189,7 @@ describe('modules support', () => {
|
|||
it('searches for module under app directory', async () => {
|
||||
w.loadURL('about:blank')
|
||||
const result = await w.webContents.executeJavaScript('typeof require("q").when')
|
||||
assert.strictEqual(result, 'function')
|
||||
expect(result).to.equal('function')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue