|
1 | 1 | import test from 'ava'; |
2 | 2 | import got from '../source/index.js'; |
3 | | -import withServer, {withHttpsServer} from './helpers/with-server.js'; |
| 3 | +import withServer from './helpers/with-server.js'; |
4 | 4 |
|
5 | 5 | test('http/1 timings', withServer, async (t, server, got) => { |
6 | 6 | server.get('/', (_request, response) => { |
@@ -28,32 +28,38 @@ test('http/1 timings', withServer, async (t, server, got) => { |
28 | 28 | t.true(phases.total! >= 0); |
29 | 29 | }); |
30 | 30 |
|
31 | | -test('http/2 timings', withHttpsServer(), async (t, server, got) => { |
32 | | - server.get('/', (_request, response) => { |
33 | | - response.json({data: 'test'}); |
34 | | - }); |
35 | | - |
36 | | - const {timings} = await got({http2: true}); |
| 31 | +test('http/2 timings', async t => { |
| 32 | + // Use a real HTTP/2 server (Google supports HTTP/2) |
| 33 | + const {timings} = await got('https://www.google.com/', {http2: true}); |
37 | 34 |
|
| 35 | + // These timings are available even for HTTP/2 |
38 | 36 | t.true(timings.start >= 0); |
39 | 37 | t.true(timings.socket! >= 0); |
40 | | - t.true(timings.lookup! >= 0); |
41 | | - t.true(timings.connect! >= 0); |
42 | | - t.true(timings.secureConnect! >= 0); |
43 | 38 | t.true(timings.upload! >= 0); |
44 | 39 | t.true(timings.response! >= 0); |
45 | 40 | t.true(timings.end! >= 0); |
46 | 41 |
|
| 42 | + // These connection timings are unavailable for HTTP/2 (socket is a proxy) |
| 43 | + // See https://github.com/sindresorhus/got/issues/1958 |
| 44 | + t.is(timings.lookup, undefined); |
| 45 | + t.is(timings.connect, undefined); |
| 46 | + t.is(timings.secureConnect, undefined); |
| 47 | + |
47 | 48 | const {phases} = timings; |
48 | 49 |
|
| 50 | + // Available phases |
49 | 51 | t.true(phases.wait! >= 0); |
50 | | - t.true(phases.dns! >= 0); |
51 | | - t.true(phases.tcp! >= 0); |
52 | | - t.true(phases.tls! >= 0); |
53 | | - t.true(phases.request! >= 0); |
54 | 52 | t.true(phases.firstByte! >= 0); |
55 | 53 | t.true(phases.download! >= 0); |
56 | 54 | t.true(phases.total! >= 0); |
| 55 | + |
| 56 | + // Unavailable phases (due to missing connection timings) |
| 57 | + t.is(phases.dns, undefined); |
| 58 | + t.is(phases.tcp, undefined); |
| 59 | + t.is(phases.tls, undefined); |
| 60 | + // Most importantly: phases.request should be undefined, NOT NaN |
| 61 | + t.is(phases.request, undefined); |
| 62 | + t.false(Number.isNaN(phases.request)); |
57 | 63 | }); |
58 | 64 |
|
59 | 65 | test('timings.end is set when stream is destroyed before completion', withServer, async (t, server, got) => { |
|
0 commit comments