diff --git a/cli.js b/cli.js index 66c90d05..3536e4a2 100755 --- a/cli.js +++ b/cli.js @@ -104,7 +104,7 @@ sade2 ) .option( '-r, --runner', - 'Test runner. Options: mocha, tape, benchmark and zora.', + 'Test runner. Options: mocha, tape, zora, uvu and benchmark.', 'mocha' ) .option( diff --git a/package.json b/package.json index 4f589e5a..b602e0f9 100644 --- a/package.json +++ b/package.json @@ -46,9 +46,9 @@ ], "dependencies": { "@hd-forks/v8-to-istanbul": "7.1.1", + "buffer": "^6.0.3", "camelcase": "^6.2.0", "esbuild": "0.11.5", - "fresh-tape": "^5.1.1", "globby": "^11.0.3", "kleur": "^4.1.4", "lilconfig": "^2.0.2", @@ -64,7 +64,9 @@ "sade": "^1.7.4", "sirv": "^1.0.11", "source-map": "0.6.1", + "stream-browserify": "^3.0.0", "strip-ansi": "^6.0.0", + "tape": "^5.2.2", "tempy": "^1.0.1", "test-exclude": "^6.0.0" }, @@ -100,6 +102,7 @@ "src/vendor/benchmark.js", "src/vendor/source-map-support.js", "node-globals.js", + "node-globals-buffer.js", "mocks" ], "prettier": "hd-scripts/prettier.config.js" diff --git a/readme.md b/readme.md index ab395d2b..a9e3d809 100644 --- a/readme.md +++ b/readme.md @@ -27,7 +27,7 @@ Description $ playwright-test [files] [options] Options - -r, --runner Test runner. Options: mocha, tape, benchmark and zora. (default mocha) + -r, --runner Test runner. Options: mocha, tape, zora, uvu and benchmark. (default mocha) -b, --browser Browser to run tests. Options: chromium, firefox, webkit. (default chromium) -m, --mode Run mode. Options: main, worker. (default main) -d, --debug Debug mode, keeps browser window open. diff --git a/src/empty-fs.js b/src/empty-fs.js new file mode 100644 index 00000000..f177540a --- /dev/null +++ b/src/empty-fs.js @@ -0,0 +1,2 @@ +'use strict' +module.exports = {} diff --git a/src/node-globals-buffer.js b/src/node-globals-buffer.js new file mode 100644 index 00000000..07794ee4 --- /dev/null +++ b/src/node-globals-buffer.js @@ -0,0 +1,4 @@ +// @ts-nocheck +export const Buffer = require('buffer') +export const process = require('process/browser') +// https://github.com/ionic-team/rollup-plugin-node-polyfills diff --git a/src/runner-mocha.js b/src/runner-mocha.js index 0d7126f2..ca2a4f33 100644 --- a/src/runner-mocha.js +++ b/src/runner-mocha.js @@ -1,6 +1,7 @@ /* eslint-disable no-console */ 'use strict' +const path = require('path') const merge = require('merge-options') const Runner = require('./runner') const waitFor = require('p-wait-for') @@ -74,7 +75,9 @@ class MochaRunner extends Runner { compiler(mode = 'bundle') { return build( this, - {}, + { + inject: [path.join(__dirname, 'node-globals.js')], + }, `require('${require.resolve('./setup-mocha.js').replace(/\\/g, '/')}')`, mode ) diff --git a/src/runner-tape.js b/src/runner-tape.js index f04b3fdd..0ca8d406 100644 --- a/src/runner-tape.js +++ b/src/runner-tape.js @@ -1,6 +1,6 @@ /* eslint-disable no-console */ 'use strict' - +const path = require('path') const Runner = require('./runner') const { build } = require('./utils') @@ -20,15 +20,21 @@ class TapeRunner extends Runner { const plugin = { name: 'swap tape', setup(build) { - build.onResolve({ filter: /^tape$/ }, () => { - return { path: require.resolve('fresh-tape') } + build.onResolve({ filter: /^stream$/ }, () => { + return { path: require.resolve('stream-browserify') } + }) + build.onResolve({ filter: /^fs$/ }, () => { + return { path: require.resolve('./empty-fs.js') } }) }, } return build( this, - { plugins: [plugin] }, + { + plugins: [plugin], + inject: [path.join(__dirname, 'node-globals-buffer.js')], + }, `require('${require.resolve('./setup-tape.js').replace(/\\/g, '/')}')`, mode ) diff --git a/src/runner-uvu.js b/src/runner-uvu.js index 153e7d0a..2b15fc63 100644 --- a/src/runner-uvu.js +++ b/src/runner-uvu.js @@ -1,6 +1,7 @@ /* eslint-disable no-console */ 'use strict' +const path = require('path') const strip = require('strip-ansi') const Runner = require('./runner') const { build } = require('./utils') @@ -40,7 +41,12 @@ class UvuRunner extends Runner { * @returns {Promise} file to be loaded in the page */ compiler(mode = 'bundle') { - return build(this, {}, '', mode) + return build( + this, + { inject: [path.join(__dirname, 'node-globals.js')] }, + '', + mode + ) } } diff --git a/src/runner-zora.js b/src/runner-zora.js index 0cffee75..055c69ac 100644 --- a/src/runner-zora.js +++ b/src/runner-zora.js @@ -74,7 +74,15 @@ class ZoraRunner extends Runner { }, } - return build(this, { plugins: [plugin] }, '', mode) + return build( + this, + { + plugins: [plugin], + inject: [path.join(__dirname, 'node-globals.js')], + }, + '', + mode + ) } } diff --git a/src/setup-tape.js b/src/setup-tape.js index 92f9a66f..12b44f8f 100644 --- a/src/setup-tape.js +++ b/src/setup-tape.js @@ -1,7 +1,7 @@ // @ts-nocheck 'use strict' -const test = require('fresh-tape') +const test = require('tape') self.TAPE_RUN_FAIL = false diff --git a/src/utils.js b/src/utils.js index b14dd8b5..b75165bb 100644 --- a/src/utils.js +++ b/src/utils.js @@ -338,7 +338,6 @@ const build = async (runner, config = {}, tmpl = '', mode = 'bundle') => { const infile = path.join(runner.dir, 'in.js') const outfile = path.join(runner.dir, outName) const sourceMapSupport = path.join(__dirname, 'vendor/source-map-support.js') - const nodeGlobalsInject = path.join(__dirname, 'node-globals.js') /** @type {ESBuildPlugin} */ const nodePlugin = { @@ -394,7 +393,6 @@ require('${require sourcemap: 'inline', plugins: [nodePlugin], outfile, - inject: [nodeGlobalsInject], watch: mode === 'watch' ? watch : false, define: { global: 'globalThis', diff --git a/yarn.lock b/yarn.lock index 63cd4efd..3953d22a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -543,6 +543,14 @@ buffer@^5.5.0, buffer@^5.6.0: base64-js "^1.3.1" ieee754 "^1.1.13" +buffer@^6.0.3: + version "6.0.3" + resolved "https://registry.yarnpkg.com/buffer/-/buffer-6.0.3.tgz#2ace578459cc8fbe2a70aaa8f52ee63b6a74c6c6" + integrity sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA== + dependencies: + base64-js "^1.3.1" + ieee754 "^1.2.1" + call-bind@^1.0.0, call-bind@^1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/call-bind/-/call-bind-1.0.2.tgz#b1d4e89e688119c3c9a903ad30abb2f6a919be3c" @@ -1601,7 +1609,7 @@ human-signals@^2.1.0: resolved "https://registry.yarnpkg.com/human-signals/-/human-signals-2.1.0.tgz#dc91fcba42e4d06e4abaed33b3e7a3c02f514ea0" integrity sha512-B4FFZ6q/T2jhhksgkbEW3HBvWIfDW85snkQgawt07S7J5QXTk6BkNV+0yAeZrM5QpMAdYlocGoljn0sJ/WQkFw== -ieee754@^1.1.13: +ieee754@^1.1.13, ieee754@^1.2.1: version "1.2.1" resolved "https://registry.yarnpkg.com/ieee754/-/ieee754-1.2.1.tgz#8eb7a10a63fff25d15a57b001586d177d1b0d352" integrity sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA== @@ -1642,7 +1650,7 @@ inflight@^1.0.4: once "^1.3.0" wrappy "1" -inherits@2, inherits@^2.0.1, inherits@^2.0.3, inherits@^2.0.4, inherits@~2.0.1, inherits@~2.0.3: +inherits@2, inherits@^2.0.1, inherits@^2.0.3, inherits@^2.0.4, inherits@~2.0.1, inherits@~2.0.3, inherits@~2.0.4: version "2.0.4" resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c" integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ== @@ -2221,7 +2229,7 @@ object-inspect@^1.9.0: resolved "https://registry.yarnpkg.com/object-inspect/-/object-inspect-1.10.2.tgz#b6385a3e2b7cae0b5eafcf90cddf85d128767f30" integrity sha512-gz58rdPpadwztRrPjZE9DZLOABUpTGdcANUgOwBFO1C+HZZhePoP83M65WGDmbpwFYJSWqavbl4SgDn4k8RYTA== -object-is@^1.0.1, object-is@^1.1.4: +object-is@^1.0.1, object-is@^1.1.4, object-is@^1.1.5: version "1.1.5" resolved "https://registry.yarnpkg.com/object-is/-/object-is-1.1.5.tgz#b9deeaa5fc7f1846a0faecdceec138e5778f53ac" integrity sha512-3cyDsyHgtmi7I7DfSSI2LDp6SK2lwvtbg0p0R1e0RvTqF5ceGx+K2dfSjm1bKDMVCFEDAQvy+o8c6a7VujOddw== @@ -2627,6 +2635,17 @@ read-pkg@^2.0.0: normalize-package-data "^2.3.2" path-type "^2.0.0" +"readable-stream@2 || 3", readable-stream@3.6.0, readable-stream@^3.4.0, readable-stream@^3.5.0, "readable-stream@https://registry.npmjs.org/@leichtgewicht/readable-stream/-/readable-stream-3.6.0.tgz": + version "3.6.0" + resolved "https://registry.npmjs.org/@leichtgewicht/readable-stream/-/readable-stream-3.6.0.tgz#25682c94346526abc8c8b1ece125b52a7247bb2e" + dependencies: + browser-util-inspect "^0.2.0" + buffer "^5.6.0" + events "^3.1.0" + inherits "^2.0.3" + string_decoder "^1.1.1" + util-deprecate "^1.0.1" + readable-stream@2.2.9: version "2.2.9" resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-2.2.9.tgz#cf78ec6f4a6d1eb43d26488cac97f042e74b7fc8" @@ -2640,18 +2659,6 @@ readable-stream@2.2.9: string_decoder "~1.0.0" util-deprecate "~1.0.1" -readable-stream@^3.4.0, "readable-stream@https://registry.npmjs.org/@leichtgewicht/readable-stream/-/readable-stream-3.6.0.tgz": - version "3.6.0" - uid "25682c94346526abc8c8b1ece125b52a7247bb2e" - resolved "https://registry.npmjs.org/@leichtgewicht/readable-stream/-/readable-stream-3.6.0.tgz#25682c94346526abc8c8b1ece125b52a7247bb2e" - dependencies: - browser-util-inspect "^0.2.0" - buffer "^5.6.0" - events "^3.1.0" - inherits "^2.0.3" - string_decoder "^1.1.1" - util-deprecate "^1.0.1" - readable-stream@~1.0.31: version "1.0.34" resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-1.0.34.tgz#125820e34bc842d2f2aaafafe4c2916ee32c157c" @@ -2738,6 +2745,14 @@ resolve@^1.10.0, resolve@^1.10.1, resolve@^1.13.1, resolve@^1.17.0, resolve@^1.1 is-core-module "^2.2.0" path-parse "^1.0.6" +resolve@^2.0.0-next.3: + version "2.0.0-next.3" + resolved "https://registry.yarnpkg.com/resolve/-/resolve-2.0.0-next.3.tgz#d41016293d4a8586a39ca5d9b5f15cbea1f55e46" + integrity sha512-W8LucSynKUIDu9ylraa7ueVZ7hc0uAgJBxVsQSKOXOyle8a93qXhcz+XAXZ8bIq2d6i4Ehddn6Evt+0/UwKk6Q== + dependencies: + is-core-module "^2.2.0" + path-parse "^1.0.6" + restore-cursor@^3.1.0: version "3.1.0" resolved "https://registry.yarnpkg.com/restore-cursor/-/restore-cursor-3.1.0.tgz#39f67c54b3a7a58cea5236d95cf0034239631f7e" @@ -2746,12 +2761,26 @@ restore-cursor@^3.1.0: onetime "^5.1.0" signal-exit "^3.0.2" +resumer-through2@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/resumer-through2/-/resumer-through2-1.0.0.tgz#04b9a3c8811d97bd4831e4d9ea82a4c5cd96c5e8" + integrity sha512-c10dQkuekQh2GQ7V1b3mHUNnB4vi6DCi7jGeJ7DVlHveYPNdYxFFSlB0pTJpbQ0YDrtRaCKgpNz6u70947bxbg== + dependencies: + through2 "2 || 3" + "resumer-through2@https://registry.npmjs.org/resumer-through2/-/resumer-through2-1.0.1.tgz": version "1.0.1" resolved "https://registry.npmjs.org/resumer-through2/-/resumer-through2-1.0.1.tgz#8d2786cc845f69de48f6593afa3d8aaeebcf1602" dependencies: through2 "https://registry.npmjs.org/@leichtgewicht/through2/-/through2-4.0.2.tgz" +resumer@^0.0.0: + version "0.0.0" + resolved "https://registry.yarnpkg.com/resumer/-/resumer-0.0.0.tgz#f1e8f461e4064ba39e82af3cdc2a8c893d076759" + integrity sha1-8ej0YeQGS6Oegq883CqMiT0HZ1k= + dependencies: + through "~2.3.4" + retry@^0.12.0: version "0.12.0" resolved "https://registry.yarnpkg.com/retry/-/retry-0.12.0.tgz#1b42a6266a21f07421d1b0b54b7dc167b01c013b" @@ -2952,6 +2981,14 @@ stack-utils@^2.0.3: dependencies: escape-string-regexp "^2.0.0" +stream-browserify@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/stream-browserify/-/stream-browserify-3.0.0.tgz#22b0a2850cdf6503e73085da1fc7b7d0c2122f2f" + integrity sha512-H73RAHsVBapbim0tU2JwwOiXUj+fikfiaoYAKHF3VJfA0pe2BCzkhAHBlLG6REzE+2WNZcxOXjK7lkso+9euLA== + dependencies: + inherits "~2.0.4" + readable-stream "^3.5.0" + string-argv@0.3.1: version "0.3.1" resolved "https://registry.yarnpkg.com/string-argv/-/string-argv-0.3.1.tgz#95e2fbec0427ae19184935f816d74aaa4c5c19da" @@ -2974,7 +3011,7 @@ string-width@^4.1.0, string-width@^4.2.0: is-fullwidth-code-point "^3.0.0" strip-ansi "^6.0.0" -string.prototype.trim@^1.2.3: +string.prototype.trim@^1.2.3, string.prototype.trim@^1.2.4: version "1.2.4" resolved "https://registry.yarnpkg.com/string.prototype.trim/-/string.prototype.trim-1.2.4.tgz#6014689baf5efaf106ad031a5fa45157666ed1bd" integrity sha512-hWCk/iqf7lp0/AgTF7/ddO1IWtSNPASjlzCicV5irAVdE1grjsneK26YG6xACMBEdCvO8fUST0UzDMh/2Qy+9Q== @@ -3133,6 +3170,29 @@ tap-spec@^5.0.0: tap-out "^2.1.0" through2 "^2.0.0" +tape@^5.2.2: + version "5.2.2" + resolved "https://registry.yarnpkg.com/tape/-/tape-5.2.2.tgz#a98475ecf30aa0ed2a89c36439bb9438d24d2184" + integrity sha512-grXrzPC1ly2kyTMKdqxh5GiLpb0BpNctCuecTB0psHX4Gu0nc+uxWR4xKjTh/4CfQlH4zhvTM2/EXmHXp6v/uA== + dependencies: + call-bind "^1.0.2" + deep-equal "^2.0.5" + defined "^1.0.0" + dotignore "^0.1.2" + for-each "^0.3.3" + glob "^7.1.6" + has "^1.0.3" + inherits "^2.0.4" + is-regex "^1.1.2" + minimist "^1.2.5" + object-inspect "^1.9.0" + object-is "^1.1.5" + object.assign "^4.1.2" + resolve "^2.0.0-next.3" + resumer "^0.0.0" + string.prototype.trim "^1.2.4" + through "^2.3.8" + temp-dir@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/temp-dir/-/temp-dir-2.0.0.tgz#bde92b05bdfeb1516e804c9c00ad45177f31321e" @@ -3163,6 +3223,14 @@ text-table@^0.2.0: resolved "https://registry.yarnpkg.com/text-table/-/text-table-0.2.0.tgz#7f5ee823ae805207c00af2df4a84ec3fcfa570b4" integrity sha1-f17oI66AUgfACvLfSoTsP8+lcLQ= +"through2@2 || 3": + version "3.0.2" + resolved "https://registry.yarnpkg.com/through2/-/through2-3.0.2.tgz#99f88931cfc761ec7678b41d5d7336b5b6a07bf4" + integrity sha512-enaDQ4MUyP2W6ZyT6EsMzqBPZaM/avg8iuo+l2d3QCs0J+6RaqkHV/2/lOwDTueBHeJ/2LG9lrLW3d5rWPucuQ== + dependencies: + inherits "^2.0.4" + readable-stream "2 || 3" + through2@^2.0.0, through2@^2.0.1: version "2.0.5" resolved "https://registry.yarnpkg.com/through2/-/through2-2.0.5.tgz#01c1e39eb31d07cb7d03a96a70823260b23132cd" @@ -3171,14 +3239,13 @@ through2@^2.0.0, through2@^2.0.1: readable-stream "~2.3.6" xtend "~4.0.1" -"through2@https://registry.npmjs.org/@leichtgewicht/through2/-/through2-4.0.2.tgz": +through2@^4.0.2, "through2@https://registry.npmjs.org/@leichtgewicht/through2/-/through2-4.0.2.tgz": version "4.0.2" - uid ea39512757acd2dab1be4ff1eeb1e43708aa7333 resolved "https://registry.npmjs.org/@leichtgewicht/through2/-/through2-4.0.2.tgz#ea39512757acd2dab1be4ff1eeb1e43708aa7333" dependencies: readable-stream "https://registry.npmjs.org/@leichtgewicht/readable-stream/-/readable-stream-3.6.0.tgz" -through@2, through@^2.3.8: +through@2, through@^2.3.8, through@~2.3.4: version "2.3.8" resolved "https://registry.yarnpkg.com/through/-/through-2.3.8.tgz#0dd4c9ffaabc357960b1b724115d7e0e86a2e1f5" integrity sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU=