polendina 1.1.1 → 2.0.0-alpha

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/.github/dependabot.yml +154 -0
  2. package/.github/workflows/test-and-release.yml +3 -0
  3. package/lib/log.js +8 -8
  4. package/lib/puppeteer.js +3 -5
  5. package/lib/webpack.config.js +8 -12
  6. package/lib/{wrap-loader.js → wrap-loader.cjs} +8 -5
  7. package/package.json +17 -13
  8. package/polendina-cli.js +7 -6
  9. package/polendina-node-cli.js +10 -6
  10. package/polendina.js +39 -18
  11. package/resources/bare-run.js +3 -3
  12. package/resources/bare.js +7 -5
  13. package/resources/common-run.js +23 -26
  14. package/resources/mocha-run.js +4 -5
  15. package/resources/tape-run.js +5 -5
  16. package/resources/test-registry.js +4 -1
  17. package/test/common.js +8 -8
  18. package/test/fixtures/bare-async/package.json +4 -1
  19. package/test/fixtures/bare-async/test-1.js +1 -1
  20. package/test/fixtures/bare-async/test-2.js +1 -1
  21. package/test/fixtures/bare-async-esm/index.js +3 -0
  22. package/test/fixtures/bare-async-esm/package.json +19 -0
  23. package/test/fixtures/bare-async-esm/test-1.js +16 -0
  24. package/test/fixtures/bare-async-esm/test-2.js +11 -0
  25. package/test/fixtures/bare-async-failure/package.json +4 -1
  26. package/test/fixtures/bare-async-failure/test-1.js +1 -1
  27. package/test/fixtures/bare-async-failure/test-2.js +2 -2
  28. package/test/fixtures/bare-async-failure-esm/index.js +3 -0
  29. package/test/fixtures/bare-async-failure-esm/package.json +19 -0
  30. package/test/fixtures/bare-async-failure-esm/test-1.js +16 -0
  31. package/test/fixtures/bare-async-failure-esm/test-2.js +11 -0
  32. package/test/fixtures/bare-sync/package.json +4 -1
  33. package/test/fixtures/bare-sync/test-1.js +1 -1
  34. package/test/fixtures/bare-sync/test-2.js +2 -1
  35. package/test/fixtures/bare-sync-esm/index.js +1 -0
  36. package/test/fixtures/bare-sync-esm/package.json +19 -0
  37. package/test/fixtures/bare-sync-esm/test-1.js +14 -0
  38. package/test/fixtures/bare-sync-esm/test-2.js +7 -0
  39. package/test/fixtures/bare-sync-failure/package.json +4 -1
  40. package/test/fixtures/bare-sync-failure/test-1.js +1 -1
  41. package/test/fixtures/bare-sync-failure/test-2.js +2 -2
  42. package/test/fixtures/bare-sync-failure-esm/index.js +1 -0
  43. package/test/fixtures/bare-sync-failure-esm/package.json +19 -0
  44. package/test/fixtures/bare-sync-failure-esm/test-1.js +14 -0
  45. package/test/fixtures/bare-sync-failure-esm/test-2.js +6 -0
  46. package/test/fixtures/mocha/package.json +2 -1
  47. package/test/fixtures/mocha/test-1.js +1 -1
  48. package/test/fixtures/mocha/test-2.js +1 -1
  49. package/test/fixtures/mocha/test-3.js +1 -1
  50. package/test/fixtures/mocha-esm/index.js +1 -0
  51. package/test/fixtures/{mocha8 → mocha-esm}/package.json +4 -2
  52. package/test/fixtures/{mocha8 → mocha-esm}/test-1.js +2 -2
  53. package/test/fixtures/{mocha8 → mocha-esm}/test-2.js +1 -1
  54. package/test/fixtures/{mocha8 → mocha-esm}/test-3.js +2 -2
  55. package/test/fixtures/mocha-failure/package.json +2 -1
  56. package/test/fixtures/mocha-failure/test.js +1 -1
  57. package/test/fixtures/mocha-failure-esm/package.json +20 -0
  58. package/test/fixtures/mocha-failure-esm/test.js +24 -0
  59. package/test/fixtures/tape/package.json +1 -1
  60. package/test/fixtures/tape-esm/index.js +1 -0
  61. package/test/fixtures/tape-esm/package.json +19 -0
  62. package/test/fixtures/tape-esm/test.js +47 -0
  63. package/test/fixtures/tape-failure/package.json +1 -1
  64. package/test/fixtures/tape-failure-esm/package.json +19 -0
  65. package/test/fixtures/tape-failure-esm/test.js +29 -0
  66. package/test/fixtures/webpack-merge/package.json +4 -1
  67. package/test/fixtures/webpack-merge/test.js +3 -4
  68. package/test/fixtures/webpack-merge/webpack.config.js +3 -3
  69. package/test/test-bare-async.js +92 -87
  70. package/test/test-bare-sync.js +92 -87
  71. package/test/test-mocha.js +101 -96
  72. package/test/test-polendina-node.js +44 -38
  73. package/test/test-tape.js +95 -90
  74. package/test/test-webpack-merge.js +11 -9
  75. package/CHANGELOG.md +0 -11
  76. package/test/fixtures/mocha8/index.js +0 -1
@@ -0,0 +1,154 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: 'github-actions'
4
+ directory: '/'
5
+ schedule:
6
+ interval: 'daily'
7
+ commit-message:
8
+ prefix: 'chore'
9
+ include: 'scope'
10
+
11
+ - package-ecosystem: 'npm'
12
+ directory: '/'
13
+ schedule:
14
+ interval: 'daily'
15
+ commit-message:
16
+ prefix: 'chore'
17
+ include: 'scope'
18
+
19
+ - package-ecosystem: 'npm'
20
+ directory: '/test/fixtures/bare-async'
21
+ schedule:
22
+ interval: 'daily'
23
+ commit-message:
24
+ prefix: 'chore'
25
+ include: 'scope'
26
+
27
+ - package-ecosystem: 'npm'
28
+ directory: '/test/fixtures/bare-async-esm'
29
+ schedule:
30
+ interval: 'daily'
31
+ commit-message:
32
+ prefix: 'chore'
33
+ include: 'scope'
34
+
35
+ - package-ecosystem: 'npm'
36
+ directory: '/test/fixtures/bare-async-failure'
37
+ schedule:
38
+ interval: 'daily'
39
+ commit-message:
40
+ prefix: 'chore'
41
+ include: 'scope'
42
+
43
+ - package-ecosystem: 'npm'
44
+ directory: '/test/fixtures/bare-async-failure-esm'
45
+ schedule:
46
+ interval: 'daily'
47
+ commit-message:
48
+ prefix: 'chore'
49
+ include: 'scope'
50
+
51
+ - package-ecosystem: 'npm'
52
+ directory: '/test/fixtures/bare-sync'
53
+ schedule:
54
+ interval: 'daily'
55
+ commit-message:
56
+ prefix: 'chore'
57
+ include: 'scope'
58
+
59
+ - package-ecosystem: 'npm'
60
+ directory: '/test/fixtures/bare-sync-esm'
61
+ schedule:
62
+ interval: 'daily'
63
+ commit-message:
64
+ prefix: 'chore'
65
+ include: 'scope'
66
+
67
+ - package-ecosystem: 'npm'
68
+ directory: '/test/fixtures/bare-sync-failure'
69
+ schedule:
70
+ interval: 'daily'
71
+ commit-message:
72
+ prefix: 'chore'
73
+ include: 'scope'
74
+
75
+ - package-ecosystem: 'npm'
76
+ directory: '/test/fixtures/bare-sync-failure-esm'
77
+ schedule:
78
+ interval: 'daily'
79
+ commit-message:
80
+ prefix: 'chore'
81
+ include: 'scope'
82
+
83
+ - package-ecosystem: 'npm'
84
+ directory: '/test/fixtures/mocha'
85
+ schedule:
86
+ interval: 'daily'
87
+ commit-message:
88
+ prefix: 'chore'
89
+ include: 'scope'
90
+
91
+ - package-ecosystem: 'npm'
92
+ directory: '/test/fixtures/mocha-esm'
93
+ schedule:
94
+ interval: 'daily'
95
+ commit-message:
96
+ prefix: 'chore'
97
+ include: 'scope'
98
+
99
+ - package-ecosystem: 'npm'
100
+ directory: '/test/fixtures/mocha-failure'
101
+ schedule:
102
+ interval: 'daily'
103
+ commit-message:
104
+ prefix: 'chore'
105
+ include: 'scope'
106
+
107
+ - package-ecosystem: 'npm'
108
+ directory: '/test/fixtures/mocha-failure-esm'
109
+ schedule:
110
+ interval: 'daily'
111
+ commit-message:
112
+ prefix: 'chore'
113
+ include: 'scope'
114
+
115
+ - package-ecosystem: 'npm'
116
+ directory: '/test/fixtures/tape'
117
+ schedule:
118
+ interval: 'daily'
119
+ commit-message:
120
+ prefix: 'chore'
121
+ include: 'scope'
122
+
123
+ - package-ecosystem: 'npm'
124
+ directory: '/test/fixtures/tape-esm'
125
+ schedule:
126
+ interval: 'daily'
127
+ commit-message:
128
+ prefix: 'chore'
129
+ include: 'scope'
130
+
131
+ - package-ecosystem: 'npm'
132
+ directory: '/test/fixtures/tape-failure'
133
+ schedule:
134
+ interval: 'daily'
135
+ commit-message:
136
+ prefix: 'chore'
137
+ include: 'scope'
138
+
139
+ - package-ecosystem: 'npm'
140
+ directory: '/test/fixtures/tape-failure-esm'
141
+ schedule:
142
+ interval: 'daily'
143
+ commit-message:
144
+ prefix: 'chore'
145
+ include: 'scope'
146
+
147
+ - package-ecosystem: 'npm'
148
+ directory: '/test/fixtures/webpack-merge'
149
+ schedule:
150
+ interval: 'daily'
151
+ commit-message:
152
+ prefix: 'chore'
153
+ include: 'scope'
154
+
@@ -39,6 +39,9 @@ jobs:
39
39
  - name: Install dependencies
40
40
  run: |
41
41
  npm install --no-progress --no-package-lock --no-save
42
+ - name: Build
43
+ run: |
44
+ npm run build
42
45
  - name: Install plugins
43
46
  run: |
44
47
  npm install \
package/lib/log.js CHANGED
@@ -1,5 +1,7 @@
1
- const colors = require('ansi-colors')
2
- const stripAnsi = require('strip-ansi')
1
+ import process from 'process'
2
+ import colors from 'ansi-colors'
3
+ import stripAnsi from 'strip-ansi'
4
+
3
5
  const tty = process.stdout.isTTY && process.stderr.isTTY
4
6
 
5
7
  function brand (error) {
@@ -7,27 +9,25 @@ function brand (error) {
7
9
  return tty ? `${colors[error ? 'red' : 'green'](brand)}` : brand
8
10
  }
9
11
 
10
- function log (msg) {
12
+ export function log (msg) {
11
13
  if (msg === undefined) {
12
14
  return console.log()
13
15
  }
14
16
  console.log(` ${brand()} ${tty ? colors.gray.italic(msg) : msg}`)
15
17
  }
16
18
 
17
- function error (msg) {
19
+ export function error (msg) {
18
20
  console.log(` ${brand(true)} ${tty ? colors.gray.italic(msg) : msg}`)
19
21
  }
20
22
 
21
- function logRaw (type, args) {
23
+ export function logRaw (type, args) {
22
24
  if (!tty) {
23
25
  args = args.map((a) => typeof a === 'string' ? stripAnsi(a) : a)
24
26
  }
25
27
  console[type === 'info' ? 'log' : type].apply(null, args)
26
28
  }
27
29
 
28
- function logWrite (args) {
30
+ export function logWrite (args) {
29
31
  args = Array.isArray(args) ? args : [args]
30
32
  process.stdout.write.apply(process.stdout, args)
31
33
  }
32
-
33
- module.exports = { log, error, logRaw, logWrite }
package/lib/puppeteer.js CHANGED
@@ -1,13 +1,13 @@
1
- const puppeteer = require('puppeteer')
1
+ import puppeteer from 'puppeteer'
2
2
  // TODO
3
3
  // const pti = require('puppeteer-to-istanbul')
4
4
  // const { copyFile } = require('fs').promises
5
- const { log, error, logRaw, logWrite } = require('./log')
5
+ import { log, error, logRaw, logWrite } from './log.js'
6
6
 
7
7
  // wrap our convoluted _run() function in a pure Promise that can handle
8
8
  // both standard throws and the callback that ends it. _run() needs to handle
9
9
  // ends in a few different ways, hence the hack.
10
- function run (outputDir, port, timeout, mode, runner, coverage) {
10
+ export function run (outputDir, port, timeout, mode, runner, coverage) {
11
11
  return new Promise((resolve, reject) => {
12
12
  _run(outputDir, port, timeout, mode, runner, coverage, (err, errors) => {
13
13
  if (err) {
@@ -112,5 +112,3 @@ async function _run (outputDir, port, timeout, mode, runner, coverage, callback)
112
112
  browser.close().then(cb).catch(cb)
113
113
  }, timeout * 1000).unref()
114
114
  }
115
-
116
- module.exports = run
@@ -1,7 +1,10 @@
1
- const path = require('path')
2
- const glob = require('glob')
1
+ import path from 'path'
2
+ import glob from 'glob'
3
+ import { fileURLToPath } from 'url'
3
4
 
4
- module.exports = function (env, options, runner) {
5
+ const __dirname = fileURLToPath(path.dirname(import.meta.url))
6
+
7
+ export function webpackConfig (env, options, runner) {
5
8
  const bundleRun = path.normalize(path.resolve(options.outputDir, runner))
6
9
  const testFiles = options._.reduce((p, c) => {
7
10
  return p.concat(glob.sync(c, { absolute: true }))
@@ -38,21 +41,14 @@ module.exports = function (env, options, runner) {
38
41
  path.join(__dirname, '../node_modules')
39
42
  ]
40
43
  },
41
- node: {
42
- dgram: 'empty',
43
- fs: 'empty',
44
- net: 'empty',
45
- tls: 'empty',
46
- dns: 'empty',
47
- child_process: 'empty'
48
- },
49
44
  module: {
50
45
  rules: [
51
46
  {
52
47
  test: testFiles,
53
48
  exclude: [/node_modules/, bundleRun],
49
+ type: 'javascript/auto', // needed so the wrap-loader can get a sync require() in
54
50
  use: [{
55
- loader: require.resolve('./wrap-loader.js'),
51
+ loader: path.resolve(__dirname, 'wrap-loader.cjs'),
56
52
  options: options
57
53
  }]
58
54
  }
@@ -5,11 +5,11 @@
5
5
 
6
6
  const path = require('path')
7
7
 
8
- function loader (src) {
8
+ function wrapLoader (src) {
9
9
  return src
10
10
  }
11
11
 
12
- loader.pitch = function pitch (remainingRequest) {
12
+ wrapLoader.pitch = function pitch (remainingRequest) {
13
13
  const argv = this.query
14
14
 
15
15
  // probably redundant
@@ -17,15 +17,18 @@ loader.pitch = function pitch (remainingRequest) {
17
17
  return
18
18
  }
19
19
 
20
- // wrap the test in a function that is only called when we want it called
20
+ // wrap the test in a function that is only called when we want it called, using CJS here because
21
+ // we get synchronous require() out of it, this needs the tests to be loaded with javascript/auto
22
+ // so webpack can auto-detect
21
23
  return `
22
- const registry = require(${JSON.stringify(`!!${path.normalize(path.resolve(argv.outputDir, 'test-registry.js'))}`)})
24
+ const { registry } = require(${JSON.stringify(`!!${path.normalize(path.resolve(argv.outputDir, 'test-registry.js'))}`)})
23
25
  registry.argv = JSON.parse(${JSON.stringify(JSON.stringify(argv))})
24
26
  registry.tests.push({
25
27
  name: JSON.parse('${JSON.stringify(path.normalize(path.relative(process.cwd(), remainingRequest)))}'),
26
28
  load: () => { return require(${JSON.stringify(`!!${remainingRequest}`)}) }
27
29
  })
30
+ module.exports = {}
28
31
  `
29
32
  }
30
33
 
31
- module.exports = loader
34
+ module.exports = wrapLoader
package/package.json CHANGED
@@ -1,29 +1,33 @@
1
1
  {
2
2
  "name": "polendina",
3
- "version": "1.1.1",
3
+ "version": "2.0.0-alpha",
4
4
  "description": "Non-UI browser testing for JavaScript libraries from the command-line",
5
5
  "main": "polendina.js",
6
+ "type": "module",
6
7
  "dependencies": {
7
8
  "ansi-colors": "^4.1.1",
8
- "glob": "^7.1.6",
9
- "puppeteer": "^5.2.1",
10
- "raw-loader": "^4.0.0",
11
- "readable-stream": "^2.3.7",
12
- "rimraf": "^3.0.0",
13
- "st": "^2.0.0",
14
- "strip-ansi": "^6.0.0",
15
- "webpack": "^4.41.5",
16
- "webpack-merge": "^4.2.2",
17
- "yargs": "^15.1.0"
9
+ "glob": "^7.2.0",
10
+ "path-browserify": "^1.0.1",
11
+ "process": "^0.11.10",
12
+ "puppeteer": "~12.0.1",
13
+ "raw-loader": "~4.0.2",
14
+ "readable-stream": "^3.6.0",
15
+ "rimraf": "^3.0.2",
16
+ "st": "^3.0.0",
17
+ "stream-browserify": "^3.0.0",
18
+ "strip-ansi": "^6.0.1",
19
+ "webpack": "~5.65.0",
20
+ "webpack-merge": "~5.8.0",
21
+ "yargs": "^17.3.0"
18
22
  },
19
23
  "bin": {
20
24
  "polendina": "./polendina-cli.js",
21
25
  "polendina-node": "./polendina-node-cli.js"
22
26
  },
23
27
  "scripts": {
24
- "lint": "npx standard",
28
+ "lint": "npm_config_yes=true npx standard",
25
29
  "test:install": "for f in $(cd test/fixtures/; ls); do (cd test/fixtures/$f && grep devDependencies package.json > /dev/null && npm i --no-audit --no-fund --no-package-lock) || true; done",
26
- "test:run": "npx mocha test/test-*.js",
30
+ "test:run": "npm_config_yes=true npx mocha test/test-*.js",
27
31
  "test": "npm run lint && npm run test:install && npm run test:run"
28
32
  },
29
33
  "repository": {
package/polendina-cli.js CHANGED
@@ -1,12 +1,13 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- const start = Date.now()
4
-
5
- const path = require('path')
6
- const { log } = require('./lib/log')
7
- const Polendina = require('./polendina')
3
+ import path from 'path'
4
+ import yargs from 'yargs'
5
+ import { hideBin } from 'yargs/helpers'
6
+ import { log } from './lib/log.js'
7
+ import { Polendina } from './polendina.js'
8
8
 
9
- const argv = require('yargs')
9
+ const start = Date.now()
10
+ const argv = yargs(hideBin(process.argv))
10
11
  .usage('$0 testfile.js [testfile2.js [tests/**/test*.js ...] ]')
11
12
  .option('runner', {
12
13
  alias: 'r',
@@ -1,12 +1,16 @@
1
1
  #!/usr/bin/env node
2
2
 
3
+ import process from 'process'
4
+ import path from 'path'
5
+ import glob from 'glob'
6
+ import stripAnsi from 'strip-ansi'
7
+ import yargs from 'yargs'
8
+ import { hideBin } from 'yargs/helpers'
9
+ import { BareRunner } from './resources/bare.js'
10
+
3
11
  const start = Date.now()
4
- const glob = require('glob')
5
- const path = require('path')
6
- const stripAnsi = require('strip-ansi')
7
12
  const tty = process.stdout.isTTY && process.stderr.isTTY
8
- const BareRunner = require('./resources/bare')
9
- const argv = require('yargs')
13
+ const argv = yargs(hideBin(process.argv))
10
14
  .command('bare-sync <test files..>', 'Run synchronous tests using a plain require(file)')
11
15
  .command('bare-async <test files..>', 'Run tests by executing exported functions from files as async')
12
16
  .demandCommand()
@@ -42,7 +46,7 @@ async function run () {
42
46
  const tests = testFiles.map((f) => {
43
47
  return {
44
48
  name: path.relative(process.cwd(), f),
45
- load: () => require(path.resolve(process.cwd(), f))
49
+ load: () => import(new URL(`file://${path.resolve(process.cwd(), f)}`))
46
50
  }
47
51
  })
48
52
  const log = {
package/polendina.js CHANGED
@@ -1,14 +1,21 @@
1
- const { promisify } = require('util')
2
- const path = require('path')
3
- const fs = require('fs').promises
4
- const http = require('http')
5
- const st = require('st')
6
- const rimraf = promisify(require('rimraf'))
7
- const webpack = promisify(require('webpack'))
8
- const merge = require('webpack-merge')
9
- const puppeteer = require('./lib/puppeteer')
10
-
11
- class Polendina {
1
+ import { promisify } from 'util'
2
+ import path from 'path'
3
+ import fs from 'fs/promises'
4
+ import http from 'http'
5
+ import { fileURLToPath } from 'url'
6
+ import st from 'st'
7
+ import _rimraf from 'rimraf'
8
+ import _webpack from 'webpack'
9
+ import { merge } from 'webpack-merge'
10
+ import { run as puppeteer } from './lib/puppeteer.js'
11
+ import { webpackConfig } from './lib/webpack.config.js'
12
+
13
+ const rimraf = promisify(_rimraf)
14
+ const webpack = promisify(_webpack)
15
+
16
+ const __dirname = fileURLToPath(path.dirname(import.meta.url))
17
+
18
+ export class Polendina {
12
19
  constructor (options) {
13
20
  this._options = options
14
21
 
@@ -32,11 +39,27 @@ class Polendina {
32
39
  }
33
40
 
34
41
  async build () {
35
- let webpackConfig = require('./lib/webpack.config')(process.env, this._options, this._runnerModule)
42
+ let config = webpackConfig(process.env, this._options, this._runnerModule)
43
+
44
+ if (this._options.runner === 'tape') {
45
+ config = merge(config, {
46
+ resolve: {
47
+ fallback: {
48
+ stream: path.join(__dirname, 'node_modules', 'stream-browserify'),
49
+ path: path.join(__dirname, 'node_modules', 'path-browserify')
50
+ }
51
+ },
52
+ plugins: [
53
+ new webpack.ProvidePlugin({
54
+ process: 'process/browser'
55
+ })
56
+ ]
57
+ })
58
+ }
36
59
 
37
60
  if (this._options.webpackConfig) {
38
- const userConfig = require(path.join(process.cwd(), this._options.webpackConfig))
39
- webpackConfig = merge.smart(webpackConfig, userConfig)
61
+ const userConfig = (await import(`file://${path.join(process.cwd(), this._options.webpackConfig)}`)).default
62
+ config = merge(config, userConfig)
40
63
  }
41
64
 
42
65
  await fs.mkdir(this.outputDir, { recursive: true })
@@ -48,7 +71,7 @@ class Polendina {
48
71
  return fs.copyFile(path.join(__dirname, 'resources', file), path.join(this.outputDir, file))
49
72
  }))
50
73
 
51
- const stats = await webpack(webpackConfig)
74
+ const stats = await webpack(config)
52
75
  const info = stats.toJson()
53
76
 
54
77
  if (stats.hasErrors()) {
@@ -65,7 +88,7 @@ class Polendina {
65
88
  this.bundleFile = info.assetsByChunkName.main[0]
66
89
 
67
90
  if (this._options.stats) {
68
- this.statsFile = path.join(webpackConfig.output.path, 'webpack-stats.json')
91
+ this.statsFile = path.join(config.output.path, 'webpack-stats.json')
69
92
  await fs.writeFile(this.statsFile, JSON.stringify(info), 'utf8')
70
93
  }
71
94
  }
@@ -119,5 +142,3 @@ class Polendina {
119
142
  })
120
143
  }
121
144
  }
122
-
123
- module.exports = Polendina
@@ -1,10 +1,10 @@
1
1
  // in-browser test runner for bare-sync and bare-async, at end of bundle
2
2
 
3
- const { registry, executionQueue, log, setup } = require('./common-run')
4
- const BareRunner = require('./bare')
3
+ import { registry, executionQueue, log, setup } from './common-run.js'
4
+ import { BareRunner } from './bare.js'
5
5
 
6
6
  setup().then(async () => {
7
7
  const runner = new BareRunner(log, registry.tests)
8
8
  const errors = await runner[registry.argv.runner === 'bare-sync' ? 'runBareSync' : 'runBareAsync']()
9
- executionQueue(() => global.polendinaEnd(errors ? 1 : 0))
9
+ executionQueue(() => globalThis.polendinaEnd(errors ? 1 : 0))
10
10
  })
package/resources/bare.js CHANGED
@@ -1,4 +1,4 @@
1
- class BareRunner {
1
+ export class BareRunner {
2
2
  constructor (log, tests) {
3
3
  this.log = log
4
4
  this.tests = tests
@@ -36,13 +36,17 @@ class BareRunner {
36
36
 
37
37
  async runBareAsync () {
38
38
  return this.runBare(async (mod) => {
39
- const exp = mod.load()
39
+ const exp = await mod.load()
40
40
  if (typeof exp === 'function') {
41
41
  return this.execBare(mod.name, exp)
42
42
  }
43
+ const expn = Object.keys(exp)
44
+ if (expn.length === 1 && expn[0] === 'default' && typeof exp.default === 'function') {
45
+ return this.execBare(mod.name, exp.default)
46
+ }
43
47
  await this.log.info(` ${mod.name}`)
44
48
  let found = false
45
- for (const name in exp) {
49
+ for (const name of expn) {
46
50
  const fn = exp[name]
47
51
  if (typeof fn === 'function') {
48
52
  found = true
@@ -55,5 +59,3 @@ class BareRunner {
55
59
  })
56
60
  }
57
61
  }
58
-
59
- module.exports = BareRunner
@@ -1,51 +1,53 @@
1
1
  /* globals WorkerGlobalScope ServiceWorkerGlobalScope clients */
2
2
 
3
- const registry = require('./test-registry')
3
+ import { registry } from './test-registry.js'
4
+
4
5
  const inPage =
5
6
  typeof window !== 'undefined' &&
6
7
  window.location &&
7
8
  typeof WorkerGlobalScope === 'undefined'
8
9
  const inServiceWorker = !inPage &&
9
10
  typeof ServiceWorkerGlobalScope !== 'undefined' &&
10
- global instanceof ServiceWorkerGlobalScope
11
+ globalThis instanceof ServiceWorkerGlobalScope
11
12
  const inWorker = !inPage && !inServiceWorker &&
12
13
  typeof WorkerGlobalScope !== 'undefined' &&
13
- global instanceof WorkerGlobalScope
14
+ globalThis instanceof WorkerGlobalScope
14
15
  let _executionQueue = Promise.resolve()
15
16
 
16
- function executionQueue (fn) {
17
+ export { registry }
18
+ export function executionQueue (fn) {
17
19
  _executionQueue = _executionQueue.then(fn)
18
20
  return _executionQueue
19
21
  }
20
22
 
21
- const log = {
23
+ export const log = {
22
24
  info: (...args) => {
23
- executionQueue(() => global.polendinaLog(['info'].concat(args)))
25
+ executionQueue(() => globalThis.polendinaLog(['info'].concat(args)))
24
26
  return executionQueue
25
27
  },
26
28
  // TODO
27
29
  warn: (...args) => {
28
- executionQueue(() => global.polendinaLog(['warn'].concat(args)))
30
+ executionQueue(() => globalThis.polendinaLog(['warn'].concat(args)))
29
31
  return executionQueue
30
32
  },
31
33
  // TODO
32
34
  error: (...args) => {
33
- executionQueue(() => global.polendinaLog(['error'].concat(args)))
35
+ executionQueue(() => globalThis.polendinaLog(['error'].concat(args)))
34
36
  return executionQueue
35
37
  }
36
38
  }
37
39
 
38
40
  function setupWorkerGlobals () {
39
- global.polendinaLog = async function (...args) {
40
- global.postMessage(['polendinaLog'].concat(args))
41
+ globalThis.polendinaLog = async function (...args) {
42
+ globalThis.postMessage(['polendinaLog'].concat(args))
41
43
  }
42
44
 
43
- global.polendinaWrite = async function (...args) {
44
- global.postMessage(['polendinaWrite'].concat(args))
45
+ globalThis.polendinaWrite = async function (...args) {
46
+ globalThis.postMessage(['polendinaWrite'].concat(args))
45
47
  }
46
48
 
47
- global.polendinaEnd = async function (...args) {
48
- global.postMessage(['polendinaEnd'].concat(args))
49
+ globalThis.polendinaEnd = async function (...args) {
50
+ globalThis.postMessage(['polendinaEnd'].concat(args))
49
51
  }
50
52
  }
51
53
 
@@ -56,15 +58,15 @@ function setupServiceWorkerGlobals () {
56
58
  }
57
59
  }
58
60
 
59
- global.polendinaLog = async function (...args) {
61
+ globalThis.polendinaLog = async function (...args) {
60
62
  _postMessage(['polendinaLog'].concat(args))
61
63
  }
62
64
 
63
- global.polendinaWrite = async function (...args) {
65
+ globalThis.polendinaWrite = async function (...args) {
64
66
  _postMessage(['polendinaWrite'].concat(args))
65
67
  }
66
68
 
67
- global.polendinaEnd = async function (...args) {
69
+ globalThis.polendinaEnd = async function (...args) {
68
70
  _postMessage(['polendinaEnd'].concat(args))
69
71
  }
70
72
  }
@@ -77,7 +79,7 @@ function setupLogging () {
77
79
  // process.stdout.write() to console.log()
78
80
  // so we strip out the extra \n that necessarily inserts
79
81
  // args[0] = args[0].replace(/\n$/, '')
80
- executionQueue(() => global.polendinaWrite(args))
82
+ executionQueue(() => globalThis.polendinaWrite(args))
81
83
  return
82
84
  }
83
85
  } catch (err) {}
@@ -89,13 +91,13 @@ function setupLogging () {
89
91
  console.error = log.error
90
92
  }
91
93
 
92
- async function setup () {
94
+ export async function setup () {
93
95
  if (inWorker) {
94
96
  setupWorkerGlobals()
95
97
  } else if (inServiceWorker) {
96
98
  await new Promise((resolve, reject) => {
97
- global.addEventListener('activate', (event) => {
98
- event.waitUntil(global.clients.claim())
99
+ globalThis.addEventListener('activate', (event) => {
100
+ event.waitUntil(globalThis.clients.claim())
99
101
  setupServiceWorkerGlobals()
100
102
  resolve()
101
103
  })
@@ -104,8 +106,3 @@ async function setup () {
104
106
 
105
107
  setupLogging()
106
108
  }
107
-
108
- module.exports.executionQueue = executionQueue
109
- module.exports.registry = registry
110
- module.exports.log = log
111
- module.exports.setup = setup