@tim-code/my-util 0.7.1 → 0.7.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.
- package/package.json +1 -1
- package/src/promise.js +4 -4
- package/src/promise.test.js +7 -7
package/package.json
CHANGED
package/src/promise.js
CHANGED
|
@@ -109,11 +109,11 @@ export async function allSettled(
|
|
|
109
109
|
await limiter?.(elements.length)
|
|
110
110
|
}
|
|
111
111
|
if (throws && errors.length) {
|
|
112
|
-
const string = errors.map((error) => error
|
|
112
|
+
const string = errors.map((error) => error?.message ?? error).join("; ")
|
|
113
113
|
const resultError = new PromiseAllError(string)
|
|
114
|
-
const {
|
|
115
|
-
if (
|
|
116
|
-
resultError.stack =
|
|
114
|
+
const { stack } = errors.find((error) => error?.stack) ?? {}
|
|
115
|
+
if (stack) {
|
|
116
|
+
resultError.stack = stack
|
|
117
117
|
}
|
|
118
118
|
throw resultError
|
|
119
119
|
}
|
package/src/promise.test.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { jest } from "@jest/globals"
|
|
3
3
|
|
|
4
4
|
// Exported API under test:
|
|
5
|
-
// -
|
|
5
|
+
// - classes: PollError, PromiseAllError
|
|
6
6
|
// - functions: poll, sleep, allSettled, allPatiently, intervalLimiter, alert, throwFirstReject
|
|
7
7
|
|
|
8
8
|
import {
|
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
intervalLimiter,
|
|
13
13
|
poll,
|
|
14
14
|
PollError,
|
|
15
|
+
PromiseAllError,
|
|
15
16
|
sleep,
|
|
16
17
|
throwFirstReject,
|
|
17
18
|
} from "./promise.js"
|
|
@@ -240,13 +241,12 @@ describe("allSettled", () => {
|
|
|
240
241
|
expect(result.results.every((r) => r.status === "fulfilled")).toBe(true)
|
|
241
242
|
})
|
|
242
243
|
|
|
243
|
-
it("throws joined error message when throws=true and adopts
|
|
244
|
-
const
|
|
245
|
-
eWithTrace.trace = ["trace line 1", "trace line 2"]
|
|
244
|
+
it("throws joined error message when throws=true and adopts stack from first error", async () => {
|
|
245
|
+
const e1 = new Error("e1")
|
|
246
246
|
const e2 = new Error("third")
|
|
247
247
|
const arr = [1, 2, 3]
|
|
248
248
|
const cb = (x) => {
|
|
249
|
-
if (x === 1) return Promise.reject(
|
|
249
|
+
if (x === 1) return Promise.reject(e1)
|
|
250
250
|
if (x === 2) return x // fulfilled
|
|
251
251
|
return Promise.reject(e2)
|
|
252
252
|
}
|
|
@@ -256,9 +256,9 @@ describe("allSettled", () => {
|
|
|
256
256
|
} catch (e) {
|
|
257
257
|
thrown = e
|
|
258
258
|
}
|
|
259
|
-
expect(thrown).toBeInstanceOf(
|
|
259
|
+
expect(thrown).toBeInstanceOf(PromiseAllError)
|
|
260
260
|
expect(thrown.message).toBe("e1; third")
|
|
261
|
-
expect(thrown.stack).toBe(
|
|
261
|
+
expect(thrown.stack).toBe(e1.stack)
|
|
262
262
|
})
|
|
263
263
|
})
|
|
264
264
|
|