Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: move to esm #216

Merged
merged 2 commits into from
May 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 22 additions & 22 deletions cli.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
#!/usr/bin/env node
/* eslint-disable no-console */

'use strict'

const path = require('path')
const sade = require('sade')
const kleur = require('kleur')
const lilconfig = require('lilconfig')
const merge = require('merge-options').bind({ ignoreUndefined: true })
const pkg = require('./package.json')
const { runnerOptions } = require('./src/utils')
const UvuRunner = require('./src/runner-uvu')
const MochaRunner = require('./src/runner-mocha')
const TapeRunner = require('./src/runner-tape')
const BenchmarkRunner = require('./src/runner-benchmark')
const ZoraRunner = require('./src/runner-zora')
import path from 'path'
import sade from 'sade'
import kleur from 'kleur'
import { lilconfigSync } from 'lilconfig'
import mergeOptions from 'merge-options'
import { runnerOptions } from './src/utils/index.js'
import UvuRunner from './src/runner-uvu.js'
import MochaRunner from './src/runner-mocha.js'
import TapeRunner from './src/runner-tape.js'
import { BenchmarkRunner } from './src/runner-benchmark.js'
import ZoraRunner from './src/runner-zora.js'
import fs from 'fs'

const { version } = JSON.parse(fs.readFileSync('package.json', 'utf8'))

const merge = mergeOptions.bind({ ignoreUndefined: true })

// Handle any uncaught errors
process.once('uncaughtException', (
Expand Down Expand Up @@ -98,7 +100,7 @@ const sade2 = new Proxy(sade('playwright-test [files]', true), {
})

sade2
.version(pkg.version)
.version(version)
.describe(
'Run mocha, zora, uvu, tape and benchmark.js scripts inside real browsers with `playwright`.'
)
Expand Down Expand Up @@ -139,17 +141,15 @@ sade2
let config

if (opts.config) {
config = lilconfig
.lilconfigSync('playwright-test')
.load(path.resolve(opts.config))
config = lilconfigSync('playwright-test').load(path.resolve(opts.config))
} else {
config = lilconfig.lilconfigSync('playwright-test').search()
config = lilconfigSync('playwright-test').search()
if (!config) {
config = lilconfig.lilconfigSync('pw-test').search()
config = lilconfigSync('pw-test').search()
}
}

let Runner = null
let Runner

switch (opts.runner) {
case 'uvu':
Expand All @@ -168,7 +168,7 @@ sade2
Runner = BenchmarkRunner
break
default:
console.error('Runner not supported: ', opts.runner)
console.error('Runner not supported:', opts.runner)
process.exit(1)
}
const runner = new Runner(
Expand Down
4 changes: 2 additions & 2 deletions mocks/benchmark.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* eslint-disable no-unused-expressions */
'use strict'

const Benchmark = require('benchmark')
// const Benchmark = require('benchmark')

// import Benchmark from 'benchmark'
import Benchmark from 'benchmark'

const suite = new Benchmark.Suite()

Expand Down
24 changes: 20 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
"repository": "hugomrdias/playwright-test",
"author": "Hugo Dias <hugomrdias@gmail.com> (hugodias.me)",
"license": "MIT",
"type": "module",
"main": "src/runner.js",
"types": "dist/src/runner.d.ts",
"exports": "./index.js",
"bin": {
"playwright-test": "cli.js",
"pw-test": "cli.js"
},
"engines": {
"node": ">=12"
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
},
"scripts": {
"prepare": "tsc && copyfiles 'src/**/*.d.ts' dist",
Expand Down Expand Up @@ -78,6 +80,7 @@
"copyfiles": "^2.4.1",
"debug": "^4.3.1",
"delay": "^5.0.0",
"eslint-plugin-unicorn": "^32.0.1",
"execa": "^5.0.0",
"hd-scripts": "^0.1.1",
"mocha": "^8.4.0",
Expand All @@ -93,16 +96,29 @@
"*.js": "eslint --fix"
},
"eslintConfig": {
"extends": "./node_modules/hd-scripts/eslint/index.js"
"extends": [
"./node_modules/hd-scripts/eslint/index.js",
"plugin:unicorn/recommended"
],
"parserOptions": {
"sourceType": "module"
},
"rules": {
"unicorn/prefer-node-protocol": "off",
"unicorn/prevent-abbreviations": "off",
"import/extensions": [
"error",
"ignorePackages"
]
}
},
"eslintIgnore": [
"node_modules",
"coverage",
"dist",
"src/vendor/benchmark.js",
"src/setup-bench.js",
"src/vendor/source-map-support.js",
"src/utils/inject-process.js",
"node-globals-buffer.js",
"mocks"
],
"prettier": "hd-scripts/prettier.config.js"
Expand Down
3 changes: 1 addition & 2 deletions src/empty-fs.js
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
'use strict'
module.exports = {}
export default {}
7 changes: 4 additions & 3 deletions src/node-globals-buffer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// @ts-nocheck
export const Buffer = require('buffer')
export const process = require('process/browser')
// https://github.com/ionic-team/rollup-plugin-node-polyfills

export { default as Buffer } from 'buffer'
// @ts-ignore
export { default as process } from 'process/browser'
14 changes: 7 additions & 7 deletions src/runner-benchmark.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
/* eslint-disable no-console */
'use strict'

const path = require('path')
const Runner = require('./runner')
const { build } = require('./utils')
import path from 'path'
import { fileURLToPath } from 'url'
import { Runner } from './runner.js'
import { build } from './utils/index.js'

class BenchmarkRunner extends Runner {
const __dirname = path.dirname(fileURLToPath(import.meta.url))

export class BenchmarkRunner extends Runner {
/**
* Compile tests
*
Expand All @@ -26,5 +28,3 @@ class BenchmarkRunner extends Runner {
return build(this, { plugins: [plugin] })
}
}

module.exports = BenchmarkRunner
16 changes: 9 additions & 7 deletions src/runner-mocha.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
/* eslint-disable no-console */
'use strict'

const merge = require('merge-options')
const Runner = require('./runner')
const waitFor = require('p-wait-for')
const { build } = require('./utils')
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'

const require = createRequire(import.meta.url)

const runMocha = () => `
mocha
Expand Down Expand Up @@ -61,7 +63,7 @@ class MochaRunner extends Runner {
break
}
default:
throw Error('mode not supported')
throw new Error('mode not supported')
}
}

Expand All @@ -81,4 +83,4 @@ class MochaRunner extends Runner {
}
}

module.exports = MochaRunner
export default MochaRunner
14 changes: 9 additions & 5 deletions src/runner-tape.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
/* eslint-disable no-console */
'use strict'
const path = require('path')
const Runner = require('./runner')
const { build } = require('./utils')

import path from 'path'
import { Runner } from './runner.js'
import { build } from './utils/index.js'
import { createRequire } from 'module'
import { fileURLToPath } from 'url'

const require = createRequire(import.meta.url)
const __dirname = path.dirname(fileURLToPath(import.meta.url))
/**
* @typedef {import('esbuild').Plugin} EsbuildPlugin
*/
Expand Down Expand Up @@ -41,4 +45,4 @@ class TapeRunner extends Runner {
}
}

module.exports = TapeRunner
export default TapeRunner
9 changes: 4 additions & 5 deletions src/runner-uvu.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
/* eslint-disable no-console */
'use strict'

const strip = require('strip-ansi')
const Runner = require('./runner')
const { build } = require('./utils')
import strip from 'strip-ansi'
import { Runner } from './runner.js'
import { build } from './utils/index.js'

const run = (/** @type {boolean} */ pass) => `
self.PW_TEST.end(${pass})
Expand Down Expand Up @@ -44,4 +43,4 @@ class UvuRunner extends Runner {
}
}

module.exports = UvuRunner
export default UvuRunner
16 changes: 9 additions & 7 deletions src/runner-zora.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
/* eslint-disable no-console */
'use strict'

const path = require('path')
const Runner = require('./runner')
const waitFor = require('p-wait-for')
const { build } = require('./utils')
import path from 'path'
import { Runner } from './runner.js'
import waitFor from 'p-wait-for'
import { build } from './utils/index.js'
import { fileURLToPath } from 'url'

const __dirname = path.dirname(fileURLToPath(import.meta.url))

const runZora = () => `
zora
Expand Down Expand Up @@ -45,7 +47,7 @@ class ZoraRunner extends Runner {
break
}
default:
throw Error('mode not supported')
throw new Error('mode not supported')
}
}

Expand Down Expand Up @@ -85,4 +87,4 @@ class ZoraRunner extends Runner {
}
}

module.exports = ZoraRunner
export default ZoraRunner
Loading