jssm 5.43.2 → 5.45.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.
@@ -5,9 +5,7 @@ import { sm } from '../jssm';
5
5
 
6
6
 
7
7
 
8
- describe('Hooks', () => {
9
-
10
-
8
+ describe('Hooks open and closed in grammar', () => {
11
9
 
12
10
  test.todo('Hooks open doesn\'t throw' /*, () => {
13
11
 
@@ -23,6 +21,189 @@ describe('Hooks', () => {
23
21
 
24
22
  } */);
25
23
 
24
+ });
25
+
26
+
27
+
28
+
29
+
30
+ describe('Basic hooks on API callpoint', () => {
31
+
32
+
33
+ test('Setting a regular hook doesn\'t throw', () => {
34
+
35
+ expect( () => {
36
+ const _foo = sm`a -> b;`;
37
+ _foo.set_hook({ from: 'a', to: 'b', handler: () => console.log('hi'), kind: 'hook' })
38
+ })
39
+ .not.toThrow();
40
+
41
+ } );
42
+
43
+
44
+ test('Setting a named hook doesn\'t throw', () => {
45
+
46
+ expect( () => {
47
+ const _foo = sm`a 'foo' -> b;`;
48
+ _foo.set_hook({ from: 'a', to: 'b', handler: () => console.log('hi'), kind: 'named', action: 'foo' })
49
+ })
50
+ .not.toThrow();
51
+
52
+ } );
53
+
54
+
55
+ test('Setting a kind of hook that doesn\'t exist throws', () => {
56
+
57
+ expect( () => {
58
+ const _foo = sm`a 'foo' -> b;`;
59
+ _foo.set_hook({ from: 'a', to: 'b', handler: () => console.log('hi'), kind: 'Smaug the Merciless', action: 'foo' } as any)
60
+ })
61
+ .toThrow();
62
+
63
+ } );
64
+
65
+ });
66
+
67
+
68
+
69
+
70
+
71
+ test('Basic hook rejection works', () => {
72
+
73
+ const foo = sm`a => b;`;
74
+
75
+ foo.set_hook({ from: 'a', to: 'b', kind: 'hook', handler: () => false });
76
+ expect(foo.transition('b')).toBe(false);
77
+ expect(foo.state()).toBe('a');
78
+
79
+ foo.set_hook({ from: 'a', to: 'b', kind: 'hook', handler: () => true });
80
+ expect(foo.transition('b')).toBe(true);
81
+ expect(foo.state()).toBe('b');
82
+
83
+ });
84
+
85
+
86
+
87
+
88
+
89
+ test('Basic hook rejection works on forced edges', () => {
90
+
91
+ const foo = sm`a ~> b ~> c;`;
92
+
93
+ foo.set_hook({ from: 'a', to: 'b', kind: 'hook', handler: () => false });
94
+ expect(foo.force_transition('b')).toBe(false);
95
+ expect(foo.state()).toBe('a');
96
+
97
+ foo.set_hook({ from: 'a', to: 'b', kind: 'hook', handler: () => true });
98
+ expect(foo.force_transition('b')).toBe(true);
99
+ expect(foo.state()).toBe('b');
100
+
101
+ // line completion for when a hook lookup finds nothing
102
+ expect(foo.force_transition('c')).toBe(true);
103
+ expect(foo.state()).toBe('c');
104
+
105
+ });
106
+
107
+
108
+
109
+
110
+
111
+ test('Named hook rejection works', () => {
112
+
113
+ const foo = sm`a 'foo' => b;`;
114
+
115
+ foo.set_hook({ from: 'a', to: 'b', action: 'foo', kind: 'named', handler: () => false });
116
+ expect(foo.action('foo')).toBe(false);
117
+ expect(foo.state()).toBe('a');
118
+
119
+ foo.set_hook({ from: 'a', to: 'b', action: 'foo', kind: 'named', handler: () => true });
120
+ expect(foo.action('foo')).toBe(true);
121
+ expect(foo.state()).toBe('b');
122
+
123
+ });
124
+
125
+
126
+
127
+
128
+
129
+ test('Named hook rejection doesn\'t block transitions', () => {
130
+
131
+ const foo = sm`a 'foo' => b;`;
132
+
133
+ foo.set_hook({ from: 'a', to: 'b', action: 'foo', kind: 'named', handler: () => false });
134
+ expect(foo.action('foo')).toBe(false);
135
+ expect(foo.state()).toBe('a');
136
+
137
+ expect(foo.transition('b')).toBe(true);
138
+ expect(foo.state()).toBe('b');
139
+
140
+ });
141
+
142
+
143
+
144
+
145
+
146
+ describe('Basic hooks on API callpoint', () => {
147
+
148
+ test('Basic hooks call their handler', () => {
149
+
150
+ const handler = jest.fn(x => true),
151
+ uncalled = jest.fn(x => true);
152
+
153
+ expect( () => {
154
+ const _foo = sm`a -> b -> c;`;
155
+ _foo.set_hook({ from: 'a', to: 'b', handler, kind: 'hook' });
156
+ _foo.set_hook({ from: 'b', to: 'a', handler: uncalled, kind: 'hook' });
157
+ _foo.set_hook({ from: 'b', to: 'c', handler: uncalled, kind: 'hook' });
158
+ _foo.transition('b');
159
+ })
160
+ .not.toThrow();
161
+
162
+ // should hook from first, but not from second
163
+ expect(handler.mock.calls.length).toBe(1);
164
+ expect(uncalled.mock.calls.length).toBe(0);
165
+
166
+ } );
167
+
168
+ test('Named hooks call their handler', () => {
169
+
170
+ const handler = jest.fn(x => true),
171
+ uncalled = jest.fn(x => true);
172
+
173
+ expect( () => {
174
+ const _foo = sm`a 'next' -> b 'next' -> c;`;
175
+ _foo.set_hook({ from: 'a', to: 'b', handler, kind: 'named', action: 'next' });
176
+ _foo.set_hook({ from: 'a', to: 'b', handler: uncalled, kind: 'named', action: 'borg' });
177
+ _foo.set_hook({ from: 'b', to: 'a', handler: uncalled, kind: 'named', action: 'next' });
178
+ _foo.action('next');
179
+ _foo.action('next');
180
+ })
181
+ .not.toThrow();
182
+
183
+ // should hook from first, but not from second
184
+ expect(handler.mock.calls.length).toBe(1);
185
+ expect(uncalled.mock.calls.length).toBe(0);
186
+
187
+ } );
188
+
189
+ test('Forced hooks call their handler', () => {
190
+
191
+ const handler = jest.fn(x => true),
192
+ uncalled = jest.fn(x => true);
193
+
194
+ expect( () => {
195
+ const _foo = sm`a ~> b ~> c;`;
196
+ _foo.set_hook({ from: 'a', to: 'b', handler, kind: 'hook' });
197
+ _foo.set_hook({ from: 'b', to: 'a', handler: uncalled, kind: 'hook' });
198
+ _foo.set_hook({ from: 'b', to: 'c', handler: uncalled, kind: 'hook' });
199
+ _foo.force_transition('b');
200
+ })
201
+ .not.toThrow();
202
+
203
+ // should hook from first, but not from second
204
+ expect(handler.mock.calls.length).toBe(1);
205
+ expect(uncalled.mock.calls.length).toBe(0);
26
206
 
207
+ } );
27
208
 
28
209
  });
package/src/ts/version.ts CHANGED
@@ -1,3 +1,3 @@
1
1
 
2
- const version: string = "5.43.2";
2
+ const version: string = "5.45.2";
3
3
  export { version };