@dropthis/cli 0.1.5
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.
- package/README.md +171 -0
- package/dist/cli.cjs +1489 -0
- package/dist/cli.cjs.map +1 -0
- package/node_modules/@dropthis/node/README.md +90 -0
- package/node_modules/@dropthis/node/dist/index.cjs +1010 -0
- package/node_modules/@dropthis/node/dist/index.cjs.map +1 -0
- package/node_modules/@dropthis/node/dist/index.d.cts +408 -0
- package/node_modules/@dropthis/node/dist/index.d.ts +408 -0
- package/node_modules/@dropthis/node/dist/index.mjs +969 -0
- package/node_modules/@dropthis/node/dist/index.mjs.map +1 -0
- package/node_modules/@dropthis/node/package.json +55 -0
- package/node_modules/@nodelib/fs.scandir/LICENSE +21 -0
- package/node_modules/@nodelib/fs.scandir/README.md +171 -0
- package/node_modules/@nodelib/fs.scandir/out/adapters/fs.d.ts +20 -0
- package/node_modules/@nodelib/fs.scandir/out/adapters/fs.js +19 -0
- package/node_modules/@nodelib/fs.scandir/out/constants.d.ts +4 -0
- package/node_modules/@nodelib/fs.scandir/out/constants.js +17 -0
- package/node_modules/@nodelib/fs.scandir/out/index.d.ts +12 -0
- package/node_modules/@nodelib/fs.scandir/out/index.js +26 -0
- package/node_modules/@nodelib/fs.scandir/out/providers/async.d.ts +7 -0
- package/node_modules/@nodelib/fs.scandir/out/providers/async.js +104 -0
- package/node_modules/@nodelib/fs.scandir/out/providers/common.d.ts +1 -0
- package/node_modules/@nodelib/fs.scandir/out/providers/common.js +13 -0
- package/node_modules/@nodelib/fs.scandir/out/providers/sync.d.ts +5 -0
- package/node_modules/@nodelib/fs.scandir/out/providers/sync.js +54 -0
- package/node_modules/@nodelib/fs.scandir/out/settings.d.ts +20 -0
- package/node_modules/@nodelib/fs.scandir/out/settings.js +24 -0
- package/node_modules/@nodelib/fs.scandir/out/types/index.d.ts +20 -0
- package/node_modules/@nodelib/fs.scandir/out/types/index.js +2 -0
- package/node_modules/@nodelib/fs.scandir/out/utils/fs.d.ts +2 -0
- package/node_modules/@nodelib/fs.scandir/out/utils/fs.js +19 -0
- package/node_modules/@nodelib/fs.scandir/out/utils/index.d.ts +2 -0
- package/node_modules/@nodelib/fs.scandir/out/utils/index.js +5 -0
- package/node_modules/@nodelib/fs.scandir/package.json +44 -0
- package/node_modules/@nodelib/fs.stat/LICENSE +21 -0
- package/node_modules/@nodelib/fs.stat/README.md +126 -0
- package/node_modules/@nodelib/fs.stat/out/adapters/fs.d.ts +13 -0
- package/node_modules/@nodelib/fs.stat/out/adapters/fs.js +17 -0
- package/node_modules/@nodelib/fs.stat/out/index.d.ts +12 -0
- package/node_modules/@nodelib/fs.stat/out/index.js +26 -0
- package/node_modules/@nodelib/fs.stat/out/providers/async.d.ts +4 -0
- package/node_modules/@nodelib/fs.stat/out/providers/async.js +36 -0
- package/node_modules/@nodelib/fs.stat/out/providers/sync.d.ts +3 -0
- package/node_modules/@nodelib/fs.stat/out/providers/sync.js +23 -0
- package/node_modules/@nodelib/fs.stat/out/settings.d.ts +16 -0
- package/node_modules/@nodelib/fs.stat/out/settings.js +16 -0
- package/node_modules/@nodelib/fs.stat/out/types/index.d.ts +4 -0
- package/node_modules/@nodelib/fs.stat/out/types/index.js +2 -0
- package/node_modules/@nodelib/fs.stat/package.json +37 -0
- package/node_modules/@nodelib/fs.walk/LICENSE +21 -0
- package/node_modules/@nodelib/fs.walk/README.md +215 -0
- package/node_modules/@nodelib/fs.walk/out/index.d.ts +14 -0
- package/node_modules/@nodelib/fs.walk/out/index.js +34 -0
- package/node_modules/@nodelib/fs.walk/out/providers/async.d.ts +12 -0
- package/node_modules/@nodelib/fs.walk/out/providers/async.js +30 -0
- package/node_modules/@nodelib/fs.walk/out/providers/index.d.ts +4 -0
- package/node_modules/@nodelib/fs.walk/out/providers/index.js +9 -0
- package/node_modules/@nodelib/fs.walk/out/providers/stream.d.ts +12 -0
- package/node_modules/@nodelib/fs.walk/out/providers/stream.js +34 -0
- package/node_modules/@nodelib/fs.walk/out/providers/sync.d.ts +10 -0
- package/node_modules/@nodelib/fs.walk/out/providers/sync.js +14 -0
- package/node_modules/@nodelib/fs.walk/out/readers/async.d.ts +30 -0
- package/node_modules/@nodelib/fs.walk/out/readers/async.js +97 -0
- package/node_modules/@nodelib/fs.walk/out/readers/common.d.ts +7 -0
- package/node_modules/@nodelib/fs.walk/out/readers/common.js +31 -0
- package/node_modules/@nodelib/fs.walk/out/readers/reader.d.ts +6 -0
- package/node_modules/@nodelib/fs.walk/out/readers/reader.js +11 -0
- package/node_modules/@nodelib/fs.walk/out/readers/sync.d.ts +15 -0
- package/node_modules/@nodelib/fs.walk/out/readers/sync.js +59 -0
- package/node_modules/@nodelib/fs.walk/out/settings.d.ts +30 -0
- package/node_modules/@nodelib/fs.walk/out/settings.js +26 -0
- package/node_modules/@nodelib/fs.walk/out/types/index.d.ts +8 -0
- package/node_modules/@nodelib/fs.walk/out/types/index.js +2 -0
- package/node_modules/@nodelib/fs.walk/package.json +44 -0
- package/node_modules/braces/LICENSE +21 -0
- package/node_modules/braces/README.md +586 -0
- package/node_modules/braces/index.js +170 -0
- package/node_modules/braces/lib/compile.js +60 -0
- package/node_modules/braces/lib/constants.js +57 -0
- package/node_modules/braces/lib/expand.js +113 -0
- package/node_modules/braces/lib/parse.js +331 -0
- package/node_modules/braces/lib/stringify.js +32 -0
- package/node_modules/braces/lib/utils.js +122 -0
- package/node_modules/braces/package.json +77 -0
- package/node_modules/fast-glob/LICENSE +21 -0
- package/node_modules/fast-glob/README.md +830 -0
- package/node_modules/fast-glob/out/index.d.ts +40 -0
- package/node_modules/fast-glob/out/index.js +102 -0
- package/node_modules/fast-glob/out/managers/tasks.d.ts +22 -0
- package/node_modules/fast-glob/out/managers/tasks.js +110 -0
- package/node_modules/fast-glob/out/providers/async.d.ts +9 -0
- package/node_modules/fast-glob/out/providers/async.js +23 -0
- package/node_modules/fast-glob/out/providers/filters/deep.d.ts +16 -0
- package/node_modules/fast-glob/out/providers/filters/deep.js +62 -0
- package/node_modules/fast-glob/out/providers/filters/entry.d.ts +17 -0
- package/node_modules/fast-glob/out/providers/filters/entry.js +85 -0
- package/node_modules/fast-glob/out/providers/filters/error.d.ts +8 -0
- package/node_modules/fast-glob/out/providers/filters/error.js +15 -0
- package/node_modules/fast-glob/out/providers/matchers/matcher.d.ts +33 -0
- package/node_modules/fast-glob/out/providers/matchers/matcher.js +45 -0
- package/node_modules/fast-glob/out/providers/matchers/partial.d.ts +4 -0
- package/node_modules/fast-glob/out/providers/matchers/partial.js +38 -0
- package/node_modules/fast-glob/out/providers/provider.d.ts +19 -0
- package/node_modules/fast-glob/out/providers/provider.js +48 -0
- package/node_modules/fast-glob/out/providers/stream.d.ts +11 -0
- package/node_modules/fast-glob/out/providers/stream.js +31 -0
- package/node_modules/fast-glob/out/providers/sync.d.ts +9 -0
- package/node_modules/fast-glob/out/providers/sync.js +23 -0
- package/node_modules/fast-glob/out/providers/transformers/entry.d.ts +8 -0
- package/node_modules/fast-glob/out/providers/transformers/entry.js +26 -0
- package/node_modules/fast-glob/out/readers/async.d.ts +10 -0
- package/node_modules/fast-glob/out/readers/async.js +35 -0
- package/node_modules/fast-glob/out/readers/reader.d.ts +15 -0
- package/node_modules/fast-glob/out/readers/reader.js +33 -0
- package/node_modules/fast-glob/out/readers/stream.d.ts +14 -0
- package/node_modules/fast-glob/out/readers/stream.js +55 -0
- package/node_modules/fast-glob/out/readers/sync.d.ts +12 -0
- package/node_modules/fast-glob/out/readers/sync.js +43 -0
- package/node_modules/fast-glob/out/settings.d.ts +164 -0
- package/node_modules/fast-glob/out/settings.js +59 -0
- package/node_modules/fast-glob/out/types/index.d.ts +31 -0
- package/node_modules/fast-glob/out/types/index.js +2 -0
- package/node_modules/fast-glob/out/utils/array.d.ts +2 -0
- package/node_modules/fast-glob/out/utils/array.js +22 -0
- package/node_modules/fast-glob/out/utils/errno.d.ts +2 -0
- package/node_modules/fast-glob/out/utils/errno.js +7 -0
- package/node_modules/fast-glob/out/utils/fs.d.ts +4 -0
- package/node_modules/fast-glob/out/utils/fs.js +19 -0
- package/node_modules/fast-glob/out/utils/index.d.ts +8 -0
- package/node_modules/fast-glob/out/utils/index.js +17 -0
- package/node_modules/fast-glob/out/utils/path.d.ts +13 -0
- package/node_modules/fast-glob/out/utils/path.js +68 -0
- package/node_modules/fast-glob/out/utils/pattern.d.ts +49 -0
- package/node_modules/fast-glob/out/utils/pattern.js +206 -0
- package/node_modules/fast-glob/out/utils/stream.d.ts +4 -0
- package/node_modules/fast-glob/out/utils/stream.js +17 -0
- package/node_modules/fast-glob/out/utils/string.d.ts +2 -0
- package/node_modules/fast-glob/out/utils/string.js +11 -0
- package/node_modules/fast-glob/package.json +81 -0
- package/node_modules/fastq/LICENSE +13 -0
- package/node_modules/fastq/README.md +310 -0
- package/node_modules/fastq/SECURITY.md +15 -0
- package/node_modules/fastq/bench.js +66 -0
- package/node_modules/fastq/eslint.config.js +11 -0
- package/node_modules/fastq/example.js +14 -0
- package/node_modules/fastq/example.mjs +9 -0
- package/node_modules/fastq/index.d.ts +59 -0
- package/node_modules/fastq/package.json +49 -0
- package/node_modules/fastq/queue.js +346 -0
- package/node_modules/fastq/test/example.ts +83 -0
- package/node_modules/fastq/test/promise.js +325 -0
- package/node_modules/fastq/test/test.js +733 -0
- package/node_modules/fastq/test/tsconfig.json +11 -0
- package/node_modules/fill-range/LICENSE +21 -0
- package/node_modules/fill-range/README.md +237 -0
- package/node_modules/fill-range/index.js +248 -0
- package/node_modules/fill-range/package.json +74 -0
- package/node_modules/glob-parent/LICENSE +15 -0
- package/node_modules/glob-parent/README.md +137 -0
- package/node_modules/glob-parent/index.js +42 -0
- package/node_modules/glob-parent/package.json +48 -0
- package/node_modules/ignore/LICENSE-MIT +21 -0
- package/node_modules/ignore/README.md +452 -0
- package/node_modules/ignore/index.d.ts +81 -0
- package/node_modules/ignore/index.js +784 -0
- package/node_modules/ignore/legacy.js +681 -0
- package/node_modules/ignore/package.json +87 -0
- package/node_modules/is-extglob/LICENSE +21 -0
- package/node_modules/is-extglob/README.md +107 -0
- package/node_modules/is-extglob/index.js +20 -0
- package/node_modules/is-extglob/package.json +69 -0
- package/node_modules/is-glob/LICENSE +21 -0
- package/node_modules/is-glob/README.md +206 -0
- package/node_modules/is-glob/index.js +150 -0
- package/node_modules/is-glob/package.json +81 -0
- package/node_modules/is-number/LICENSE +21 -0
- package/node_modules/is-number/README.md +187 -0
- package/node_modules/is-number/index.js +18 -0
- package/node_modules/is-number/package.json +82 -0
- package/node_modules/merge2/LICENSE +21 -0
- package/node_modules/merge2/README.md +144 -0
- package/node_modules/merge2/index.js +144 -0
- package/node_modules/merge2/package.json +43 -0
- package/node_modules/micromatch/LICENSE +21 -0
- package/node_modules/micromatch/README.md +1024 -0
- package/node_modules/micromatch/index.js +474 -0
- package/node_modules/micromatch/package.json +119 -0
- package/node_modules/mime-db/HISTORY.md +541 -0
- package/node_modules/mime-db/LICENSE +23 -0
- package/node_modules/mime-db/README.md +109 -0
- package/node_modules/mime-db/db.json +9342 -0
- package/node_modules/mime-db/index.js +12 -0
- package/node_modules/mime-db/package.json +56 -0
- package/node_modules/mime-types/HISTORY.md +421 -0
- package/node_modules/mime-types/LICENSE +23 -0
- package/node_modules/mime-types/README.md +126 -0
- package/node_modules/mime-types/index.js +211 -0
- package/node_modules/mime-types/mimeScore.js +52 -0
- package/node_modules/mime-types/package.json +45 -0
- package/node_modules/picomatch/LICENSE +21 -0
- package/node_modules/picomatch/README.md +716 -0
- package/node_modules/picomatch/index.js +3 -0
- package/node_modules/picomatch/lib/constants.js +184 -0
- package/node_modules/picomatch/lib/parse.js +1392 -0
- package/node_modules/picomatch/lib/picomatch.js +342 -0
- package/node_modules/picomatch/lib/scan.js +391 -0
- package/node_modules/picomatch/lib/utils.js +64 -0
- package/node_modules/picomatch/package.json +81 -0
- package/node_modules/queue-microtask/LICENSE +20 -0
- package/node_modules/queue-microtask/README.md +90 -0
- package/node_modules/queue-microtask/index.d.ts +2 -0
- package/node_modules/queue-microtask/index.js +9 -0
- package/node_modules/queue-microtask/package.json +55 -0
- package/node_modules/reusify/.github/dependabot.yml +7 -0
- package/node_modules/reusify/.github/workflows/ci.yml +96 -0
- package/node_modules/reusify/LICENSE +22 -0
- package/node_modules/reusify/README.md +139 -0
- package/node_modules/reusify/SECURITY.md +15 -0
- package/node_modules/reusify/benchmarks/createNoCodeFunction.js +30 -0
- package/node_modules/reusify/benchmarks/fib.js +13 -0
- package/node_modules/reusify/benchmarks/reuseNoCodeFunction.js +38 -0
- package/node_modules/reusify/eslint.config.js +14 -0
- package/node_modules/reusify/package.json +50 -0
- package/node_modules/reusify/reusify.d.ts +14 -0
- package/node_modules/reusify/reusify.js +33 -0
- package/node_modules/reusify/test.js +66 -0
- package/node_modules/reusify/tsconfig.json +11 -0
- package/node_modules/run-parallel/LICENSE +20 -0
- package/node_modules/run-parallel/README.md +85 -0
- package/node_modules/run-parallel/index.js +51 -0
- package/node_modules/run-parallel/package.json +58 -0
- package/node_modules/to-regex-range/LICENSE +21 -0
- package/node_modules/to-regex-range/README.md +305 -0
- package/node_modules/to-regex-range/index.js +288 -0
- package/node_modules/to-regex-range/package.json +88 -0
- package/package.json +53 -0
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const test = require('tape')
|
|
4
|
+
const buildQueue = require('../').promise
|
|
5
|
+
const { promisify } = require('util')
|
|
6
|
+
const sleep = promisify(setTimeout)
|
|
7
|
+
const immediate = promisify(setImmediate)
|
|
8
|
+
|
|
9
|
+
test('concurrency', function (t) {
|
|
10
|
+
t.plan(2)
|
|
11
|
+
t.throws(buildQueue.bind(null, worker, 0))
|
|
12
|
+
t.doesNotThrow(buildQueue.bind(null, worker, 1))
|
|
13
|
+
|
|
14
|
+
async function worker (arg) {
|
|
15
|
+
return true
|
|
16
|
+
}
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
test('worker execution', async function (t) {
|
|
20
|
+
const queue = buildQueue(worker, 1)
|
|
21
|
+
|
|
22
|
+
const result = await queue.push(42)
|
|
23
|
+
|
|
24
|
+
t.equal(result, true, 'result matches')
|
|
25
|
+
|
|
26
|
+
async function worker (arg) {
|
|
27
|
+
t.equal(arg, 42)
|
|
28
|
+
return true
|
|
29
|
+
}
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
test('limit', async function (t) {
|
|
33
|
+
const queue = buildQueue(worker, 1)
|
|
34
|
+
|
|
35
|
+
const [res1, res2] = await Promise.all([queue.push(10), queue.push(0)])
|
|
36
|
+
t.equal(res1, 10, 'the result matches')
|
|
37
|
+
t.equal(res2, 0, 'the result matches')
|
|
38
|
+
|
|
39
|
+
async function worker (arg) {
|
|
40
|
+
await sleep(arg)
|
|
41
|
+
return arg
|
|
42
|
+
}
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
test('multiple executions', async function (t) {
|
|
46
|
+
const queue = buildQueue(worker, 1)
|
|
47
|
+
const toExec = [1, 2, 3, 4, 5]
|
|
48
|
+
const expected = ['a', 'b', 'c', 'd', 'e']
|
|
49
|
+
let count = 0
|
|
50
|
+
|
|
51
|
+
await Promise.all(toExec.map(async function (task, i) {
|
|
52
|
+
const result = await queue.push(task)
|
|
53
|
+
t.equal(result, expected[i], 'the result matches')
|
|
54
|
+
}))
|
|
55
|
+
|
|
56
|
+
async function worker (arg) {
|
|
57
|
+
t.equal(arg, toExec[count], 'arg matches')
|
|
58
|
+
return expected[count++]
|
|
59
|
+
}
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
test('drained', async function (t) {
|
|
63
|
+
const queue = buildQueue(worker, 2)
|
|
64
|
+
|
|
65
|
+
const toExec = new Array(10).fill(10)
|
|
66
|
+
let count = 0
|
|
67
|
+
|
|
68
|
+
async function worker (arg) {
|
|
69
|
+
await sleep(arg)
|
|
70
|
+
count++
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
toExec.forEach(function (i) {
|
|
74
|
+
queue.push(i)
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
await queue.drained()
|
|
78
|
+
|
|
79
|
+
t.equal(count, toExec.length)
|
|
80
|
+
|
|
81
|
+
toExec.forEach(function (i) {
|
|
82
|
+
queue.push(i)
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
await queue.drained()
|
|
86
|
+
|
|
87
|
+
t.equal(count, toExec.length * 2)
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
test('drained with exception should not throw', async function (t) {
|
|
91
|
+
const queue = buildQueue(worker, 2)
|
|
92
|
+
|
|
93
|
+
const toExec = new Array(10).fill(10)
|
|
94
|
+
|
|
95
|
+
async function worker () {
|
|
96
|
+
throw new Error('foo')
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
toExec.forEach(function (i) {
|
|
100
|
+
queue.push(i)
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
await queue.drained()
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
test('drained with drain function', async function (t) {
|
|
107
|
+
let drainCalled = false
|
|
108
|
+
const queue = buildQueue(worker, 2)
|
|
109
|
+
|
|
110
|
+
queue.drain = function () {
|
|
111
|
+
drainCalled = true
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const toExec = new Array(10).fill(10)
|
|
115
|
+
let count = 0
|
|
116
|
+
|
|
117
|
+
async function worker (arg) {
|
|
118
|
+
await sleep(arg)
|
|
119
|
+
count++
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
toExec.forEach(function () {
|
|
123
|
+
queue.push()
|
|
124
|
+
})
|
|
125
|
+
|
|
126
|
+
await queue.drained()
|
|
127
|
+
|
|
128
|
+
t.equal(count, toExec.length)
|
|
129
|
+
t.equal(drainCalled, true)
|
|
130
|
+
})
|
|
131
|
+
|
|
132
|
+
test('drained while idle should resolve', async function (t) {
|
|
133
|
+
const queue = buildQueue(worker, 2)
|
|
134
|
+
|
|
135
|
+
async function worker (arg) {
|
|
136
|
+
await sleep(arg)
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
await queue.drained()
|
|
140
|
+
})
|
|
141
|
+
|
|
142
|
+
test('drained while idle should not call the drain function', async function (t) {
|
|
143
|
+
let drainCalled = false
|
|
144
|
+
const queue = buildQueue(worker, 2)
|
|
145
|
+
|
|
146
|
+
queue.drain = function () {
|
|
147
|
+
drainCalled = true
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
async function worker (arg) {
|
|
151
|
+
await sleep(arg)
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
await queue.drained()
|
|
155
|
+
|
|
156
|
+
t.equal(drainCalled, false)
|
|
157
|
+
})
|
|
158
|
+
|
|
159
|
+
test('set this', async function (t) {
|
|
160
|
+
t.plan(1)
|
|
161
|
+
const that = {}
|
|
162
|
+
const queue = buildQueue(that, worker, 1)
|
|
163
|
+
|
|
164
|
+
await queue.push(42)
|
|
165
|
+
|
|
166
|
+
async function worker (arg) {
|
|
167
|
+
t.equal(this, that, 'this matches')
|
|
168
|
+
}
|
|
169
|
+
})
|
|
170
|
+
|
|
171
|
+
test('unshift', async function (t) {
|
|
172
|
+
const queue = buildQueue(worker, 1)
|
|
173
|
+
const expected = [1, 2, 3, 4]
|
|
174
|
+
|
|
175
|
+
await Promise.all([
|
|
176
|
+
queue.push(1),
|
|
177
|
+
queue.push(4),
|
|
178
|
+
queue.unshift(3),
|
|
179
|
+
queue.unshift(2)
|
|
180
|
+
])
|
|
181
|
+
|
|
182
|
+
t.is(expected.length, 0)
|
|
183
|
+
|
|
184
|
+
async function worker (arg) {
|
|
185
|
+
t.equal(expected.shift(), arg, 'tasks come in order')
|
|
186
|
+
}
|
|
187
|
+
})
|
|
188
|
+
|
|
189
|
+
test('push with worker throwing error', async function (t) {
|
|
190
|
+
t.plan(5)
|
|
191
|
+
const q = buildQueue(async function (task, cb) {
|
|
192
|
+
throw new Error('test error')
|
|
193
|
+
}, 1)
|
|
194
|
+
q.error(function (err, task) {
|
|
195
|
+
t.ok(err instanceof Error, 'global error handler should catch the error')
|
|
196
|
+
t.match(err.message, /test error/, 'error message should be "test error"')
|
|
197
|
+
t.equal(task, 42, 'The task executed should be passed')
|
|
198
|
+
})
|
|
199
|
+
try {
|
|
200
|
+
await q.push(42)
|
|
201
|
+
} catch (err) {
|
|
202
|
+
t.ok(err instanceof Error, 'push callback should catch the error')
|
|
203
|
+
t.match(err.message, /test error/, 'error message should be "test error"')
|
|
204
|
+
}
|
|
205
|
+
})
|
|
206
|
+
|
|
207
|
+
test('unshift with worker throwing error', async function (t) {
|
|
208
|
+
t.plan(2)
|
|
209
|
+
const q = buildQueue(async function (task, cb) {
|
|
210
|
+
throw new Error('test error')
|
|
211
|
+
}, 1)
|
|
212
|
+
try {
|
|
213
|
+
await q.unshift(42)
|
|
214
|
+
} catch (err) {
|
|
215
|
+
t.ok(err instanceof Error, 'push callback should catch the error')
|
|
216
|
+
t.match(err.message, /test error/, 'error message should be "test error"')
|
|
217
|
+
}
|
|
218
|
+
})
|
|
219
|
+
|
|
220
|
+
test('no unhandledRejection (push)', async function (t) {
|
|
221
|
+
function handleRejection () {
|
|
222
|
+
t.fail('unhandledRejection')
|
|
223
|
+
}
|
|
224
|
+
process.once('unhandledRejection', handleRejection)
|
|
225
|
+
const q = buildQueue(async function (task, cb) {
|
|
226
|
+
throw new Error('test error')
|
|
227
|
+
}, 1)
|
|
228
|
+
|
|
229
|
+
q.push(42)
|
|
230
|
+
|
|
231
|
+
await immediate()
|
|
232
|
+
process.removeListener('unhandledRejection', handleRejection)
|
|
233
|
+
})
|
|
234
|
+
|
|
235
|
+
test('no unhandledRejection (unshift)', async function (t) {
|
|
236
|
+
function handleRejection () {
|
|
237
|
+
t.fail('unhandledRejection')
|
|
238
|
+
}
|
|
239
|
+
process.once('unhandledRejection', handleRejection)
|
|
240
|
+
const q = buildQueue(async function (task, cb) {
|
|
241
|
+
throw new Error('test error')
|
|
242
|
+
}, 1)
|
|
243
|
+
|
|
244
|
+
q.unshift(42)
|
|
245
|
+
|
|
246
|
+
await immediate()
|
|
247
|
+
process.removeListener('unhandledRejection', handleRejection)
|
|
248
|
+
})
|
|
249
|
+
|
|
250
|
+
test('drained should resolve after async tasks complete', async function (t) {
|
|
251
|
+
const logs = []
|
|
252
|
+
|
|
253
|
+
async function processTask () {
|
|
254
|
+
await new Promise(resolve => setTimeout(resolve, 0))
|
|
255
|
+
logs.push('processed')
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
const queue = buildQueue(processTask, 1)
|
|
259
|
+
queue.drain = () => logs.push('called drain')
|
|
260
|
+
|
|
261
|
+
queue.drained().then(() => logs.push('drained promise resolved'))
|
|
262
|
+
|
|
263
|
+
await Promise.all([
|
|
264
|
+
queue.push(),
|
|
265
|
+
queue.push(),
|
|
266
|
+
queue.push()
|
|
267
|
+
])
|
|
268
|
+
|
|
269
|
+
t.deepEqual(logs, [
|
|
270
|
+
'processed',
|
|
271
|
+
'processed',
|
|
272
|
+
'processed',
|
|
273
|
+
'called drain',
|
|
274
|
+
'drained promise resolved'
|
|
275
|
+
], 'events happened in correct order')
|
|
276
|
+
})
|
|
277
|
+
|
|
278
|
+
test('drained should handle undefined drain function', async function (t) {
|
|
279
|
+
const queue = buildQueue(worker, 1)
|
|
280
|
+
|
|
281
|
+
async function worker (arg) {
|
|
282
|
+
await sleep(10)
|
|
283
|
+
return arg
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
queue.drain = undefined
|
|
287
|
+
queue.push(1)
|
|
288
|
+
await queue.drained()
|
|
289
|
+
|
|
290
|
+
t.pass('drained resolved successfully with undefined drain')
|
|
291
|
+
})
|
|
292
|
+
|
|
293
|
+
test('abort rejects all pending promises', async function (t) {
|
|
294
|
+
const queue = buildQueue(worker, 1)
|
|
295
|
+
const promises = []
|
|
296
|
+
let rejectedCount = 0
|
|
297
|
+
|
|
298
|
+
// Pause queue to prevent tasks from starting
|
|
299
|
+
queue.pause()
|
|
300
|
+
|
|
301
|
+
for (let i = 0; i < 10; i++) {
|
|
302
|
+
promises.push(queue.push(i))
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
queue.abort()
|
|
306
|
+
|
|
307
|
+
// All promises should be rejected
|
|
308
|
+
for (const promise of promises) {
|
|
309
|
+
try {
|
|
310
|
+
await promise
|
|
311
|
+
t.fail('promise should have been rejected')
|
|
312
|
+
} catch (err) {
|
|
313
|
+
t.equal(err.message, 'abort', 'error message is abort')
|
|
314
|
+
rejectedCount++
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
t.equal(rejectedCount, 10, 'all promises were rejected')
|
|
319
|
+
t.equal(queue.length(), 0, 'queue is empty')
|
|
320
|
+
|
|
321
|
+
async function worker (arg) {
|
|
322
|
+
await sleep(500)
|
|
323
|
+
return arg
|
|
324
|
+
}
|
|
325
|
+
})
|