Skip to content

Commit fdf830c

Browse files
committed
chore: use jsdom for jest
1 parent e14506c commit fdf830c

File tree

9 files changed

+505
-186
lines changed

9 files changed

+505
-186
lines changed

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
"flow-bin": "0.201.0",
6565
"form-data": "^4.0.0",
6666
"jest": "^29.4.3",
67+
"jest-environment-jsdom": "^29.4.3",
6768
"prettier": "^2.8.4",
6869
"relay-runtime": "^14.1.0",
6970
"rimraf": "^4.3.0",
@@ -79,6 +80,7 @@
7980
}
8081
},
8182
"jest": {
83+
"testEnvironment": "jsdom",
8284
"roots": [
8385
"<rootDir>/src"
8486
]
@@ -91,7 +93,7 @@
9193
"build-flow": "echo `$1` && find ./src -name '*.js' -not -path '*/__*' | while read filepath; do cp $filepath `echo ./${COPY_TO_FOLDER:-lib}$filepath | sed 's/.\\/src\\//\\//g'`.flow; done",
9294
"build-dts": "echo `$1` && find ./src -name '*d.ts' -not -path '*/__*' | while read filepath; do cp $filepath `echo ./${COPY_TO_FOLDER:-lib}$filepath | sed 's/.\\/src\\//\\//g'`; done",
9395
"lint": "npm run eslint && npm run tslint && npm run tscheck",
94-
"eslint": "eslint --ext .js ./src --fix",
96+
"eslint": "eslint --ext .js ./src",
9597
"tslint": "tslint -p . \"src/**/*.d.ts\"",
9698
"tscheck": "tsc --noEmit",
9799
"coverage": "jest --coverage --maxWorkers 2",

src/middlewares/__tests__/__snapshots__/auth-test.js.snap

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

33
exports[`middlewares/auth \`token\` option as string (with default \`prefix\` and \`header\`) 1`] = `
4-
Object {
5-
"body": "{\\"id\\":\\"1\\",\\"query\\":\\"\\",\\"variables\\":{}}",
6-
"headers": Object {
4+
{
5+
"body": "{"id":"1","query":"","variables":{}}",
6+
"headers": {
77
"Accept": "*/*",
88
"Authorization": "Bearer 123",
99
"Content-Type": "application/json",
@@ -14,9 +14,9 @@ Object {
1414
`;
1515

1616
exports[`middlewares/auth \`token\` option as thunk (with custom \`prefix\` and \`header\`) 1`] = `
17-
Object {
18-
"body": "{\\"id\\":\\"1\\",\\"query\\":\\"\\",\\"variables\\":{}}",
19-
"headers": Object {
17+
{
18+
"body": "{"id":"1","query":"","variables":{}}",
19+
"headers": {
2020
"Accept": "*/*",
2121
"Content-Type": "application/json",
2222
"MyAuthorization": "MyBearer 333",
@@ -27,12 +27,12 @@ Object {
2727
`;
2828

2929
exports[`middlewares/auth \`tokenRefreshPromise\` should be called on 401 response 1`] = `
30-
Array [
31-
Array [
30+
[
31+
[
3232
"/graphql",
33-
Object {
34-
"body": "{\\"id\\":\\"1\\",\\"query\\":\\"\\",\\"variables\\":{}}",
35-
"headers": Object {
33+
{
34+
"body": "{"id":"1","query":"","variables":{}}",
35+
"headers": {
3636
"Accept": "*/*",
3737
"Authorization": "Bearer 123",
3838
"Content-Type": "application/json",
@@ -41,11 +41,11 @@ Array [
4141
"signal": AbortSignal {},
4242
},
4343
],
44-
Array [
44+
[
4545
"/graphql",
46-
Object {
47-
"body": "{\\"id\\":\\"1\\",\\"query\\":\\"\\",\\"variables\\":{}}",
48-
"headers": Object {
46+
{
47+
"body": "{"id":"1","query":"","variables":{}}",
48+
"headers": {
4949
"Accept": "*/*",
5050
"Authorization": "Bearer ValidToken",
5151
"Content-Type": "application/json",

src/middlewares/__tests__/__snapshots__/batch-test.js.snap

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

33
exports[`middlewares/batch option \`allowMutations\` should batch mutations if \`allowMutations=true\` 1`] = `
4-
Object {
5-
"body": "[{\\"id\\":\\"1\\",\\"query\\":\\"mutation {}\\",\\"variables\\":{}},{\\"id\\":\\"2\\",\\"query\\":\\"mutation {}\\",\\"variables\\":{}}]",
6-
"headers": Object {
4+
{
5+
"body": "[{"id":"1","query":"mutation {}","variables":{}},{"id":"2","query":"mutation {}","variables":{}}]",
6+
"headers": {
77
"Accept": "*/*",
88
"Content-Type": "application/json",
99
},
@@ -13,24 +13,24 @@ Object {
1313
`;
1414

1515
exports[`middlewares/batch option \`allowMutations\` should not batch mutations by default 1`] = `
16-
Array [
17-
Array [
16+
[
17+
[
1818
"/graphql",
19-
Object {
20-
"body": "{\\"id\\":\\"1\\",\\"query\\":\\"mutation {}\\",\\"variables\\":{}}",
21-
"headers": Object {
19+
{
20+
"body": "{"id":"1","query":"mutation {}","variables":{}}",
21+
"headers": {
2222
"Accept": "*/*",
2323
"Content-Type": "application/json",
2424
},
2525
"method": "POST",
2626
"signal": AbortSignal {},
2727
},
2828
],
29-
Array [
29+
[
3030
"/graphql",
31-
Object {
32-
"body": "{\\"id\\":\\"1\\",\\"query\\":\\"mutation {}\\",\\"variables\\":{}}",
33-
"headers": Object {
31+
{
32+
"body": "{"id":"1","query":"mutation {}","variables":{}}",
33+
"headers": {
3434
"Accept": "*/*",
3535
"Content-Type": "application/json",
3636
},
@@ -42,9 +42,9 @@ Array [
4242
`;
4343

4444
exports[`middlewares/batch option \`batchTimeout\` should gather different requests into one batch request 1`] = `
45-
Object {
46-
"body": "[{\\"id\\":\\"1\\",\\"query\\":\\"\\",\\"variables\\":{}},{\\"id\\":\\"3\\",\\"query\\":\\"\\",\\"variables\\":{}},{\\"id\\":\\"2\\",\\"query\\":\\"\\",\\"variables\\":{}}]",
47-
"headers": Object {
45+
{
46+
"body": "[{"id":"1","query":"","variables":{}},{"id":"3","query":"","variables":{}},{"id":"2","query":"","variables":{}}]",
47+
"headers": {
4848
"Accept": "*/*",
4949
"Content-Type": "application/json",
5050
},
@@ -54,24 +54,24 @@ Object {
5454
`;
5555

5656
exports[`middlewares/batch option \`batchTimeout\` should gather different requests into two batch request 1`] = `
57-
Array [
58-
Array [
57+
[
58+
[
5959
"/graphql/batch",
60-
Object {
61-
"body": "[{\\"id\\":\\"1\\",\\"query\\":\\"\\",\\"variables\\":{}},{\\"id\\":\\"4\\",\\"query\\":\\"\\",\\"variables\\":{}}]",
62-
"headers": Object {
60+
{
61+
"body": "[{"id":"1","query":"","variables":{}},{"id":"4","query":"","variables":{}}]",
62+
"headers": {
6363
"Accept": "*/*",
6464
"Content-Type": "application/json",
6565
},
6666
"method": "POST",
6767
"url": "/graphql/batch",
6868
},
6969
],
70-
Array [
70+
[
7171
"/graphql/batch",
72-
Object {
73-
"body": "[{\\"id\\":\\"2\\",\\"query\\":\\"\\",\\"variables\\":{}},{\\"id\\":\\"3\\",\\"query\\":\\"\\",\\"variables\\":{}}]",
74-
"headers": Object {
72+
{
73+
"body": "[{"id":"2","query":"","variables":{}},{"id":"3","query":"","variables":{}}]",
74+
"headers": {
7575
"Accept": "*/*",
7676
"Content-Type": "application/json",
7777
},
@@ -83,9 +83,9 @@ Array [
8383
`;
8484

8585
exports[`middlewares/batch should handle network failure 1`] = `
86-
Object {
87-
"body": "[{\\"id\\":\\"1\\",\\"query\\":\\"\\",\\"variables\\":{}},{\\"id\\":\\"2\\",\\"query\\":\\"\\",\\"variables\\":{}}]",
88-
"headers": Object {
86+
{
87+
"body": "[{"id":"1","query":"","variables":{}},{"id":"2","query":"","variables":{}}]",
88+
"headers": {
8989
"Accept": "*/*",
9090
"Content-Type": "application/json",
9191
},
@@ -95,9 +95,9 @@ Object {
9595
`;
9696

9797
exports[`middlewares/batch should handle responses without payload wrapper 1`] = `
98-
Object {
99-
"body": "[{\\"id\\":\\"1\\",\\"query\\":\\"\\",\\"variables\\":{}},{\\"id\\":\\"2\\",\\"query\\":\\"\\",\\"variables\\":{}}]",
100-
"headers": Object {
98+
{
99+
"body": "[{"id":"1","query":"","variables":{}},{"id":"2","query":"","variables":{}}]",
100+
"headers": {
101101
"Accept": "*/*",
102102
"Content-Type": "application/json",
103103
},
@@ -107,9 +107,9 @@ Object {
107107
`;
108108

109109
exports[`middlewares/batch should handle server errors for all requests 1`] = `
110-
Object {
111-
"body": "[{\\"id\\":\\"1\\",\\"query\\":\\"\\",\\"variables\\":{}},{\\"id\\":\\"2\\",\\"query\\":\\"\\",\\"variables\\":{}},{\\"id\\":\\"3\\",\\"query\\":\\"\\",\\"variables\\":{}}]",
112-
"headers": Object {
110+
{
111+
"body": "[{"id":"1","query":"","variables":{}},{"id":"2","query":"","variables":{}},{"id":"3","query":"","variables":{}}]",
112+
"headers": {
113113
"Accept": "*/*",
114114
"Content-Type": "application/json",
115115
},
@@ -119,9 +119,9 @@ Object {
119119
`;
120120

121121
exports[`middlewares/batch should handle server errors for one request 1`] = `
122-
Object {
123-
"body": "[{\\"id\\":\\"1\\",\\"query\\":\\"\\",\\"variables\\":{}},{\\"id\\":\\"2\\",\\"query\\":\\"\\",\\"variables\\":{}}]",
124-
"headers": Object {
122+
{
123+
"body": "[{"id":"1","query":"","variables":{}},{"id":"2","query":"","variables":{}}]",
124+
"headers": {
125125
"Accept": "*/*",
126126
"Content-Type": "application/json",
127127
},
@@ -131,9 +131,9 @@ Object {
131131
`;
132132

133133
exports[`middlewares/batch should make a successfull single request 1`] = `
134-
Object {
135-
"body": "{\\"id\\":\\"1\\",\\"query\\":\\"\\",\\"variables\\":{}}",
136-
"headers": Object {
134+
{
135+
"body": "{"id":"1","query":"","variables":{}}",
136+
"headers": {
137137
"Accept": "*/*",
138138
"Content-Type": "application/json",
139139
},
@@ -143,9 +143,9 @@ Object {
143143
`;
144144

145145
exports[`middlewares/batch should make a successfully batch request 1`] = `
146-
Object {
147-
"body": "[{\\"id\\":\\"1\\",\\"query\\":\\"\\",\\"variables\\":{}},{\\"id\\":\\"2\\",\\"query\\":\\"\\",\\"variables\\":{}}]",
148-
"headers": Object {
146+
{
147+
"body": "[{"id":"1","query":"","variables":{}},{"id":"2","query":"","variables":{}}]",
148+
"headers": {
149149
"Accept": "*/*",
150150
"Content-Type": "application/json",
151151
},
@@ -155,9 +155,9 @@ Object {
155155
`;
156156

157157
exports[`middlewares/batch should make a successfully batch request with duplicate request payloads 1`] = `
158-
Object {
159-
"body": "[{\\"id\\":\\"2\\",\\"query\\":\\"\\",\\"variables\\":{}},{\\"id\\":\\"2\\",\\"query\\":\\"duplicate\\",\\"variables\\":{\\"duplicate\\":true}}]",
160-
"headers": Object {
158+
{
159+
"body": "[{"id":"2","query":"","variables":{}},{"id":"2","query":"duplicate","variables":{"duplicate":true}}]",
160+
"headers": {
161161
"Accept": "*/*",
162162
"Content-Type": "application/json",
163163
},
@@ -167,9 +167,9 @@ Object {
167167
`;
168168

169169
exports[`middlewares/batch should reject if server does not return response for duplicate request payloads 1`] = `
170-
Object {
171-
"body": "[{\\"id\\":\\"1\\",\\"query\\":\\"\\",\\"variables\\":{}},{\\"id\\":\\"2\\",\\"query\\":\\"\\",\\"variables\\":{}},{\\"id\\":\\"3\\",\\"query\\":\\"\\",\\"variables\\":{}}]",
172-
"headers": Object {
170+
{
171+
"body": "[{"id":"1","query":"","variables":{}},{"id":"2","query":"","variables":{}},{"id":"3","query":"","variables":{}}]",
172+
"headers": {
173173
"Accept": "*/*",
174174
"Content-Type": "application/json",
175175
},

0 commit comments

Comments
 (0)