Skip to content

Commit 83d9481

Browse files
committed
upgrade jest and migrate
1 parent 4f17078 commit 83d9481

File tree

8 files changed

+497
-1534
lines changed

8 files changed

+497
-1534
lines changed

jest.config.js

+1-6
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,5 @@ module.exports = {
22
testEnvironment: 'node',
33
moduleFileExtensions: ['ts', 'js'],
44
extensionsToTreatAsEsm: ['.ts'],
5-
testPathIgnorePatterns: [
6-
'/__tests__/jest.d.ts', // augments some jest types
7-
'/node_modules/',
8-
'/fixtures/',
9-
'/utils/',
10-
],
5+
testPathIgnorePatterns: ['/node_modules/', '/fixtures/', '/utils/'],
116
};

package.json

+3-10
Original file line numberDiff line numberDiff line change
@@ -83,24 +83,17 @@
8383
"@rollup/plugin-typescript": "^10.0.1",
8484
"@semantic-release/changelog": "^6.0.2",
8585
"@semantic-release/git": "^10.0.1",
86-
"@types/eventsource": "^1.1.10",
87-
"@types/express": "^4.17.14",
8886
"@types/glob": "^8.0.0",
89-
"@types/jest": "^28.1.8",
87+
"@types/jest": "^29.2.4",
9088
"@typescript-eslint/eslint-plugin": "^5.45.0",
9189
"@typescript-eslint/parser": "^5.45.0",
92-
"babel-jest": "^28.1.3",
90+
"babel-jest": "^29.3.1",
9391
"eslint": "^8.29.0",
9492
"eslint-config-prettier": "^8.5.0",
9593
"eslint-plugin-prettier": "^4.2.1",
96-
"eventsource": "^2.0.2",
97-
"express": "^4.18.2",
98-
"fastify": "^4.10.2",
9994
"glob": "^8.0.3",
10095
"graphql": "^16.6.0",
101-
"jest": "^28.1.3",
102-
"jest-jasmine2": "^28.1.3",
103-
"node-fetch": "^3.3.0",
96+
"jest": "^29.3.1",
10497
"prettier": "^2.8.0",
10598
"rollup": "^3.5.1",
10699
"rollup-plugin-terser": "^7.0.2",

src/__tests__/__snapshots__/handler.ts.snap

+18-18
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ exports[`distinct connections mode should stream query operations to connected e
88

99
exports[`distinct connections mode should stream query operations to connected event stream and then disconnect 2`] = `
1010
"event: next
11-
data: {\\"data\\":{\\"getValue\\":\\"value\\"}}
11+
data: {"data":{"getValue":"value"}}
1212
1313
"
1414
`;
@@ -27,7 +27,7 @@ exports[`distinct connections mode should stream query operations to connected e
2727

2828
exports[`distinct connections mode should stream query operations to connected event stream and then disconnect 5`] = `
2929
"event: next
30-
data: {\\"data\\":{\\"getValue\\":\\"value\\"}}
30+
data: {"data":{"getValue":"value"}}
3131
3232
"
3333
`;
@@ -46,35 +46,35 @@ exports[`distinct connections mode should stream subscription operations to conn
4646

4747
exports[`distinct connections mode should stream subscription operations to connected event stream and then disconnect 2`] = `
4848
"event: next
49-
data: {\\"data\\":{\\"greetings\\":\\"Hi\\"}}
49+
data: {"data":{"greetings":"Hi"}}
5050
5151
"
5252
`;
5353

5454
exports[`distinct connections mode should stream subscription operations to connected event stream and then disconnect 3`] = `
5555
"event: next
56-
data: {\\"data\\":{\\"greetings\\":\\"Bonjour\\"}}
56+
data: {"data":{"greetings":"Bonjour"}}
5757
5858
"
5959
`;
6060

6161
exports[`distinct connections mode should stream subscription operations to connected event stream and then disconnect 4`] = `
6262
"event: next
63-
data: {\\"data\\":{\\"greetings\\":\\"Hola\\"}}
63+
data: {"data":{"greetings":"Hola"}}
6464
6565
"
6666
`;
6767

6868
exports[`distinct connections mode should stream subscription operations to connected event stream and then disconnect 5`] = `
6969
"event: next
70-
data: {\\"data\\":{\\"greetings\\":\\"Ciao\\"}}
70+
data: {"data":{"greetings":"Ciao"}}
7171
7272
"
7373
`;
7474

7575
exports[`distinct connections mode should stream subscription operations to connected event stream and then disconnect 6`] = `
7676
"event: next
77-
data: {\\"data\\":{\\"greetings\\":\\"Zdravo\\"}}
77+
data: {"data":{"greetings":"Zdravo"}}
7878
7979
"
8080
`;
@@ -93,35 +93,35 @@ exports[`distinct connections mode should stream subscription operations to conn
9393

9494
exports[`distinct connections mode should stream subscription operations to connected event stream and then disconnect 9`] = `
9595
"event: next
96-
data: {\\"data\\":{\\"greetings\\":\\"Hi\\"}}
96+
data: {"data":{"greetings":"Hi"}}
9797
9898
"
9999
`;
100100

101101
exports[`distinct connections mode should stream subscription operations to connected event stream and then disconnect 10`] = `
102102
"event: next
103-
data: {\\"data\\":{\\"greetings\\":\\"Bonjour\\"}}
103+
data: {"data":{"greetings":"Bonjour"}}
104104
105105
"
106106
`;
107107

108108
exports[`distinct connections mode should stream subscription operations to connected event stream and then disconnect 11`] = `
109109
"event: next
110-
data: {\\"data\\":{\\"greetings\\":\\"Hola\\"}}
110+
data: {"data":{"greetings":"Hola"}}
111111
112112
"
113113
`;
114114

115115
exports[`distinct connections mode should stream subscription operations to connected event stream and then disconnect 12`] = `
116116
"event: next
117-
data: {\\"data\\":{\\"greetings\\":\\"Ciao\\"}}
117+
data: {"data":{"greetings":"Ciao"}}
118118
119119
"
120120
`;
121121

122122
exports[`distinct connections mode should stream subscription operations to connected event stream and then disconnect 13`] = `
123123
"event: next
124-
data: {\\"data\\":{\\"greetings\\":\\"Zdravo\\"}}
124+
data: {"data":{"greetings":"Zdravo"}}
125125
126126
"
127127
`;
@@ -134,42 +134,42 @@ exports[`distinct connections mode should stream subscription operations to conn
134134

135135
exports[`single connection mode should stream subscription operations to connected event stream 2`] = `
136136
"event: next
137-
data: {\\"id\\":\\"1\\",\\"payload\\":{\\"data\\":{\\"greetings\\":\\"Hi\\"}}}
137+
data: {"id":"1","payload":{"data":{"greetings":"Hi"}}}
138138
139139
"
140140
`;
141141

142142
exports[`single connection mode should stream subscription operations to connected event stream 3`] = `
143143
"event: next
144-
data: {\\"id\\":\\"1\\",\\"payload\\":{\\"data\\":{\\"greetings\\":\\"Bonjour\\"}}}
144+
data: {"id":"1","payload":{"data":{"greetings":"Bonjour"}}}
145145
146146
"
147147
`;
148148

149149
exports[`single connection mode should stream subscription operations to connected event stream 4`] = `
150150
"event: next
151-
data: {\\"id\\":\\"1\\",\\"payload\\":{\\"data\\":{\\"greetings\\":\\"Hola\\"}}}
151+
data: {"id":"1","payload":{"data":{"greetings":"Hola"}}}
152152
153153
"
154154
`;
155155

156156
exports[`single connection mode should stream subscription operations to connected event stream 5`] = `
157157
"event: next
158-
data: {\\"id\\":\\"1\\",\\"payload\\":{\\"data\\":{\\"greetings\\":\\"Ciao\\"}}}
158+
data: {"id":"1","payload":{"data":{"greetings":"Ciao"}}}
159159
160160
"
161161
`;
162162

163163
exports[`single connection mode should stream subscription operations to connected event stream 6`] = `
164164
"event: next
165-
data: {\\"id\\":\\"1\\",\\"payload\\":{\\"data\\":{\\"greetings\\":\\"Zdravo\\"}}}
165+
data: {"id":"1","payload":{"data":{"greetings":"Zdravo"}}}
166166
167167
"
168168
`;
169169

170170
exports[`single connection mode should stream subscription operations to connected event stream 7`] = `
171171
"event: complete
172-
data: {\\"id\\":\\"1\\"}
172+
data: {"id":"1"}
173173
174174
"
175175
`;

src/__tests__/__snapshots__/parser.ts.snap

+32-32
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`should accept valid events only 1`] = `"Invalid stream event \\"done\\""`;
3+
exports[`should accept valid events only 1`] = `"Invalid stream event "done""`;
44

5-
exports[`should accept valid events only 2`] = `"Invalid stream event \\"value\\""`;
5+
exports[`should accept valid events only 2`] = `"Invalid stream event "value""`;
66

77
exports[`should ignore comments 1`] = `
8-
Array [
9-
Object {
10-
"data": Object {
8+
[
9+
{
10+
"data": {
1111
"iAm": "data",
1212
},
1313
"event": "next",
@@ -16,9 +16,9 @@ Array [
1616
`;
1717

1818
exports[`should parse chunked message 1`] = `
19-
Array [
20-
Object {
21-
"data": Object {
19+
[
20+
{
21+
"data": {
2222
"iAm": "data",
2323
},
2424
"event": "next",
@@ -27,9 +27,9 @@ Array [
2727
`;
2828

2929
exports[`should parse message whose lines are separated by \\r\\n 1`] = `
30-
Array [
31-
Object {
32-
"data": Object {
30+
[
31+
{
32+
"data": {
3333
"iAm": "data",
3434
},
3535
"event": "next",
@@ -38,9 +38,9 @@ Array [
3838
`;
3939

4040
exports[`should parse message with prepended ping 1`] = `
41-
Array [
42-
Object {
43-
"data": Object {
41+
[
42+
{
43+
"data": {
4444
"iAm": "data",
4545
},
4646
"event": "next",
@@ -49,13 +49,13 @@ Array [
4949
`;
5050

5151
exports[`should parse multiple messages from one chunk 1`] = `
52-
Array [
53-
Object {
54-
"data": Object {},
52+
[
53+
{
54+
"data": {},
5555
"event": "next",
5656
},
57-
Object {
58-
"data": Object {
57+
{
58+
"data": {
5959
"no": "data",
6060
},
6161
"event": "next",
@@ -64,24 +64,24 @@ Array [
6464
`;
6565

6666
exports[`should parse multiple messages from one chunk 2`] = `
67-
Array [
68-
Object {
69-
"data": Object {
67+
[
68+
{
69+
"data": {
7070
"almost": "done",
7171
},
7272
"event": "next",
7373
},
74-
Object {
75-
"data": Object {},
74+
{
75+
"data": {},
7676
"event": "complete",
7777
},
7878
]
7979
`;
8080

8181
exports[`should parse whole message 1`] = `
82-
Array [
83-
Object {
84-
"data": Object {
82+
[
83+
{
84+
"data": {
8585
"iAm": "data",
8686
},
8787
"event": "next",
@@ -90,9 +90,9 @@ Array [
9090
`;
9191

9292
exports[`should parse whole message 2`] = `
93-
Array [
94-
Object {
95-
"data": Object {
93+
[
94+
{
95+
"data": {
9696
"iAm": "data",
9797
},
9898
"event": "next",
@@ -101,8 +101,8 @@ Array [
101101
`;
102102

103103
exports[`should parse whole message 3`] = `
104-
Array [
105-
Object {
104+
[
105+
{
106106
"data": null,
107107
"event": "complete",
108108
},

src/__tests__/client.ts

+16-16
Original file line numberDiff line numberDiff line change
@@ -76,20 +76,20 @@ it('should supply all valid messages received to onMessage', async () => {
7676
});
7777
await Promise.race([sub.throwOnError(), sub.waitForComplete()]);
7878
expect(msgs).toMatchInlineSnapshot(`
79-
Array [
80-
Object {
81-
"data": Object {
79+
[
80+
{
81+
"data": {
8282
"id": "veryunique",
83-
"payload": Object {
84-
"data": Object {
83+
"payload": {
84+
"data": {
8585
"getValue": "value",
8686
},
8787
},
8888
},
8989
"event": "next",
9090
},
91-
Object {
92-
"data": Object {
91+
{
92+
"data": {
9393
"id": "veryunique",
9494
},
9595
"event": "complete",
@@ -112,16 +112,16 @@ it('should supply all valid messages received to onMessage', async () => {
112112
});
113113
await Promise.race([sub.throwOnError(), sub.waitForComplete()]);
114114
expect(msgs).toMatchInlineSnapshot(`
115-
Array [
116-
Object {
117-
"data": Object {
118-
"data": Object {
115+
[
116+
{
117+
"data": {
118+
"data": {
119119
"getValue": "value",
120120
},
121121
},
122122
"event": "next",
123123
},
124-
Object {
124+
{
125125
"data": null,
126126
"event": "complete",
127127
},
@@ -207,8 +207,8 @@ describe('single connection mode', () => {
207207
});
208208

209209
await expect(sub.waitForNext()).resolves.toMatchInlineSnapshot(`
210-
Object {
211-
"data": Object {
210+
{
211+
"data": {
212212
"getValue": "value",
213213
},
214214
}
@@ -236,8 +236,8 @@ describe('single connection mode', () => {
236236
setTimeout(() => pong(key), 0);
237237

238238
await expect(sub.waitForNext()).resolves.toMatchInlineSnapshot(`
239-
Object {
240-
"data": Object {
239+
{
240+
"data": {
241241
"ping": "pong",
242242
},
243243
}

0 commit comments

Comments
 (0)