-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathextractTriggers.spec.js
More file actions
78 lines (67 loc) · 1.68 KB
/
extractTriggers.spec.js
File metadata and controls
78 lines (67 loc) · 1.68 KB
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
"use strict";
const chai = require("chai");
const expect = chai.expect;
const extractTriggers = require("./extractTriggers");
describe("extractTriggers", function () {
const fnWithTrigger = function () {};
fnWithTrigger.__trigger = { service: "function.with.trigger" };
const fnWithoutTrigger = function () {};
let triggers;
beforeEach(function () {
triggers = [];
});
it("should find exported functions with __trigger", function () {
extractTriggers(
{
foo: fnWithTrigger,
bar: fnWithoutTrigger,
baz: fnWithTrigger,
},
triggers,
);
expect(triggers.length).to.eq(2);
});
it("should attach name and entryPoint to exported triggers", function () {
extractTriggers(
{
foo: fnWithTrigger,
},
triggers,
);
expect(triggers[0].name).to.eq("foo");
expect(triggers[0].entryPoint).to.eq("foo");
});
it("should find nested functions and set name and entryPoint", function () {
extractTriggers(
{
foo: {
bar: fnWithTrigger,
baz: {
qux: fnWithTrigger,
not: fnWithoutTrigger,
},
},
baz: fnWithTrigger,
},
triggers,
);
expect(triggers[0].name).to.eq("foo-bar");
expect(triggers[0].entryPoint).to.eq("foo.bar");
expect(triggers.length).to.eq(3);
});
it("should ignore null exports", function () {
expect(() =>
extractTriggers(
{
foo: {
bar: fnWithTrigger,
baz: null,
},
},
triggers,
),
).not.to.throw();
expect(triggers[0].name).to.eq("foo-bar");
expect(triggers.length).to.eq(1);
});
});