-
Notifications
You must be signed in to change notification settings - Fork 79
/
index.js
79 lines (56 loc) · 1.18 KB
/
index.js
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
75
76
77
78
79
const path = require('node:path');
const test = require('ava');
const Bree = require('../../src');
const root = path.join(__dirname, '..', 'jobs');
const baseConfig = {
root,
timeout: 0,
interval: 0,
hasSeconds: false,
defaultExtension: 'js'
};
test('successfully add plugin', (t) => {
t.plan(2);
const plugin = (_, c) => {
c.prototype.test = () => {
t.pass();
};
};
Bree.extend(plugin);
t.is(plugin.$i, true);
const bree = new Bree({ ...baseConfig });
bree.test();
});
test('successfully add plugin with options', (t) => {
t.plan(1);
const plugin = (options, c) => {
c.prototype.test = () => {
if (options.test) {
t.pass();
} else {
t.fail();
}
};
};
Bree.extend(plugin, { test: true });
const bree = new Bree({ ...baseConfig });
bree.test();
});
test('only adds plugin once', (t) => {
t.plan(2);
let count = 0;
const plugin = (_, c) => {
if (count === 1) {
t.fail();
}
count++;
c.prototype.test = () => {
t.pass();
};
};
Bree.extend(plugin);
t.is(plugin.$i, true);
Bree.extend(plugin);
const bree = new Bree({ ...baseConfig });
bree.test();
});