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
@@ -1,114 +1,119 @@
1
1
  /* globals describe it */
2
2
 
3
- const assert = require('assert')
4
- const path = require('path')
5
- const { runCli } = require('./common')
3
+ import assert from 'assert'
4
+ import path from 'path'
5
+ import { fileURLToPath } from 'url'
6
+ import { runCli } from './common.js'
6
7
 
7
- const bareSyncFixture = path.join(__dirname, 'fixtures/bare-sync')
8
- const bareSyncFailureFixture = path.join(__dirname, 'fixtures/bare-sync-failure')
8
+ const __dirname = fileURLToPath(path.dirname(import.meta.url))
9
9
 
10
- describe('basic bare-sync', function () {
11
- this.timeout(20000)
12
- const expectedTemplate = `
10
+ for (const type of ['cjs', 'esm']) {
11
+ const bareSyncFixture = path.join(__dirname, `fixtures/bare-sync${type === 'esm' ? '-esm' : ''}`)
12
+ const bareSyncFailureFixture = path.join(__dirname, `fixtures/bare-sync-failure${type === 'esm' ? '-esm' : ''}`)
13
+
14
+ describe(`basic bare-sync (${type})`, function () {
15
+ this.timeout(20000)
16
+ const expectedTemplate = `
13
17
  testing is WORKER
14
18
  ✔ test-1.js
15
19
  testing bare fixture
16
20
  ✔ test-2.js
17
21
  `
18
22
 
19
- it('should run in page', async () => {
20
- const { stdout, code } = await runCli(bareSyncFixture, '--runner=bare-sync')
21
- assert.strictEqual(code, 0, 'exited with zero exit code')
22
- const expected = expectedTemplate.replace(/WORKER/, 'not in worker')
23
- assert.ok(stdout.includes(expected), 'stdout contains expected test output')
24
- assert.ok(stdout.includes('Running bare-sync page tests with Puppeteer'), 'stdout contains expected output for running in page')
25
- })
23
+ it('should run in page', async () => {
24
+ const { stdout, code } = await runCli(bareSyncFixture, '--runner=bare-sync')
25
+ assert.strictEqual(code, 0, 'exited with zero exit code')
26
+ const expected = expectedTemplate.replace(/WORKER/, 'not in worker')
27
+ assert.ok(stdout.includes(expected), 'stdout contains expected test output')
28
+ assert.ok(stdout.includes('Running bare-sync page tests with Puppeteer'), 'stdout contains expected output for running in page')
29
+ })
26
30
 
27
- it('should run in worker', async () => {
28
- const { stdout, code } = await runCli(bareSyncFixture, '--runner=bare-sync --worker --page=false')
29
- assert.strictEqual(code, 0, 'exited with zero exit code')
30
- const expected = expectedTemplate.replace(/WORKER/, 'in worker')
31
- assert.ok(stdout.includes(expected), 'stdout contains expected test output')
32
- assert.ok(stdout.includes('Running bare-sync worker tests with Puppeteer'), 'stdout contains expected output for running in page')
33
- })
31
+ it('should run in worker', async () => {
32
+ const { stdout, code } = await runCli(bareSyncFixture, '--runner=bare-sync --worker --page=false')
33
+ assert.strictEqual(code, 0, 'exited with zero exit code')
34
+ const expected = expectedTemplate.replace(/WORKER/, 'in worker')
35
+ assert.ok(stdout.includes(expected), 'stdout contains expected test output')
36
+ assert.ok(stdout.includes('Running bare-sync worker tests with Puppeteer'), 'stdout contains expected output for running in page')
37
+ })
34
38
 
35
- it('should run in serviceworker', async () => {
36
- const { stdout, code } = await runCli(bareSyncFixture, '--runner=bare-sync --serviceworker --page=false')
37
- assert.strictEqual(code, 0, 'exited with zero exit code')
38
- const expected = expectedTemplate.replace(/WORKER/, 'in serviceworker')
39
- assert.ok(stdout.includes(expected), 'stdout contains expected test output')
40
- assert.ok(stdout.includes('Running bare-sync serviceworker tests with Puppeteer'), 'stdout contains expected output for running in page')
41
- })
39
+ it('should run in serviceworker', async () => {
40
+ const { stdout, code } = await runCli(bareSyncFixture, '--runner=bare-sync --serviceworker --page=false')
41
+ assert.strictEqual(code, 0, 'exited with zero exit code')
42
+ const expected = expectedTemplate.replace(/WORKER/, 'in serviceworker')
43
+ assert.ok(stdout.includes(expected), 'stdout contains expected test output')
44
+ assert.ok(stdout.includes('Running bare-sync serviceworker tests with Puppeteer'), 'stdout contains expected output for running in page')
45
+ })
42
46
 
43
- it('should run in page, worker and serviceworker', async () => {
44
- const { stdout, code } = await runCli(bareSyncFixture, '--runner=bare-sync --worker --serviceworker')
45
- assert.strictEqual(code, 0, 'exited with zero exit code')
47
+ it('should run in page, worker and serviceworker', async () => {
48
+ const { stdout, code } = await runCli(bareSyncFixture, '--runner=bare-sync --worker --serviceworker')
49
+ assert.strictEqual(code, 0, 'exited with zero exit code')
46
50
 
47
- let expected = expectedTemplate.replace(/WORKER/, 'not in worker')
48
- assert.ok(stdout.includes(expected), 'stdout contains expected test output')
49
- assert.ok(stdout.includes('Running bare-sync serviceworker tests with Puppeteer'), 'stdout contains expected output for running in page')
51
+ let expected = expectedTemplate.replace(/WORKER/, 'not in worker')
52
+ assert.ok(stdout.includes(expected), 'stdout contains expected test output')
53
+ assert.ok(stdout.includes('Running bare-sync serviceworker tests with Puppeteer'), 'stdout contains expected output for running in page')
50
54
 
51
- expected = expectedTemplate.replace(/WORKER/, 'in worker')
52
- assert.ok(stdout.includes(expected), 'stdout contains expected test output')
53
- assert.ok(stdout.includes('Running bare-sync serviceworker tests with Puppeteer'), 'stdout contains expected output for running in page')
55
+ expected = expectedTemplate.replace(/WORKER/, 'in worker')
56
+ assert.ok(stdout.includes(expected), 'stdout contains expected test output')
57
+ assert.ok(stdout.includes('Running bare-sync serviceworker tests with Puppeteer'), 'stdout contains expected output for running in page')
54
58
 
55
- expected = expectedTemplate.replace(/WORKER/, 'in serviceworker')
56
- assert.ok(stdout.includes(expected), 'stdout contains expected test output')
57
- assert.ok(stdout.includes('Running bare-sync serviceworker tests with Puppeteer'), 'stdout contains expected output for running in page')
59
+ expected = expectedTemplate.replace(/WORKER/, 'in serviceworker')
60
+ assert.ok(stdout.includes(expected), 'stdout contains expected test output')
61
+ assert.ok(stdout.includes('Running bare-sync serviceworker tests with Puppeteer'), 'stdout contains expected output for running in page')
62
+ })
58
63
  })
59
- })
60
64
 
61
- describe('failing bare-sync', function () {
62
- this.timeout(20000)
63
- const expectedTemplate = `
65
+ describe(`failing bare-sync (${type})`, function () {
66
+ this.timeout(20000)
67
+ const expectedTemplate = `
64
68
  testing is WORKER
65
69
  ✔ test-1.js
66
70
  testing bare fixture
67
71
  ✘ test-2.js
68
72
  `
69
- const expectedStderr = 'AssertionError: \'nope\' undefined \'faily mcfailface\''
70
-
71
- it('should fail in page', async () => {
72
- let { stdout, stderr, code } = await runCli(bareSyncFailureFixture, '--runner=bare-sync')
73
- assert.strictEqual(code, 1, 'exited with non-zero exit code')
74
- stdout = stdout.replace(/^ +at .*\n/gm, '') // stack traces
75
- const expected = expectedTemplate.replace(/WORKER/, 'not in worker')
76
- assert.ok(stdout.includes(expected), 'stdout contains expected test output')
77
- assert.ok(stdout.includes('Running bare-sync page tests with Puppeteer'), 'stdout contains expected output for running in worker')
78
- assert.ok(stderr.includes(expectedStderr), 'stderr contains expected output')
79
- })
73
+ const expectedStderr = 'AssertionError: faily mcfailface'
80
74
 
81
- it('should fail in worker', async () => {
82
- let { stdout, stderr, code } = await runCli(bareSyncFailureFixture, '--runner=bare-sync --worker --page=false')
83
- assert.strictEqual(code, 1, 'exited with non-zero exit code')
84
- stdout = stdout.replace(/^ +at .*\n/gm, '') // stack traces
85
- const expected = expectedTemplate.replace(/WORKER/, 'in worker')
86
- assert.ok(stdout.includes(expected), 'stdout contains expected test output')
87
- assert.ok(stdout.includes('Running bare-sync worker tests with Puppeteer'), 'stdout contains expected output for running in worker')
88
- assert.ok(stderr.includes(expectedStderr), 'stderr contains expected output')
89
- })
75
+ it('should fail in page', async () => {
76
+ let { stdout, stderr, code } = await runCli(bareSyncFailureFixture, '--runner=bare-sync')
77
+ assert.strictEqual(code, 1, 'exited with non-zero exit code')
78
+ stdout = stdout.replace(/^ +at .*\n/gm, '') // stack traces
79
+ const expected = expectedTemplate.replace(/WORKER/, 'not in worker')
80
+ assert.ok(stdout.includes(expected), 'stdout contains expected test output')
81
+ assert.ok(stdout.includes('Running bare-sync page tests with Puppeteer'), 'stdout contains expected output for running in worker')
82
+ assert.ok(stderr.includes(expectedStderr), 'stderr contains expected output')
83
+ })
90
84
 
91
- it('should fail in serviceworker', async () => {
92
- let { stdout, stderr, code } = await runCli(bareSyncFailureFixture, '--runner=bare-sync --serviceworker --page=false')
93
- assert.strictEqual(code, 1, 'exited with non-zero exit code')
94
- stdout = stdout.replace(/^ +at .*\n/gm, '') // stack traces
95
- const expected = expectedTemplate.replace(/WORKER/, 'in serviceworker')
96
- assert.ok(stdout.includes(expected), 'stdout contains expected test output')
97
- assert.ok(stdout.includes('Running bare-sync serviceworker tests with Puppeteer'), 'stdout contains expected output for running in worker')
98
- assert.ok(stderr.includes(expectedStderr), 'stderr contains expected output')
99
- })
85
+ it('should fail in worker', async () => {
86
+ let { stdout, stderr, code } = await runCli(bareSyncFailureFixture, '--runner=bare-sync --worker --page=false')
87
+ assert.strictEqual(code, 1, 'exited with non-zero exit code')
88
+ stdout = stdout.replace(/^ +at .*\n/gm, '') // stack traces
89
+ const expected = expectedTemplate.replace(/WORKER/, 'in worker')
90
+ assert.ok(stdout.includes(expected), 'stdout contains expected test output')
91
+ assert.ok(stdout.includes('Running bare-sync worker tests with Puppeteer'), 'stdout contains expected output for running in worker')
92
+ assert.ok(stderr.includes(expectedStderr), 'stderr contains expected output')
93
+ })
94
+
95
+ it('should fail in serviceworker', async () => {
96
+ let { stdout, stderr, code } = await runCli(bareSyncFailureFixture, '--runner=bare-sync --serviceworker --page=false')
97
+ assert.strictEqual(code, 1, 'exited with non-zero exit code')
98
+ stdout = stdout.replace(/^ +at .*\n/gm, '') // stack traces
99
+ const expected = expectedTemplate.replace(/WORKER/, 'in serviceworker')
100
+ assert.ok(stdout.includes(expected), 'stdout contains expected test output')
101
+ assert.ok(stdout.includes('Running bare-sync serviceworker tests with Puppeteer'), 'stdout contains expected output for running in worker')
102
+ assert.ok(stderr.includes(expectedStderr), 'stderr contains expected output')
103
+ })
100
104
 
101
- it('should fail in page and not run in worker', async () => {
102
- let { stdout, stderr, code } = await runCli(bareSyncFailureFixture, '--runner=bare-sync --worker')
103
- assert.strictEqual(code, 1, 'exited with non-zero exit code')
104
- stdout = stdout.replace(/^ +at .*\n/gm, '') // stack traces
105
- const expected = expectedTemplate.replace(/WORKER/, 'not in worker')
106
- let found = stdout.indexOf(expected)
107
- assert.ok(found > -1, 'stdout contains expected test output')
108
- found = stdout.indexOf(expected, found + 1)
109
- assert.ok(found === -1, 'stdout doesn\'t contain second instance of expected test output')
110
- assert.ok(stdout.includes('Running bare-sync page tests with Puppeteer'), 'stdout contains expected output for running in page')
111
- assert.ok(!stdout.includes('Running bare-sync worker tests with Puppeteer'), 'stdout doesn\'t contain expected output for running in worker')
112
- assert.ok(stderr.includes(expectedStderr), 'stderr contains expected output')
105
+ it('should fail in page and not run in worker', async () => {
106
+ let { stdout, stderr, code } = await runCli(bareSyncFailureFixture, '--runner=bare-sync --worker')
107
+ assert.strictEqual(code, 1, 'exited with non-zero exit code')
108
+ stdout = stdout.replace(/^ +at .*\n/gm, '') // stack traces
109
+ const expected = expectedTemplate.replace(/WORKER/, 'not in worker')
110
+ let found = stdout.indexOf(expected)
111
+ assert.ok(found > -1, 'stdout contains expected test output')
112
+ found = stdout.indexOf(expected, found + 1)
113
+ assert.ok(found === -1, 'stdout doesn\'t contain second instance of expected test output')
114
+ assert.ok(stdout.includes('Running bare-sync page tests with Puppeteer'), 'stdout contains expected output for running in page')
115
+ assert.ok(!stdout.includes('Running bare-sync worker tests with Puppeteer'), 'stdout doesn\'t contain expected output for running in worker')
116
+ assert.ok(stderr.includes(expectedStderr), 'stderr contains expected output')
117
+ })
113
118
  })
114
- })
119
+ }
@@ -1,78 +1,82 @@
1
1
  /* globals describe it */
2
2
 
3
- const assert = require('assert')
4
- const path = require('path')
5
- const { runCli } = require('./common')
3
+ import assert from 'assert'
4
+ import path from 'path'
5
+ import { fileURLToPath } from 'url'
6
+ import { runCli } from './common.js'
6
7
 
7
- const mochaFixture = path.join(__dirname, 'fixtures/mocha')
8
- const mochaFailureFixture = path.join(__dirname, 'fixtures/mocha-failure')
8
+ const __dirname = fileURLToPath(path.dirname(import.meta.url))
9
9
 
10
10
  function removeTimings (stdout) {
11
11
  return stdout.replace(/\(\d+ms\)/g, '(Xms)')
12
12
  }
13
13
 
14
- describe('basic mocha', function () {
15
- this.timeout(20000)
16
- const expectedTemplate = `
14
+ for (const type of ['cjs', 'esm']) {
15
+ const mochaFixture = path.join(__dirname, `fixtures/mocha${type === 'esm' ? '-esm' : ''}`)
16
+ const mochaFailureFixture = path.join(__dirname, `fixtures/mocha-failure${type === 'esm' ? '-esm' : ''}`)
17
+
18
+ describe(`basic mocha (${type})`, function () {
19
+ this.timeout(20000)
20
+ const expectedTemplate = `
17
21
  test suite 1
18
- ✓ test case 1
19
- ✓ test case 2
22
+ ✅ test case 1
23
+ ✅ test case 2
20
24
 
21
25
  test suite 2 - worker
22
- ✓ is WORKER
26
+ ✅ is WORKER
23
27
 
24
28
  test suite 3
25
- ✓ test case 1
26
- ✓ test case 2
29
+ ✅ test case 1
30
+ ✅ test case 2
27
31
  `
28
32
 
29
- it('should run in page', async () => {
30
- const { stdout, code } = await runCli(mochaFixture)
31
- assert.strictEqual(code, 0, 'exited with zero exit code')
32
- const expected = expectedTemplate.replace(/WORKER/, 'not in worker')
33
- assert.ok(stdout.includes(expected), 'stdout contains expected test output')
34
- assert.ok(stdout.includes('Running mocha page tests with Puppeteer'), 'stdout contains expected output for running in page')
35
- })
36
-
37
- it('should run in worker', async () => {
38
- const { stdout, code } = await runCli(mochaFixture, '--worker --page=false')
39
- assert.strictEqual(code, 0, 'exited with zero exit code')
40
- const expected = expectedTemplate.replace(/WORKER/, 'in worker')
41
- assert.ok(stdout.includes(expected), 'stdout contains expected test output')
42
- assert.ok(stdout.includes('Running mocha worker tests with Puppeteer'), 'stdout contains expected output for running in worker')
43
- })
44
-
45
- it('should run in serviceworker', async () => {
46
- const { stdout, code } = await runCli(mochaFixture, '--serviceworker --page=false')
47
- assert.strictEqual(code, 0, 'exited with zero exit code')
48
- const expected = expectedTemplate.replace(/WORKER/, 'in serviceworker')
49
- assert.ok(stdout.includes(expected), 'stdout contains expected test output')
50
- assert.ok(stdout.includes('Running mocha serviceworker tests with Puppeteer'), 'stdout contains expected output for running in worker')
33
+ it('should run in page', async () => {
34
+ const { stdout, code } = await runCli(mochaFixture)
35
+ assert.strictEqual(code, 0, 'exited with zero exit code')
36
+ const expected = expectedTemplate.replace(/WORKER/, 'not in worker')
37
+ assert.ok(stdout.includes(expected), 'stdout contains expected test output')
38
+ assert.ok(stdout.includes('Running mocha page tests with Puppeteer'), 'stdout contains expected output for running in page')
39
+ })
40
+
41
+ it('should run in worker', async () => {
42
+ const { stdout, code } = await runCli(mochaFixture, '--worker --page=false')
43
+ assert.strictEqual(code, 0, 'exited with zero exit code')
44
+ const expected = expectedTemplate.replace(/WORKER/, 'in worker')
45
+ assert.ok(stdout.includes(expected), 'stdout contains expected test output')
46
+ assert.ok(stdout.includes('Running mocha worker tests with Puppeteer'), 'stdout contains expected output for running in worker')
47
+ })
48
+
49
+ it('should run in serviceworker', async () => {
50
+ const { stdout, code } = await runCli(mochaFixture, '--serviceworker --page=false')
51
+ assert.strictEqual(code, 0, 'exited with zero exit code')
52
+ const expected = expectedTemplate.replace(/WORKER/, 'in serviceworker')
53
+ assert.ok(stdout.includes(expected), 'stdout contains expected test output')
54
+ assert.ok(stdout.includes('Running mocha serviceworker tests with Puppeteer'), 'stdout contains expected output for running in worker')
55
+ })
56
+
57
+ it('should run in page, worker and serviceworker', async () => {
58
+ const { stdout, code } = await runCli(mochaFixture, '--worker --serviceworker')
59
+ assert.strictEqual(code, 0, 'exited with zero exit code')
60
+
61
+ let expected = expectedTemplate.replace(/WORKER/, 'not in worker')
62
+ assert.ok(stdout.includes(expected), 'stdout contains expected test output')
63
+ assert.ok(stdout.includes('Running mocha page tests with Puppeteer'), 'stdout contains expected output for running in page')
64
+
65
+ expected = expectedTemplate.replace(/WORKER/, 'in worker')
66
+ assert.ok(stdout.includes(expected), 'stdout contains expected test output')
67
+ assert.ok(stdout.includes('Running mocha worker tests with Puppeteer'), 'stdout contains expected output for running in worker')
68
+
69
+ expected = expectedTemplate.replace(/WORKER/, 'in serviceworker')
70
+ assert.ok(stdout.includes(expected), 'stdout contains expected test output')
71
+ assert.ok(stdout.includes('Running mocha serviceworker tests with Puppeteer'), 'stdout contains expected output for running in worker')
72
+ })
51
73
  })
52
74
 
53
- it('should run in page, worker and serviceworker', async () => {
54
- const { stdout, code } = await runCli(mochaFixture, '--worker --serviceworker')
55
- assert.strictEqual(code, 0, 'exited with zero exit code')
56
-
57
- let expected = expectedTemplate.replace(/WORKER/, 'not in worker')
58
- assert.ok(stdout.includes(expected), 'stdout contains expected test output')
59
- assert.ok(stdout.includes('Running mocha page tests with Puppeteer'), 'stdout contains expected output for running in page')
60
-
61
- expected = expectedTemplate.replace(/WORKER/, 'in worker')
62
- assert.ok(stdout.includes(expected), 'stdout contains expected test output')
63
- assert.ok(stdout.includes('Running mocha worker tests with Puppeteer'), 'stdout contains expected output for running in worker')
64
-
65
- expected = expectedTemplate.replace(/WORKER/, 'in serviceworker')
66
- assert.ok(stdout.includes(expected), 'stdout contains expected test output')
67
- assert.ok(stdout.includes('Running mocha serviceworker tests with Puppeteer'), 'stdout contains expected output for running in worker')
68
- })
69
- })
70
-
71
- describe('failing mocha', function () {
72
- this.timeout(20000)
73
- const expectedTemplate = `
75
+ describe(`failing mocha (${type})`, function () {
76
+ this.timeout(20000)
77
+ const expectedTemplate = `
74
78
  test suite 1 - worker
75
- ✓ is WORKER
79
+ ✅ is WORKER
76
80
 
77
81
  test suite 2 - failing
78
82
  1) should fail
@@ -86,43 +90,44 @@ describe('failing mocha', function () {
86
90
  Error: failing test
87
91
  `
88
92
 
89
- it('should fail in page', async () => {
90
- let { stdout, code } = await runCli(mochaFailureFixture)
91
- assert.strictEqual(code, 1, 'exited with non-zero exit code')
92
- stdout = removeTimings(stdout)
93
- const expected = expectedTemplate.replace(/WORKER/, 'not in worker')
94
- assert.ok(stdout.includes(expected), 'stdout contains expected test output')
95
- assert.ok(stdout.includes('Running mocha page tests with Puppeteer'), 'stdout contains expected output for running in worker')
96
- })
97
-
98
- it('should fail in worker', async () => {
99
- let { stdout, code } = await runCli(mochaFailureFixture, '--worker --page=false')
100
- assert.strictEqual(code, 1, 'exited with non-zero exit code')
101
- stdout = removeTimings(stdout)
102
- const expected = expectedTemplate.replace(/WORKER/, 'in worker')
103
- assert.ok(stdout.includes(expected), 'stdout contains expected test output')
104
- assert.ok(stdout.includes('Running mocha worker tests with Puppeteer'), 'stdout contains expected output for running in worker')
105
- })
106
-
107
- it('should fail in serviceworker', async () => {
108
- let { stdout, code } = await runCli(mochaFailureFixture, '--serviceworker --page=false')
109
- assert.strictEqual(code, 1, 'exited with non-zero exit code')
110
- stdout = removeTimings(stdout)
111
- const expected = expectedTemplate.replace(/WORKER/, 'in serviceworker')
112
- assert.ok(stdout.includes(expected), 'stdout contains expected test output')
113
- assert.ok(stdout.includes('Running mocha serviceworker tests with Puppeteer'), 'stdout contains expected output for running in worker')
114
- })
115
-
116
- it('should fail in page and not run in worker', async () => {
117
- let { stdout, code } = await runCli(mochaFailureFixture, '--worker')
118
- assert.strictEqual(code, 1, 'exited with non-zero exit code')
119
- stdout = removeTimings(stdout)
120
- const expected = expectedTemplate.replace(/WORKER/, 'not in worker')
121
- let found = stdout.indexOf(expected)
122
- assert.ok(found > -1, 'stdout contains expected test output')
123
- found = stdout.indexOf(expected, found + 1)
124
- assert.ok(found === -1, 'stdout doesn\'t contain second instance of expected test output')
125
- assert.ok(stdout.includes('Running mocha page tests with Puppeteer'), 'stdout contains expected output for running in page')
126
- assert.ok(!stdout.includes('Running mocha worker tests with Puppeteer'), 'stdout doesn\'t contain expected output for running in worker')
93
+ it('should fail in page', async () => {
94
+ let { stdout, code } = await runCli(mochaFailureFixture)
95
+ assert.strictEqual(code, 1, 'exited with non-zero exit code')
96
+ stdout = removeTimings(stdout)
97
+ const expected = expectedTemplate.replace(/WORKER/, 'not in worker')
98
+ assert.ok(stdout.includes(expected), 'stdout contains expected test output')
99
+ assert.ok(stdout.includes('Running mocha page tests with Puppeteer'), 'stdout contains expected output for running in worker')
100
+ })
101
+
102
+ it('should fail in worker', async () => {
103
+ let { stdout, code } = await runCli(mochaFailureFixture, '--worker --page=false')
104
+ assert.strictEqual(code, 1, 'exited with non-zero exit code')
105
+ stdout = removeTimings(stdout)
106
+ const expected = expectedTemplate.replace(/WORKER/, 'in worker')
107
+ assert.ok(stdout.includes(expected), 'stdout contains expected test output')
108
+ assert.ok(stdout.includes('Running mocha worker tests with Puppeteer'), 'stdout contains expected output for running in worker')
109
+ })
110
+
111
+ it('should fail in serviceworker', async () => {
112
+ let { stdout, code } = await runCli(mochaFailureFixture, '--serviceworker --page=false')
113
+ assert.strictEqual(code, 1, 'exited with non-zero exit code')
114
+ stdout = removeTimings(stdout)
115
+ const expected = expectedTemplate.replace(/WORKER/, 'in serviceworker')
116
+ assert.ok(stdout.includes(expected), 'stdout contains expected test output')
117
+ assert.ok(stdout.includes('Running mocha serviceworker tests with Puppeteer'), 'stdout contains expected output for running in worker')
118
+ })
119
+
120
+ it('should fail in page and not run in worker', async () => {
121
+ let { stdout, code } = await runCli(mochaFailureFixture, '--worker')
122
+ assert.strictEqual(code, 1, 'exited with non-zero exit code')
123
+ stdout = removeTimings(stdout)
124
+ const expected = expectedTemplate.replace(/WORKER/, 'not in worker')
125
+ let found = stdout.indexOf(expected)
126
+ assert.ok(found > -1, 'stdout contains expected test output')
127
+ found = stdout.indexOf(expected, found + 1)
128
+ assert.ok(found === -1, 'stdout doesn\'t contain second instance of expected test output')
129
+ assert.ok(stdout.includes('Running mocha page tests with Puppeteer'), 'stdout contains expected output for running in page')
130
+ assert.ok(!stdout.includes('Running mocha worker tests with Puppeteer'), 'stdout doesn\'t contain expected output for running in worker')
131
+ })
127
132
  })
128
- })
133
+ }
@@ -1,14 +1,13 @@
1
1
  /* globals describe it */
2
2
 
3
- const assert = require('assert')
4
- const path = require('path')
5
- const { runCommand } = require('./common')
6
- const cli = path.join(__dirname, '../polendina-node-cli.js')
3
+ import assert from 'assert'
4
+ import path from 'path'
5
+ import { fileURLToPath } from 'url'
6
+ import { runCommand } from './common.js'
7
+
8
+ const __dirname = fileURLToPath(path.dirname(import.meta.url))
7
9
 
8
- const bareSyncFixture = path.join(__dirname, 'fixtures/bare-sync')
9
- const bareSyncFailureFixture = path.join(__dirname, 'fixtures/bare-sync-failure')
10
- const bareAsyncFixture = path.join(__dirname, 'fixtures/bare-async')
11
- const bareAsyncFailureFixture = path.join(__dirname, 'fixtures/bare-async-failure')
10
+ const cli = path.join(__dirname, '../polendina-node-cli.js')
12
11
 
13
12
  function runCli (mode, cwd) {
14
13
  return runCommand(`${cli} ${mode} test*.js`, cwd)
@@ -18,40 +17,46 @@ function removeTiming (stdout) {
18
17
  return stdout.replace(/Took [\d.]+ seconds/, 'Took X seconds')
19
18
  }
20
19
 
21
- describe('polendina-node bare-sync', function () {
22
- this.timeout(20000)
23
- it('pass', async () => {
24
- const expected =
20
+ for (const type of ['cjs', 'esm']) {
21
+ const bareSyncFixture = path.join(__dirname, `fixtures/bare-sync${type === 'esm' ? '-esm' : ''}`)
22
+ const bareSyncFailureFixture = path.join(__dirname, `fixtures/bare-sync-failure${type === 'esm' ? '-esm' : ''}`)
23
+ const bareAsyncFixture = path.join(__dirname, `fixtures/bare-async${type === 'esm' ? '-esm' : ''}`)
24
+ const bareAsyncFailureFixture = path.join(__dirname, `fixtures/bare-async-failure${type === 'esm' ? '-esm' : ''}`)
25
+
26
+ describe(`polendina-node bare-sync (${type})`, function () {
27
+ this.timeout(20000)
28
+ it('pass', async () => {
29
+ const expected =
25
30
  `testing is not in worker
26
31
  ✔ test-1.js
27
32
  testing bare fixture
28
33
  ✔ test-2.js
29
34
  Took X seconds
30
35
  `
31
- const { stdout, code } = await runCli('bare-sync', bareSyncFixture)
32
- assert.strictEqual(code, 0, 'exited with zero exit code')
33
- assert.strictEqual(removeTiming(stdout), expected)
34
- })
36
+ const { stdout, code } = await runCli('bare-sync', bareSyncFixture)
37
+ assert.strictEqual(code, 0, 'exited with zero exit code')
38
+ assert.strictEqual(removeTiming(stdout), expected)
39
+ })
35
40
 
36
- it('failure', async () => {
37
- const expected =
41
+ it('failure', async () => {
42
+ const expected =
38
43
  `testing is not in worker
39
44
  ✔ test-1.js
40
45
  testing bare fixture
41
46
  ✘ test-2.js
42
47
  Took X seconds
43
48
  `
44
- const { stdout, stderr, code } = await runCli('bare-sync', bareSyncFailureFixture)
45
- assert.strictEqual(code, 1, 'exited with non-zero exit code')
46
- assert.strictEqual(removeTiming(stdout), expected)
47
- assert.ok(stderr.includes('AssertionError [ERR_ASSERTION]: \'nope\' != \'faily mcfailface\''), 'stderr contains expected output')
49
+ const { stdout, stderr, code } = await runCli('bare-sync', bareSyncFailureFixture)
50
+ assert.strictEqual(code, 1, 'exited with non-zero exit code')
51
+ assert.strictEqual(removeTiming(stdout), expected)
52
+ assert.ok(stderr.includes('AssertionError: faily mcfailface'), 'stderr contains expected output')
53
+ })
48
54
  })
49
- })
50
55
 
51
- describe('polendina-node bare-async', function () {
52
- this.timeout(20000)
53
- it('pass', async () => {
54
- const expected =
56
+ describe(`polendina-node bare-async (${type})`, function () {
57
+ this.timeout(20000)
58
+ it('pass', async () => {
59
+ const expected =
55
60
  `testing is not in worker
56
61
  ✔ test-1.js
57
62
  test-2.js
@@ -60,13 +65,13 @@ testing bare fixture
60
65
  ✔ test2
61
66
  Took X seconds
62
67
  `
63
- const { stdout, code } = await runCli('bare-async', bareAsyncFixture)
64
- assert.strictEqual(code, 0, 'exited with zero exit code')
65
- assert.strictEqual(removeTiming(stdout), expected)
66
- })
68
+ const { stdout, code } = await runCli('bare-async', bareAsyncFixture)
69
+ assert.strictEqual(code, 0, 'exited with zero exit code')
70
+ assert.strictEqual(removeTiming(stdout), expected)
71
+ })
67
72
 
68
- it('failure', async () => {
69
- const expected =
73
+ it('failure', async () => {
74
+ const expected =
70
75
  `testing is not in worker
71
76
  ✔ test-1.js
72
77
  test-2.js
@@ -75,9 +80,10 @@ testing bare fixture
75
80
  ✘ test2
76
81
  Took X seconds
77
82
  `
78
- const { stdout, stderr, code } = await runCli('bare-async', bareAsyncFailureFixture)
79
- assert.strictEqual(code, 1, 'exited with non-zero exit code')
80
- assert.strictEqual(removeTiming(stdout), expected)
81
- assert.ok(stderr.includes('AssertionError [ERR_ASSERTION]: \'nope\' != \'faily mcfailface\''), 'stderr contains expected output')
83
+ const { stdout, stderr, code } = await runCli('bare-async', bareAsyncFailureFixture)
84
+ assert.strictEqual(code, 1, 'exited with non-zero exit code')
85
+ assert.strictEqual(removeTiming(stdout), expected)
86
+ assert.ok(stderr.includes('AssertionError: faily mcfailface'), 'stderr contains expected output')
87
+ })
82
88
  })
83
- })
89
+ }