Repository: node-fetch/node-fetch
Pull request #1139 (2021-04-28 22:09:42)

Upgrade to GitHub-native Dependabot
_Dependabot Preview will be shut down on August 3rd, 2021. In order to keep getting Dependabot updates, please merge this PR and migrate to GitHub-native Dependabot before then._

Dependabot has been fully integrated into GitHub, so you no longer have to install and manage a separate app. This pull request migrates your configuration from Dependabot.com to a config file, using the [new syntax][new_syntax]. When merged, we'll swap out `dependabot-preview` (me) for a new `dependabot` app, and you'll be all set!

With this change, you'll now use the [Dependabot page in GitHub][dependabot_page], rather than the [Dependabot dashboard][dashboard], to monitor your version updates, and you'll configure Dependabot through the new config file rather than a UI.







If you've got any questions or feedback for us, please let us know by creating an issue in the [dependabot/dependabot-core][issues] repository.

[Learn more about migrating to GitHub-native Dependabot][learn]

Please note that regular `@dependabot` commands do not work on this pull request.

[dashboard]: https://app.dependabot.com/
[dependabot_page]: https://github.com/node-fetch/node-fetch/network/updates
[issues]: https://github.com/dependabot/dependabot-core/issues/new?assignees=%40dependabot%2Fpreview-migration-reviewers&labels=E%3A+preview-migration&template=migration-issue.md
[learn]: http://docs.github.com/code-security/supply-chain-security/upgrading-from-dependabotcom-to-github-native-dependabot
[new_syntax]: https://help.github.com/en/github/administering-a-repository/configuration-options-for-dependency-updates
[org_secrets_url]: https://github.com/organizations/node-fetch/settings/secrets/dependabot
[repo_secrets_url]: https://github.com/node-fetch/node-fetch/settings/secrets/dependabot



Patch:
diff --git a/.github/dependabot.yml b/.github/dependabot.yml
new file mode 100644
index 0000000..9db9c69
--- /dev/null
+++ b/.github/dependabot.yml
@@ -0,0 +1,20 @@
+version: 2
+updates:
+- package-ecosystem: npm
+  directory: "/"
+  schedule:
+    interval: daily
+  open-pull-requests-limit: 10
+  ignore:
+  - dependency-name: formdata-node
+    versions:
+    - 3.0.0
+    - 3.1.0
+  - dependency-name: xo
+    versions:
+    - 0.37.1
+    - 0.38.1
+    - 0.38.2
+  - dependency-name: p-timeout
+    versions:
+    - 4.1.0
diff --git a/@types/index.d.ts b/@types/index.d.ts
index 3f666dd..f13e023 100644
--- a/@types/index.d.ts
+++ b/@types/index.d.ts
@@ -143,6 +143,8 @@ declare class Request extends Body {
 	clone(): Request;
 }
 
+type ResponseType = "basic" | "cors" | "default" | "error" | "opaque" | "opaqueredirect"
+
 declare class Response extends Body {
 	constructor(body?: BodyInit | null, init?: ResponseInit);
 
@@ -151,8 +153,11 @@ declare class Response extends Body {
 	readonly redirected: boolean;
 	readonly status: number;
 	readonly statusText: string;
+	readonly type: ResponseType;
 	readonly url: string;
 	clone(): Response;
+
+	static error(): Response;
 }
 
 declare class FetchError extends Error {
diff --git a/README.md b/README.md
index 7b68bb3..b90fa39 100644
--- a/README.md
+++ b/README.md
@@ -56,6 +56,7 @@
 		- [new Response([body[, options]])](#new-responsebody-options)
 		- [response.ok](#responseok)
 		- [response.redirected](#responseredirected)
+		- [response.type](#responsetype)
 	- [Class: Headers](#class-headers)
 		- [new Headers([init])](#new-headersinit)
 	- [Interface: Body](#interface-body)
@@ -636,9 +637,6 @@ An HTTP(S) response. This class implements the [Body](#iface-body) interface.
 
 The following properties are not implemented in node-fetch at this moment:
 
-- `Response.error()`
-- `Response.redirect()`
-- `type`
 - `trailer`
 
 #### new Response([body[, options]])
@@ -664,6 +662,12 @@ Convenience property representing if the request ended normally. Will evaluate t
 
 Convenience property representing if the request has been redirected at least once. Will evaluate to true if the internal redirect counter is greater than 0.
 
+#### response.type
+
+<small>_(deviation from spec)_</small>
+
+Convenience property representing the response's type. node-fetch only supports `'default'` and `'error'` and does not make use of [filtered responses](https://fetch.spec.whatwg.org/#concept-filtered-response).
+
 <a id="class-headers"></a>
 
 ### Class: Headers
diff --git a/src/response.js b/src/response.js
index 3c69d5e..7e6c5c7 100644
--- a/src/response.js
+++ b/src/response.js
@@ -21,7 +21,9 @@ export default class Response extends Body {
 	constructor(body = null, options = {}) {
 		super(body, options);
 
-		const status = options.status || 200;
+		// eslint-disable-next-line no-eq-null, eqeqeq, no-negated-condition
+		const status = options.status != null ? options.status : 200;
+
 		const headers = new Headers(options.headers);
 
 		if (body !== null && !headers.has('Content-Type')) {
@@ -32,6 +34,7 @@ export default class Response extends Body {
 		}
 
 		this[INTERNALS] = {
+			type: 'default',
 			url: options.url,
 			status,
 			statusText: options.statusText || '',
@@ -41,6 +44,10 @@ export default class Response extends Body {
 		};
 	}
 
+	get type() {
+		return this[INTERNALS].type;
+	}
+
 	get url() {
 		return this[INTERNALS].url || '';
 	}
@@ -79,6 +86,7 @@ export default class Response extends Body {
 	 */
 	clone() {
 		return new Response(clone(this, this.highWaterMark), {
+			type: this.type,
 			url: this.url,
 			status: this.status,
 			statusText: this.statusText,
@@ -107,12 +115,19 @@ export default class Response extends Body {
 		});
 	}
 
+	static error() {
+		const response = new Response(null, {status: 0, statusText: ''});
+		response[INTERNALS].type = 'error';
+		return response;
+	}
+
 	get [Symbol.toStringTag]() {
 		return 'Response';
 	}
 }
 
 Object.defineProperties(Response.prototype, {
+	type: {enumerable: true},
 	url: {enumerable: true},
 	status: {enumerable: true},
 	ok: {enumerable: true},


Test patch:
diff --git a/test/response.js b/test/response.js
index f02b67f..8de19d6 100644
--- a/test/response.js
+++ b/test/response.js
@@ -35,6 +35,7 @@ describe('Response', () => {
 			'blob',
 			'json',
 			'text',
+			'type',
 			'url',
 			'status',
 			'ok',
@@ -49,6 +50,7 @@ describe('Response', () => {
 		for (const toCheck of [
 			'body',
 			'bodyUsed',
+			'type',
 			'url',
 			'status',
 			'ok',
@@ -125,6 +127,7 @@ describe('Response', () => {
 		});
 		const cl = res.clone();
 		expect(cl.headers.get('a')).to.equal('1');
+		expect(cl.type).to.equal('default');
 		expect(cl.url).to.equal(base);
 		expect(cl.status).to.equal(346);
 		expect(cl.statusText).to.equal('production');
@@ -205,4 +208,12 @@ describe('Response', () => {
 		const res = new Response();
 		expect(res.url).to.equal('');
 	});
+
+	it('should support error() static method', () => {
+		const res = Response.error();
+		expect(res).to.be.an.instanceof(Response);
+		expect(res.type).to.equal('error');
+		expect(res.status).to.equal(0);
+		expect(res.statusText).to.equal('');
+	});
 });