polendina 2.0.0-alpha2 → 2.0.2

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.
@@ -1,108 +0,0 @@
1
- /* globals WorkerGlobalScope ServiceWorkerGlobalScope clients */
2
-
3
- import { registry } from './test-registry.js'
4
-
5
- const inPage =
6
- typeof window !== 'undefined' &&
7
- window.location &&
8
- typeof WorkerGlobalScope === 'undefined'
9
- const inServiceWorker = !inPage &&
10
- typeof ServiceWorkerGlobalScope !== 'undefined' &&
11
- globalThis instanceof ServiceWorkerGlobalScope
12
- const inWorker = !inPage && !inServiceWorker &&
13
- typeof WorkerGlobalScope !== 'undefined' &&
14
- globalThis instanceof WorkerGlobalScope
15
- let _executionQueue = Promise.resolve()
16
-
17
- export { registry }
18
- export function executionQueue (fn) {
19
- _executionQueue = _executionQueue.then(fn)
20
- return _executionQueue
21
- }
22
-
23
- export const log = {
24
- info: (...args) => {
25
- executionQueue(() => globalThis.polendinaLog(['info'].concat(args)))
26
- return executionQueue
27
- },
28
- // TODO
29
- warn: (...args) => {
30
- executionQueue(() => globalThis.polendinaLog(['warn'].concat(args)))
31
- return executionQueue
32
- },
33
- // TODO
34
- error: (...args) => {
35
- executionQueue(() => globalThis.polendinaLog(['error'].concat(args)))
36
- return executionQueue
37
- }
38
- }
39
-
40
- function setupWorkerGlobals () {
41
- globalThis.polendinaLog = async function (...args) {
42
- globalThis.postMessage(['polendinaLog'].concat(args))
43
- }
44
-
45
- globalThis.polendinaWrite = async function (...args) {
46
- globalThis.postMessage(['polendinaWrite'].concat(args))
47
- }
48
-
49
- globalThis.polendinaEnd = async function (...args) {
50
- globalThis.postMessage(['polendinaEnd'].concat(args))
51
- }
52
- }
53
-
54
- function setupServiceWorkerGlobals () {
55
- async function _postMessage (msg) {
56
- for (const client of await clients.matchAll()) {
57
- client.postMessage(msg)
58
- }
59
- }
60
-
61
- globalThis.polendinaLog = async function (...args) {
62
- _postMessage(['polendinaLog'].concat(args))
63
- }
64
-
65
- globalThis.polendinaWrite = async function (...args) {
66
- _postMessage(['polendinaWrite'].concat(args))
67
- }
68
-
69
- globalThis.polendinaEnd = async function (...args) {
70
- _postMessage(['polendinaEnd'].concat(args))
71
- }
72
- }
73
-
74
- function setupLogging () {
75
- console.log = function (...args) {
76
- try {
77
- if (/BrowserStdout.*write/.test(new Error().stack)) {
78
- // the BrowserStdout polyfill (Mocha ships with among others) that converts
79
- // process.stdout.write() to console.log()
80
- // so we strip out the extra \n that necessarily inserts
81
- // args[0] = args[0].replace(/\n$/, '')
82
- executionQueue(() => globalThis.polendinaWrite(args))
83
- return
84
- }
85
- } catch (err) {}
86
- log.info.apply(null, args)
87
- }
88
-
89
- // TODO: differentiate
90
- console.warn = log.warn
91
- console.error = log.error
92
- }
93
-
94
- export async function setup () {
95
- if (inWorker) {
96
- setupWorkerGlobals()
97
- } else if (inServiceWorker) {
98
- await new Promise((resolve, reject) => {
99
- globalThis.addEventListener('activate', (event) => {
100
- event.waitUntil(globalThis.clients.claim())
101
- setupServiceWorkerGlobals()
102
- resolve()
103
- })
104
- })
105
- }
106
-
107
- setupLogging()
108
- }
@@ -1,10 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="utf-8" />
5
- <title>Tests</title>
6
- </head>
7
- <body>
8
- <script src="page-run.js"></script>
9
- </body>
10
- </html>
@@ -1,46 +0,0 @@
1
- /* globals self Worker */
2
-
3
- // loaded as script file in index.html, determines how to load the bundle
4
-
5
- const isWorkerMode = /mode=worker/.test(window.location.search)
6
- const isServiceWorkerMode = /mode=serviceworker/.test(window.location.search)
7
- const _consoleLog = console ? console.log : () => {}
8
-
9
- function runPage () {
10
- const script = document.createElement('script')
11
- script.type = 'text/javascript'
12
- script.src = 'bundle.js'
13
- document.head.appendChild(script)
14
- }
15
-
16
- function onWorkerMessage (msg) {
17
- if (!Array.isArray(msg.data)) {
18
- return
19
- }
20
-
21
- if (!self[msg.data[0]]) {
22
- _consoleLog.apply(console, msg.data)
23
- } else {
24
- self[msg.data[0]].apply(null, msg.data.slice(1))
25
- }
26
- }
27
-
28
- function runWorker () {
29
- const worker = new Worker('bundle.js')
30
- worker.addEventListener('message', onWorkerMessage, false)
31
- }
32
-
33
- function runServiceWorker () {
34
- navigator.serviceWorker.register('bundle.js', { scope: './' })
35
- navigator.serviceWorker.addEventListener('message', onWorkerMessage, false)
36
- }
37
-
38
- window.addEventListener('load', () => {
39
- if (isWorkerMode) {
40
- runWorker()
41
- } else if (isServiceWorkerMode) {
42
- runServiceWorker()
43
- } else {
44
- runPage()
45
- }
46
- })
@@ -1,39 +0,0 @@
1
- // in-browser setup and runner for Tape, at end of bundle
2
-
3
- import tape from 'tape'
4
- import { registry, setup, executionQueue } from './common-run.js'
5
- import { Transform } from 'stream'
6
-
7
- function runTape () {
8
- let failures = 0
9
-
10
- const stream = new Transform({
11
- transform (chunk, encoding, callback) {
12
- executionQueue(() => {
13
- globalThis.polendinaWrite(chunk.toString())
14
- .catch(callback)
15
- .then(callback)
16
- })
17
- },
18
-
19
- flush (callback) {
20
- executionQueue(() => {
21
- globalThis.polendinaEnd(failures)
22
- .catch(callback)
23
- .then(callback)
24
- })
25
- }
26
- })
27
-
28
- tape.getHarness({ stream })
29
-
30
- tape.getHarness().onFailure((...args) => {
31
- failures = 1
32
- })
33
-
34
- for (const mod of registry.tests) {
35
- mod.load()
36
- }
37
- }
38
-
39
- setup().then(runTape)
@@ -1,6 +0,0 @@
1
- // see wrap-loader.js
2
-
3
- export const registry = {
4
- argv: null,
5
- tests: []
6
- }