File tree Expand file tree Collapse file tree 3 files changed +34
-2
lines changed Expand file tree Collapse file tree 3 files changed +34
-2
lines changed Original file line number Diff line number Diff line change
1
+ import fetch from 'node-fetch' ;
2
+
3
+ /**
4
+ * @see https://github.com/vercel/next.js/discussions/13678 How to use built-in fetch in tests?
5
+ * @see https://nextjs.org/blog/next-9-4#improved-built-in-fetch-support Next.js Blog - Improved Built-in Fetch Support
6
+ * @see https://jestjs.io/docs/en/configuration#setupfilesafterenv-array About setupFilesAfterEnv usage
7
+ */
8
+ // Polyfill "fetch" for node.js, so that our tests may replicate the built-in "fetch" provided by Next.js
9
+ global . fetch = fetch ;
10
+
11
+ console . info ( 'Jest env has been enhanced - See "./jest.setup.js"' )
Original file line number Diff line number Diff line change 40
40
"test" : " NODE_ENV=test jest --watchAll" ,
41
41
"test:once" : " NODE_ENV=test jest" ,
42
42
"test:coverage" : " NODE_ENV=test jest --coverage" ,
43
+ "test:config" : " NODE_ENV=test jest --showConfig" ,
43
44
"security:audit" : " yarn audit" ,
44
45
"packages:upgrade" : " yarn upgrade-interactive --latest"
45
46
},
46
47
"jest" : {
47
48
"setupFilesAfterEnv" : [
48
- " jest-extended"
49
+ " jest-extended" ,
50
+ " ./jest.setup.js"
49
51
]
50
52
},
51
53
"dependencies" : {
128
130
"@types/lodash.some" : " 4.6.6" ,
129
131
"@types/lodash.startswith" : " 4.2.6" ,
130
132
"@types/lodash.xorby" : " 4.7.6" ,
133
+ "@types/node-fetch" : " 2.5.7" ,
131
134
"@types/popper.js" : " 1.11.0" ,
132
135
"@types/react" : " 16.9.35" ,
133
136
"@types/reactstrap" : " 8.4.2" ,
149
152
"eslint-watch" : " 6.0.1" ,
150
153
"jest" : " 26.0.1" ,
151
154
"jest-extended" : " 0.11.5" ,
155
+ "node-fetch" : " 2.6.0" ,
152
156
"node-mocks-http" : " 1.8.1" ,
153
157
"now" : " 17.1.1" ,
154
158
"react-test-renderer" : " 16.13.1" ,
Original file line number Diff line number Diff line change 2146
2146
resolved "https://registry.yarnpkg.com/@types/mocha/-/mocha-5.2.7.tgz#315d570ccb56c53452ff8638738df60726d5b6ea"
2147
2147
integrity sha512-NYrtPht0wGzhwe9+/idPaBB+TqkY9AhTvOLMkThm0IoEfLaiVQZwBwyJ5puCkO3AUCWrmcoePjp2mbFocKy4SQ==
2148
2148
2149
+
2150
+ version "2.5.7"
2151
+ resolved "https://registry.yarnpkg.com/@types/node-fetch/-/node-fetch-2.5.7.tgz#20a2afffa882ab04d44ca786449a276f9f6bbf3c"
2152
+ integrity sha512-o2WVNf5UhWRkxlf6eq+jMZDu7kjgpgJfl4xVNlvryc95O/6F2ld8ztKX+qu+Rjyet93WAWm5LjeX9H5FGkODvw==
2153
+ dependencies:
2154
+ "@types/node" "*"
2155
+ form-data "^3.0.0"
2156
+
2149
2157
"@types/node@*":
2150
2158
version "13.7.6"
2151
2159
resolved "https://registry.yarnpkg.com/@types/node/-/node-13.7.6.tgz#cb734a7c191472ae6a2b3a502b4dfffcea974113"
3825
3833
color "3.0.x"
3826
3834
text-hex "1.0.x"
3827
3835
3828
- combined-stream@^1.0.6, combined-stream@~1.0.6:
3836
+ combined-stream@^1.0.6, combined-stream@^1.0.8, combined-stream@ ~1.0.6:
3829
3837
version "1.0.8"
3830
3838
resolved "https://registry.yarnpkg.com/combined-stream/-/combined-stream-1.0.8.tgz#c3d45a8b34fd730631a110a8a2520682b31d5a7f"
3831
3839
integrity sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==
5657
5665
tapable "^1.0.0"
5658
5666
worker-rpc "^0.1.0"
5659
5667
5668
+ form-data@^3.0.0:
5669
+ version "3.0.0"
5670
+ resolved "https://registry.yarnpkg.com/form-data/-/form-data-3.0.0.tgz#31b7e39c85f1355b7139ee0c647cf0de7f83c682"
5671
+ integrity sha512-CKMFDglpbMi6PyN+brwB9Q/GOw0eAnsrEZDgcsH5Krhz5Od/haKHAX0NmQfha2zPPz0JpWzA7GJHGSnvCRLWsg==
5672
+ dependencies:
5673
+ asynckit "^0.4.0"
5674
+ combined-stream "^1.0.8"
5675
+ mime-types "^2.1.12"
5676
+
5660
5677
form-data@~2.3.2:
5661
5678
version "2.3.3"
5662
5679
resolved "https://registry.yarnpkg.com/form-data/-/form-data-2.3.3.tgz#dcce52c05f644f298c6a7ab936bd724ceffbf3a6"
You can’t perform that action at this time.
0 commit comments