polendina 1.0.0 → 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 (75) hide show
  1. package/.github/dependabot.yml +154 -0
  2. package/.github/workflows/test-and-release.yml +61 -0
  3. package/lib/log.js +8 -8
  4. package/lib/puppeteer.js +6 -5
  5. package/lib/webpack.config.js +15 -18
  6. package/lib/{wrap-loader.js → wrap-loader.cjs} +10 -7
  7. package/package.json +99 -18
  8. package/polendina-cli.js +7 -6
  9. package/polendina-node-cli.js +10 -6
  10. package/polendina.js +45 -19
  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 +12 -12
  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/mocha-esm/package.json +20 -0
  52. package/test/fixtures/mocha-esm/test-1.js +14 -0
  53. package/test/fixtures/mocha-esm/test-2.js +19 -0
  54. package/test/fixtures/mocha-esm/test-3.js +14 -0
  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 +99 -94
  74. package/test/test-webpack-merge.js +11 -9
  75. package/.github/workflows/main.yml +0 -21
@@ -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
+
@@ -0,0 +1,61 @@
1
+ name: Test & Maybe Release
2
+ on: [push, pull_request]
3
+ jobs:
4
+ test:
5
+ strategy:
6
+ fail-fast: false
7
+ matrix:
8
+ node: [14.x, 16.x]
9
+ os: [macos-latest, ubuntu-latest, windows-latest]
10
+ runs-on: ${{ matrix.os }}
11
+ steps:
12
+ - name: Checkout Repository
13
+ uses: actions/checkout@v2.3.4
14
+ - name: Use Node.js ${{ matrix.node }}
15
+ uses: actions/setup-node@v2.4.0
16
+ with:
17
+ node-version: ${{ matrix.node }}
18
+ - name: Install Dependencies
19
+ run: |
20
+ npm install --no-progress
21
+ - name: Run tests
22
+ run: |
23
+ npm config set script-shell bash
24
+ npm test
25
+ release:
26
+ name: Release
27
+ needs: test
28
+ runs-on: ubuntu-latest
29
+ if: github.event_name == 'push' && github.ref == 'refs/heads/master'
30
+ steps:
31
+ - name: Checkout
32
+ uses: actions/checkout@v2.3.4
33
+ with:
34
+ fetch-depth: 0
35
+ - name: Setup Node.js
36
+ uses: actions/setup-node@v2.4.0
37
+ with:
38
+ node-version: 14
39
+ - name: Install dependencies
40
+ run: |
41
+ npm install --no-progress --no-package-lock --no-save
42
+ - name: Build
43
+ run: |
44
+ npm run build
45
+ - name: Install plugins
46
+ run: |
47
+ npm install \
48
+ @semantic-release/commit-analyzer \
49
+ conventional-changelog-conventionalcommits \
50
+ @semantic-release/release-notes-generator \
51
+ @semantic-release/npm \
52
+ @semantic-release/github \
53
+ @semantic-release/git \
54
+ @semantic-release/changelog \
55
+ --no-progress --no-package-lock --no-save
56
+ - name: Release
57
+ env:
58
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
59
+ NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
60
+ run: npx semantic-release
61
+
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) {
@@ -79,6 +79,9 @@ async function _run (outputDir, port, timeout, mode, runner, coverage, callback)
79
79
  maybeEnd()
80
80
  })
81
81
 
82
+ page.on('error', (error) => console.error(error))
83
+ page.on('pageerror', (error) => console.error(error))
84
+
82
85
  await page.exposeFunction('polendinaEnd', (errors) => {
83
86
  end(errors)
84
87
  })
@@ -109,5 +112,3 @@ async function _run (outputDir, port, timeout, mode, runner, coverage, callback)
109
112
  browser.close().then(cb).catch(cb)
110
113
  }, timeout * 1000).unref()
111
114
  }
112
-
113
- module.exports = run
@@ -1,11 +1,14 @@
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 bundleRun = path.resolve(options.outputDir, runner)
5
+ const __dirname = fileURLToPath(path.dirname(import.meta.url))
6
+
7
+ export function webpackConfig (env, options, runner) {
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 }))
8
- }, [])
11
+ }, []).map(path.normalize)
9
12
 
10
13
  // our globs may be fruitless
11
14
  if (!testFiles.length) {
@@ -16,6 +19,7 @@ module.exports = function (env, options, runner) {
16
19
 
17
20
  return {
18
21
  mode: 'development',
22
+ context: process.cwd(),
19
23
  entry: testFiles,
20
24
  output: {
21
25
  path: path.resolve(process.cwd(), options.outputDir),
@@ -27,31 +31,24 @@ module.exports = function (env, options, runner) {
27
31
  },
28
32
  resolve: {
29
33
  modules: [
30
- path.join(__dirname, '../node_modules'),
31
- path.join(process.cwd(), 'node_modules')
34
+ path.join(process.cwd(), 'node_modules'),
35
+ path.join(__dirname, '../node_modules')
32
36
  ]
33
37
  },
34
38
  resolveLoader: {
35
39
  modules: [
36
- path.join(__dirname, '../node_modules'),
37
- path.join(process.cwd(), 'node_modules')
40
+ path.join(process.cwd(), 'node_modules'),
41
+ path.join(__dirname, '../node_modules')
38
42
  ]
39
43
  },
40
- node: {
41
- dgram: 'empty',
42
- fs: 'empty',
43
- net: 'empty',
44
- tls: 'empty',
45
- dns: 'empty',
46
- child_process: 'empty'
47
- },
48
44
  module: {
49
45
  rules: [
50
46
  {
51
47
  test: testFiles,
52
48
  exclude: [/node_modules/, bundleRun],
49
+ type: 'javascript/auto', // needed so the wrap-loader can get a sync require() in
53
50
  use: [{
54
- loader: require.resolve('./wrap-loader.js'),
51
+ loader: path.resolve(__dirname, 'wrap-loader.cjs'),
55
52
  options: options
56
53
  }]
57
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.resolve(argv.outputDir, 'test-registry.js')}`)})
23
- registry.argv = JSON.parse('${JSON.stringify(argv)}')
24
+ const { registry } = require(${JSON.stringify(`!!${path.normalize(path.resolve(argv.outputDir, 'test-registry.js'))}`)})
25
+ registry.argv = JSON.parse(${JSON.stringify(JSON.stringify(argv))})
24
26
  registry.tests.push({
25
- name: JSON.parse('${JSON.stringify(path.relative(process.cwd(), remainingRequest))}'),
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,33 +1,33 @@
1
1
  {
2
2
  "name": "polendina",
3
- "version": "1.0.0",
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": "^2.0.0",
10
- "raw-loader": "^4.0.0",
11
- "rimraf": "^3.0.0",
12
- "st": "^2.0.0",
13
- "strip-ansi": "^6.0.0",
14
- "webpack": "^4.41.5",
15
- "webpack-merge": "^4.2.2",
16
- "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"
17
22
  },
18
23
  "bin": {
19
24
  "polendina": "./polendina-cli.js",
20
25
  "polendina-node": "./polendina-node-cli.js"
21
26
  },
22
- "devDependencies": {
23
- "mocha": "^7.0.0",
24
- "standard": "^14.3.1",
25
- "tape": "^4.12.1"
26
- },
27
27
  "scripts": {
28
- "lint": "standard",
28
+ "lint": "npm_config_yes=true npx standard",
29
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",
30
- "test:run": "mocha test/test-*.js",
30
+ "test:run": "npm_config_yes=true npx mocha test/test-*.js",
31
31
  "test": "npm run lint && npm run test:install && npm run test:run"
32
32
  },
33
33
  "repository": {
@@ -45,5 +45,86 @@
45
45
  "test"
46
46
  ],
47
47
  "author": "Rod <rod@vagg.org> (http://r.va.gg/)",
48
- "license": "Apache-2.0"
48
+ "license": "Apache-2.0",
49
+ "release": {
50
+ "branches": [
51
+ "master"
52
+ ],
53
+ "plugins": [
54
+ [
55
+ "@semantic-release/commit-analyzer",
56
+ {
57
+ "preset": "conventionalcommits",
58
+ "releaseRules": [
59
+ {
60
+ "breaking": true,
61
+ "release": "major"
62
+ },
63
+ {
64
+ "revert": true,
65
+ "release": "patch"
66
+ },
67
+ {
68
+ "type": "feat",
69
+ "release": "minor"
70
+ },
71
+ {
72
+ "type": "fix",
73
+ "release": "patch"
74
+ },
75
+ {
76
+ "type": "chore",
77
+ "release": "patch"
78
+ },
79
+ {
80
+ "type": "docs",
81
+ "release": "patch"
82
+ },
83
+ {
84
+ "type": "test",
85
+ "release": "patch"
86
+ },
87
+ {
88
+ "scope": "no-release",
89
+ "release": false
90
+ }
91
+ ]
92
+ }
93
+ ],
94
+ [
95
+ "@semantic-release/release-notes-generator",
96
+ {
97
+ "preset": "conventionalcommits",
98
+ "presetConfig": {
99
+ "types": [
100
+ {
101
+ "type": "feat",
102
+ "section": "Features"
103
+ },
104
+ {
105
+ "type": "fix",
106
+ "section": "Bug Fixes"
107
+ },
108
+ {
109
+ "type": "chore",
110
+ "section": "Trivial Changes"
111
+ },
112
+ {
113
+ "type": "docs",
114
+ "section": "Trivial Changes"
115
+ },
116
+ {
117
+ "type": "test",
118
+ "section": "Tests"
119
+ }
120
+ ]
121
+ }
122
+ }
123
+ ],
124
+ "@semantic-release/changelog",
125
+ "@semantic-release/npm",
126
+ "@semantic-release/github",
127
+ "@semantic-release/git"
128
+ ]
129
+ }
49
130
  }
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
  }
@@ -89,7 +112,12 @@ class Polendina {
89
112
  }
90
113
 
91
114
  _executeMode (mode) {
92
- const mount = st({ path: this.outputDir, index: 'index.html', url: '/' })
115
+ const mount = st({
116
+ path: this.outputDir,
117
+ index: 'index.html',
118
+ url: '/',
119
+ cache: false
120
+ })
93
121
  return new Promise((resolve, reject) => {
94
122
  const server = http.createServer((req, res) => {
95
123
  mount(req, res, () => {
@@ -114,5 +142,3 @@ class Polendina {
114
142
  })
115
143
  }
116
144
  }
117
-
118
- module.exports = Polendina