Skip to content

Commit

Permalink
fix: fix missing util for mocha (#317)
Browse files Browse the repository at this point in the history
* fix: fix missing util for mocha

simplify with mocha-2018 bundle.

* chore: lock
  • Loading branch information
hugomrdias authored Oct 20, 2021
1 parent 36dac27 commit cd6d140
Show file tree
Hide file tree
Showing 7 changed files with 303 additions and 555 deletions.
6 changes: 3 additions & 3 deletions mocks/sw/sw-test.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/* eslint-disable no-undef */
// eslint-disable-next-line strict
const assert = require('assert')
const { is } = require('uvu/assert')

const { KV } = require('./sw-globals')

describe('sw', () => {
it('should intercept and return kv and env', async () => {
const out = await fetch('/favicon.ico')
const data = await out.json()
assert.strictEqual(data.env.browser, 'chromium')
assert.strictEqual(data.kv.test, KV.test)
is(data.env.browser, 'chromium')
is(data.kv.test, KV.test)
})
})
12 changes: 6 additions & 6 deletions mocks/test.mocha.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
/* eslint-disable no-undef */
// eslint-disable-next-line strict
const assert = require('assert')
const { is } = require('uvu/assert')
const debug = require('debug')('app')
const { good, bad } = require('./lib')

describe('Array', () => {
describe('#indexOf()', () => {
it('should return -1 when the value is not present', () => {
assert.equal([1, 2, 3].indexOf(4), -1)
is([1, 2, 3].indexOf(4), -1)
})

it('should fail ', () => {
assert.strictEqual([1, 2, 3].indexOf(2), 1)
is([1, 2, 3].indexOf(2), 1)
})

it('should pass with debug', () => {
assert.equal([1, 2, 3].indexOf(4), -1)
is([1, 2, 3].indexOf(4), -1)
debug('test pass')
})

it('should return "good"', async () => {
assert.strictEqual(await good(), 'good')
is(await good(), 'good')
})

it('should return "bad"', async () => {
assert.strictEqual(await bad(), 'bad')
is(await bad(), 'bad')
})
})
})
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,14 @@
"@types/mocha": "^9.0.0",
"@types/polka": "^0.5.2",
"@types/sade": "^1.7.3",
"assert": "^2.0.0",
"benchmark": "^2.1.4",
"copyfiles": "^2.4.1",
"debug": "^4.3.2",
"delay": "^5.0.0",
"execa": "^5.1.1",
"hd-scripts": "^1.0.0",
"mocha": "^9.0.2",
"tap-spec": "^5.0.0",
"mocha": "^9.1.3",
"simple-git-hooks": "^2.6.1",
"uvu": "^0.5.1",
"zora": "^4.0.2"
},
Expand Down
18 changes: 1 addition & 17 deletions src/runner-mocha.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
/* eslint-disable no-console */

import path from 'path'
import merge from 'merge-options'
import { Runner } from './runner.js'
import waitFor from 'p-wait-for'
import { build } from './utils/index.js'
import { createRequire } from 'module'
import { fileURLToPath } from 'url'
/**
* @typedef {import('esbuild').Plugin} EsbuildPlugin
*/
const require = createRequire(import.meta.url)
const __dirname = path.dirname(fileURLToPath(import.meta.url))

const runMocha = () => `
mocha
Expand Down Expand Up @@ -79,22 +76,9 @@ class MochaRunner extends Runner {
* @returns {Promise<import('./types.js').CompilerOutput>} file to be loaded in the page
*/
compiler(mode = 'bundle') {
/** @type {EsbuildPlugin} */
const plugin = {
name: 'swap tape',

setup(build) {
build.onResolve({ filter: /^stream$/ }, () => {
return { path: require.resolve('stream-browserify') }
})
},
}
return build(
this,
{
plugins: [plugin],
inject: [path.join(__dirname, 'node-globals-buffer.js')],
},
{},
`require('${require.resolve('./setup-mocha.js').replace(/\\/g, '/')}')`,
mode
)
Expand Down
13 changes: 3 additions & 10 deletions src/setup-mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,10 @@
/* eslint-disable no-undef */

// mocha library itself, to have it set up on global
import mocha from 'mocha'
import mocha from 'mocha/mocha-es2018.js'

const {
allowUncaught,
bail,
reporter,
timeout,
color,
ui,
grep,
} = process.env.PW_TEST.runnerOptions
const { allowUncaught, bail, reporter, timeout, color, ui, grep } =
process.env.PW_TEST.runnerOptions

mocha.setup({
allowUncaught,
Expand Down
2 changes: 1 addition & 1 deletion test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ok, strictEqual as is } from 'assert'
import { ok, is } from 'uvu/assert'
import execa from 'execa'

describe('mocha', function () {
Expand Down
Loading

0 comments on commit cd6d140

Please sign in to comment.