Skip to content
Myr

methods.ts

This file

Path

test/methods.ts

138 lines · 3.2 KiB · TypeScript

Last changed by

Skip a needless request rebuild, report an unknown total as zero, and fix two stale testsSindre Sorhusbefore adoptionfa0eac4

History of this file

Take it

The walk stopped after 200 commits: lines older than 37fc250 point at it.

Add retry count to `afterResponse` and `beforeError` hooks (#763)Sindre Sorhusbefore adoption37fc250

lines 1–4why, one step back
1import test from 'ava';
2import ky from '../source/index.js';3import {createHttpTestServer} from './helpers/create-http-test-server.js';4

Support readonly inputs and explicit undefined in TypeScript optionsSindre Sorhusbefore adoption51b3177

lines 5–37why, one step back
5test('undefined method restores the input default without changing the parent', async t => {
6 const url = 'https://example.com';7 const parent = ky.create({8 method: 'POST',9 async fetch(request) {10 return new Response(request.method);11 },12 });13 const extended = parent.extend({method: undefined});1415 t.is(await parent(url, {method: undefined}).text(), 'GET');16 t.is(await extended(url).text(), 'GET');17 t.is(await extended(new Request(url, {method: 'PUT'})).text(), 'PUT');18 t.is(await parent(url).text(), 'POST');19});2021test('init hooks can reset the request method to the input default', async t => {22 const api = ky.create({23 method: 'POST',24 hooks: {25 init: [options => {26 options.method = undefined;27 }],28 },29 async fetch(request) {30 return new Response(request.method);31 },32 });3334 t.is(await api('https://example.com').text(), 'GET');35 t.is(await api(new Request('https://example.com', {method: 'PUT'})).text(), 'PUT');36});37

Add retry count to `afterResponse` and `beforeError` hooks (#763)Sindre Sorhusbefore adoption37fc250

line 38why, one step back
38test('common method is normalized', async t => {

Simplify testsSindre Sorhusbefore adoptiondfa3f59

line 39why, one step back
39 const server = await createHttpTestServer(t);

Add retry count to `afterResponse` and `beforeError` hooks (#763)Sindre Sorhusbefore adoption37fc250

lines 40–48why, one step back
40 server.all('/', (_request, response) => {
41 response.end();42 });4344 await t.notThrowsAsync(45 ky(server.url, {46 method: 'get',47 hooks: {48 beforeRequest: [

Unify hook signatures around a single state object (#827)Sindre Sorhusbefore adoptionecdd45e

line 49why, one step back
49 ({options}) => {

Add retry count to `afterResponse` and `beforeError` hooks (#763)Sindre Sorhusbefore adoption37fc250

lines 50–58why, one step back
50 t.is(options.method, 'GET');
51 },52 ],53 },54 }),55 );56});5758test('method defaults to "GET"', async t => {

Simplify testsSindre Sorhusbefore adoptiondfa3f59

line 59why, one step back
59 const server = await createHttpTestServer(t);

Add retry count to `afterResponse` and `beforeError` hooks (#763)Sindre Sorhusbefore adoption37fc250

lines 60–69why, one step back
60 server.all('/', (_request, response) => {
61 response.end();62 });6364 t.plan(2);6566 await t.notThrowsAsync(67 ky(server.url, {68 hooks: {69 beforeRequest: [

Unify hook signatures around a single state object (#827)Sindre Sorhusbefore adoptionecdd45e

line 70why, one step back
70 ({options}) => {

Add retry count to `afterResponse` and `beforeError` hooks (#763)Sindre Sorhusbefore adoption37fc250

lines 71–78why, one step back
71 t.is(options.method, 'GET');
72 },73 ],74 },75 }),76 );77});78

Add QUERY method support (#873)Sindre Sorhusbefore adoption6edddd9

lines 79–98why, one step back
79test('QUERY method is normalized', async t => {
80 const server = await createHttpTestServer(t);81 server.all('/', (_request, response) => {82 response.end();83 });8485 t.plan(1);8687 await ky(server.url, {88 method: 'query',89 hooks: {90 beforeRequest: [91 ({options}) => {92 t.is(options.method, 'QUERY');93 },94 ],95 },96 });97});98

Fix mixed-case standard `method` values not being uppercasedSindre Sorhusbefore adoption8950864

lines 99–109why, one step back
99test('mixed-case standard method is uppercased', async t => {
100 const server = await createHttpTestServer(t);101 server.all('/', (request, response) => {102 response.end(request.method);103 });104105 t.is(await ky(server.url, {method: 'Patch'}).text(), 'PATCH');106 t.is(await ky(server.url, {method: 'Query'}).text(), 'QUERY');107 t.is(await ky(server.url, {method: 'Delete'}).text(), 'DELETE');108});109

Skip a needless request rebuild, report an unknown total as zero, and fix two stale testsSindre Sorhusbefore adoptionfa0eac4

lines 110–111why, one step back
110// A custom method is passed through with its casing intact. It is asserted on the outgoing request, because an HTTP server may reject an unknown method before the application sees it.
111test('custom method remains identical', async t => {

Add retry count to `afterResponse` and `beforeError` hooks (#763)Sindre Sorhusbefore adoption37fc250

line 112why, one step back
112 await t.notThrowsAsync(

Skip a needless request rebuild, report an unknown total as zero, and fix two stale testsSindre Sorhusbefore adoptionfa0eac4

line 113why, one step back
113 ky('https://example.com', {

Add retry count to `afterResponse` and `beforeError` hooks (#763)Sindre Sorhusbefore adoption37fc250

lines 114–116why, one step back
114 method: 'report',
115 hooks: {116 beforeRequest: [

Unify hook signatures around a single state object (#827)Sindre Sorhusbefore adoptionecdd45e

line 117why, one step back
117 ({options}) => {

Add retry count to `afterResponse` and `beforeError` hooks (#763)Sindre Sorhusbefore adoption37fc250

lines 118–120why, one step back
118 t.is(options.method, 'report');
119 },120 ],

Skip a needless request rebuild, report an unknown total as zero, and fix two stale testsSindre Sorhusbefore adoptionfa0eac4

lines 121–124why, one step back
121 },
122 async fetch(request) {123 t.is(request.method, 'report');124 return new Response();

Add retry count to `afterResponse` and `beforeError` hooks (#763)Sindre Sorhusbefore adoption37fc250

lines 125–130why, one step back
125 },
126 }),127 );128});129130test('shortcut headers have correct accept headers set', async t => {

Simplify testsSindre Sorhusbefore adoptiondfa3f59

line 131why, one step back
131 const server = await createHttpTestServer(t);

Add retry count to `afterResponse` and `beforeError` hooks (#763)Sindre Sorhusbefore adoption37fc250

lines 132–138why, one step back
132 server.all('/', (request, response) => {
133 t.is(request.headers.accept, 'text/*');134 response.end('whatever');135 });136137 await ky.get(server.url).text();138});