-
-
Notifications
You must be signed in to change notification settings - Fork 313
/
plugin.abort.spec.ts
74 lines (61 loc) · 2.11 KB
/
plugin.abort.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import { promiseError } from '@kwsites/promise-result';
import {
assertExecutedTasksCount,
assertGitError,
createAbortController,
newSimpleGit,
wait,
} from '../__fixtures__';
import { GitPluginError } from '../../..';
describe('plugin.abort', function () {
it('aborts an active child process', async () => {
const { controller, abort } = createAbortController();
const git = newSimpleGit({ abort });
const queue = promiseError(git.raw('foo'));
await wait();
assertExecutedTasksCount(1);
controller.abort();
assertGitError(await queue, 'Abort signal received', GitPluginError);
});
it('aborts all active promises', async () => {
const { controller, abort } = createAbortController();
const git = newSimpleGit({ abort });
const all = Promise.all([
git.raw('a').catch((e) => e),
git.raw('b').catch((e) => e),
git.raw('c').catch((e) => e),
]);
await wait();
assertExecutedTasksCount(3);
controller.abort();
expect(await all).toEqual([
expect.any(GitPluginError),
expect.any(GitPluginError),
expect.any(GitPluginError),
]);
});
it('aborts all steps in chained promises', async () => {
const { controller, abort } = createAbortController();
const git = newSimpleGit({ abort });
const a = git.raw('a');
const b = a.raw('b');
const c = b.raw('c');
const all = Promise.all([a.catch((e) => e), b.catch((e) => e), c.catch((e) => e)]);
await wait();
assertExecutedTasksCount(1);
controller.abort();
expect(await all).toEqual([
expect.any(GitPluginError),
expect.any(GitPluginError),
expect.any(GitPluginError),
]);
assertExecutedTasksCount(1);
});
it('aborts before attempting to spawn', async () => {
const { controller, abort } = createAbortController();
controller.abort();
const git = newSimpleGit({ abort });
assertGitError(await promiseError(git.raw('a')), 'Abort already signaled', GitPluginError);
assertExecutedTasksCount(0);
});
});