Skip to content

Commit e061098

Browse files
authored
test: exclude non-deterministic tests for setTimeout (marpple#254)
* test: exclude non-deterministic tests * test: set maxWorkers 0
1 parent 46b7186 commit e061098

22 files changed

+27
-189
lines changed

jest.config.cjs

-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,4 @@ module.exports = {
55
preset: "ts-jest",
66
testEnvironment: "node",
77
testMatch: [path.join(__dirname, "test/**/*.spec.ts")],
8-
maxWorkers: 1,
98
};

test/Lazy/append.spec.ts

+1-7
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
toAsync,
1010
} from "../../src/index";
1111
import { Concurrent } from "../../src/Lazy/concurrent";
12-
import { callFuncAfterTime, generatorMock } from "../utils";
12+
import { generatorMock } from "../utils";
1313

1414
describe("append", function () {
1515
describe("sync", function () {
@@ -43,8 +43,6 @@ describe("append", function () {
4343
});
4444

4545
it("should be appended sequentially", async function () {
46-
const fn = jest.fn();
47-
callFuncAfterTime(fn, 3000);
4846
let chainedPromise: Promise<void | number> = Promise.resolve();
4947
const res = await pipe(
5048
toAsync(range(1, 4)),
@@ -65,13 +63,10 @@ describe("append", function () {
6563
),
6664
toArray,
6765
);
68-
expect(fn).toBeCalled();
6966
expect(res).toEqual([1, 2, 3, 4, 5, 6]);
7067
}, 3050);
7168

7269
it("should be appended concurrently", async function () {
73-
const fn = jest.fn();
74-
callFuncAfterTime(fn, 1000);
7570
const res = await pipe(
7671
toAsync([1, 2, 3]),
7772
map((a) => delay(1000, a)),
@@ -81,7 +76,6 @@ describe("append", function () {
8176
concurrent(3),
8277
toArray,
8378
);
84-
expect(fn).toBeCalled();
8579
expect(res).toEqual([1, 2, 3, 4, 5, 6]);
8680
}, 1050);
8781

test/Lazy/chunk.spec.ts

+1-10
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
toAsync,
1111
} from "../../src/index";
1212
import { Concurrent } from "../../src/Lazy/concurrent";
13-
import { callFuncAfterTime, generatorMock } from "../utils";
13+
import { generatorMock } from "../utils";
1414

1515
const expected = [
1616
[1, 2, 3],
@@ -60,22 +60,17 @@ describe("chunk", function () {
6060
});
6161

6262
it("should be chunked after concurrent", async function () {
63-
const fn = jest.fn();
64-
callFuncAfterTime(fn, 600);
6563
const res = await pipe(
6664
toAsync(range(1, 12)),
6765
map((a) => delay(100, a)),
6866
concurrent(2),
6967
chunk(3),
7068
toArray,
7169
);
72-
expect(fn).toBeCalled();
7370
expect(res).toEqual(expected);
7471
}, 650);
7572

7673
it("should be chunked after concurrent with filter", async function () {
77-
const fn = jest.fn();
78-
callFuncAfterTime(fn, 1000);
7974
const res = await pipe(
8075
toAsync(range(1, 21)),
8176
map((a) => delay(100, a)),
@@ -85,13 +80,10 @@ describe("chunk", function () {
8580
toArray,
8681
);
8782
const expected: number[][] = [[2, 4, 6], [8, 10, 12], [14, 16, 18], [20]];
88-
expect(fn).toBeCalled();
8983
expect(res).toEqual(expected);
9084
}, 1050);
9185

9286
it("should be chunked before concurrent", async function () {
93-
const fn = jest.fn();
94-
callFuncAfterTime(fn, 1000);
9587
const res = await pipe(
9688
toAsync(range(1, 21)),
9789
map((a) => delay(100, a)),
@@ -101,7 +93,6 @@ describe("chunk", function () {
10193
toArray,
10294
);
10395
const expected: number[][] = [[2, 4, 6], [8, 10, 12], [14, 16, 18], [20]];
104-
expect(fn).toBeCalled();
10596
expect(res).toEqual(expected);
10697
}, 1050);
10798

test/Lazy/concat.spec.ts

+1-7
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
toAsync,
99
} from "../../src/index";
1010
import { Concurrent } from "../../src/Lazy/concurrent";
11-
import { callFuncAfterTime, generatorMock } from "../utils";
11+
import { generatorMock } from "../utils";
1212

1313
describe("concat", function () {
1414
describe("sync", function () {
@@ -25,8 +25,6 @@ describe("concat", function () {
2525

2626
describe("async", function () {
2727
it("should be concatenated given two 'AsyncIterable'", async function () {
28-
const fn = jest.fn();
29-
callFuncAfterTime(fn, 4000);
3028
const res = await pipe(
3129
[
3230
map((a) => delay(1000, a), toAsync([1, 2])),
@@ -35,13 +33,10 @@ describe("concat", function () {
3533
([a, b]) => concat(a, b),
3634
toArray,
3735
);
38-
expect(fn).toBeCalled();
3936
expect(res).toEqual([1, 2, 3, 4]);
4037
}, 4050);
4138

4239
it("should be concatenated given two 'AsyncIterable' concurrently", async function () {
43-
const fn = jest.fn();
44-
callFuncAfterTime(fn, 3000);
4540
const res = await pipe(
4641
[
4742
map((a) => delay(1000, a), toAsync([1, 2, 3])),
@@ -51,7 +46,6 @@ describe("concat", function () {
5146
concurrent(2),
5247
toArray,
5348
);
54-
expect(fn).toBeCalled();
5549
expect(res).toEqual([1, 2, 3, 4, 5, 6]);
5650
}, 3050);
5751

test/Lazy/concurrent.spec.ts

-24
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,9 @@ import {
88
range,
99
toAsync,
1010
} from "../../src/index";
11-
import { callFuncAfterTime } from "../utils";
1211

1312
describe("concurrent", function () {
1413
it("should be consumed 'AsyncIterable' concurrently", async function () {
15-
const fn = jest.fn();
16-
callFuncAfterTime(fn, 2000);
1714
const res = concurrent(
1815
2,
1916
toAsync(
@@ -29,14 +26,10 @@ describe("concurrent", function () {
2926
for await (const item of res) {
3027
acc.push(item);
3128
}
32-
expect(fn).toBeCalled();
3329
expect(acc).toEqual([1, 2, 3, 4]);
3430
}, 2050);
3531

3632
it("should be able to be used as a curried function in the pipeline", async function () {
37-
const fn = jest.fn();
38-
callFuncAfterTime(fn, 500);
39-
4033
const iter = pipe(
4134
toAsync(range(1, 101)),
4235
map((a) => delay(100, a)),
@@ -56,13 +49,10 @@ describe("concurrent", function () {
5649
iter.next(),
5750
]).then((arr) => arr.map((a) => a.value));
5851

59-
expect(fn).toBeCalled();
6052
expect(arr).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
6153
}, 550);
6254

6355
it("should be affected only one concurrent below it, when nested concurrent", async function () {
64-
let fn: jest.Mock<any, any>;
65-
fn = jest.fn();
6656
let concurrent10Count = 0;
6757
let concurrent2Count = 0;
6858

@@ -77,33 +67,23 @@ describe("concurrent", function () {
7767
concurrent(2),
7868
);
7969

80-
callFuncAfterTime(fn, 300);
8170
await iter.next();
8271
await iter.next();
83-
expect(fn).toBeCalled();
8472
expect(concurrent2Count).toEqual(4);
8573
expect(concurrent10Count).toEqual(10);
8674

87-
fn = jest.fn();
88-
callFuncAfterTime(fn, 200);
8975
await iter.next();
9076
await iter.next();
91-
expect(fn).toBeCalled();
9277
expect(concurrent2Count).toEqual(8);
9378
expect(concurrent10Count).toEqual(10);
9479

95-
fn = jest.fn();
96-
callFuncAfterTime(fn, 300);
9780
await iter.next();
9881
await iter.next();
99-
expect(fn).toBeCalled();
10082
expect(concurrent2Count).toEqual(12);
10183
expect(concurrent10Count).toEqual(20);
10284
}, 850);
10385

10486
it("should return IteratorReturnResult after all consuming 'AsyncIterable'", async function () {
105-
const fn = jest.fn();
106-
callFuncAfterTime(fn, 1000);
10787
const iter = concurrent(
10888
2,
10989
toAsync(
@@ -121,7 +101,6 @@ describe("concurrent", function () {
121101
{ value: v4, done: d4 },
122102
] = await Promise.all([iter.next(), iter.next(), iter.next(), iter.next()]);
123103

124-
expect(fn).toBeCalled();
125104
expect(v1).toEqual(1);
126105
expect(d1).toEqual(false);
127106
expect(v2).toEqual(2);
@@ -133,8 +112,6 @@ describe("concurrent", function () {
133112
}, 1050);
134113

135114
it("should be able to handle an error when working concurrent", async function () {
136-
const fn = jest.fn();
137-
callFuncAfterTime(fn, 2000);
138115
const res = concurrent(
139116
2,
140117
toAsync(
@@ -158,7 +135,6 @@ describe("concurrent", function () {
158135
} catch (err) {
159136
expect(err).toEqual("err");
160137
}
161-
expect(fn).toBeCalled();
162138
expect(acc).toEqual([1, 2, 3]);
163139
}, 2050);
164140
});

test/Lazy/cycle.spec.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
} from "../../src";
1010
import { Concurrent } from "../../src/Lazy/concurrent";
1111
import cycle from "../../src/Lazy/cycle";
12-
import { callFuncAfterTime, generatorMock } from "../utils";
12+
import { generatorMock } from "../utils";
1313

1414
describe("cycle", function () {
1515
describe("sync", function () {
@@ -77,9 +77,6 @@ describe("cycle", function () {
7777
});
7878

7979
it("should be repeated concurrently", async function () {
80-
const fn = jest.fn();
81-
callFuncAfterTime(fn, 900);
82-
8380
const res = await pipe(
8481
toAsync(
8582
(function* () {
@@ -97,7 +94,6 @@ describe("cycle", function () {
9794
toArray,
9895
);
9996

100-
expect(fn).toBeCalled();
10197
expect(res).toEqual([1, 2, 3, 4, 5, 6]);
10298
}, 950);
10399

test/Lazy/difference.spec.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { delay, map, pipe, toArray, toAsync } from "../../src";
22
import concurrent, { Concurrent } from "../../src/Lazy/concurrent";
33
import difference from "../../src/Lazy/difference";
4-
import { callFuncAfterTime, generatorMock } from "../utils";
4+
import { generatorMock } from "../utils";
55

66
describe("difference", function () {
77
describe("sync", function () {
@@ -53,9 +53,6 @@ describe("difference", function () {
5353
});
5454

5555
it("should be handled concurrently", async function () {
56-
const fn = jest.fn();
57-
callFuncAfterTime(fn, 900);
58-
5956
const res = await pipe(
6057
[1, 2, 3, 4, 5, 6, 7, 8, 9],
6158
toAsync,
@@ -65,7 +62,6 @@ describe("difference", function () {
6562
toArray,
6663
);
6764

68-
expect(fn).toBeCalled();
6965
expect(res).toEqual([1, 2, 6, 7, 8, 9]);
7066
}, 950);
7167

test/Lazy/drop.spec.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
toAsync,
1010
} from "../../src/index";
1111
import { Concurrent } from "../../src/Lazy/concurrent";
12-
import { callFuncAfterTime, generatorMock } from "../utils";
12+
import { generatorMock } from "../utils";
1313

1414
describe("drop", function () {
1515
describe("sync", function () {
@@ -61,8 +61,6 @@ describe("drop", function () {
6161
});
6262

6363
it("should be discarded elements by length concurrently", async function () {
64-
const fn = jest.fn();
65-
callFuncAfterTime(fn, 400);
6664
const res = await pipe(
6765
toAsync([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]),
6866
map((a) => delay(100, a)),
@@ -71,7 +69,6 @@ describe("drop", function () {
7169
concurrent(3),
7270
toArray,
7371
);
74-
expect(fn).toBeCalled();
7572
expect(res).toEqual([6, 8, 10]);
7673
}, 450);
7774

test/Lazy/dropRight.spec.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
toAsync,
1010
} from "../../src/index";
1111
import { Concurrent } from "../../src/Lazy/concurrent";
12-
import { callFuncAfterTime, generatorMock } from "../utils";
12+
import { generatorMock } from "../utils";
1313

1414
describe("dropRight", function () {
1515
describe("sync", function () {
@@ -69,8 +69,6 @@ describe("dropRight", function () {
6969
});
7070

7171
it("should be discarded elements by length concurrently", async function () {
72-
const fn = jest.fn();
73-
callFuncAfterTime(fn, 400);
7472
const res = await pipe(
7573
toAsync([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]),
7674
map((a) => delay(100, a)),
@@ -79,7 +77,6 @@ describe("dropRight", function () {
7977
concurrent(3),
8078
toArray,
8179
);
82-
expect(fn).toBeCalled();
8380
expect(res).toEqual([2, 4, 6]);
8481
}, 450);
8582

test/Lazy/dropUntil.spec.ts

+1-8
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
} from "../../src";
1111
import { AsyncFunctionException } from "../../src/_internal/error";
1212
import { Concurrent } from "../../src/Lazy/concurrent";
13-
import { callFuncAfterTime, generatorMock } from "../utils";
13+
import { generatorMock } from "../utils";
1414

1515
describe("dropUntil", function () {
1616
describe("sync", function () {
@@ -89,8 +89,6 @@ describe("dropUntil", function () {
8989
});
9090

9191
it("should be dropped elements concurrently", async function () {
92-
const fn = jest.fn();
93-
callFuncAfterTime(fn, 1500);
9492
const res = await pipe(
9593
[1, 2, 3, 4, 5, 1, 2],
9694
toAsync,
@@ -100,14 +98,10 @@ describe("dropUntil", function () {
10098
concurrent(3),
10199
toArray,
102100
);
103-
expect(fn).toBeCalled();
104101
expect(res).toEqual([11]);
105102
}, 1550);
106103

107104
it("should be controlled the order when concurrency", async function () {
108-
const fn = jest.fn();
109-
callFuncAfterTime(fn, 2000);
110-
111105
const res = await pipe(
112106
toAsync(
113107
(function* () {
@@ -127,7 +121,6 @@ describe("dropUntil", function () {
127121
concurrent(5),
128122
toArray,
129123
);
130-
expect(fn).toBeCalled();
131124
expect(res).toEqual([8, 9]);
132125
}, 2050);
133126

0 commit comments

Comments
 (0)