-
Notifications
You must be signed in to change notification settings - Fork 561
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert nowAbsolute, add regression test (#3850)
Signed-off-by: Matteo Collina <hello@matteocollina.com>
- Loading branch information
Showing
9 changed files
with
69 additions
and
70 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
'use strict' | ||
|
||
const { test, after } = require('node:test') | ||
const { strictEqual } = require('node:assert') | ||
const { createServer } = require('node:http') | ||
const { once } = require('node:events') | ||
const { request, Client, interceptors } = require('../../index') | ||
const { setTimeout: sleep } = require('timers/promises') | ||
|
||
test('revalidates the request when the response is stale', async () => { | ||
let count = 0 | ||
const server = createServer((req, res) => { | ||
res.setHeader('Cache-Control', 'public, max-age=1') | ||
res.end('hello world ' + count++) | ||
}) | ||
|
||
server.listen(0) | ||
await once(server, 'listening') | ||
|
||
const dispatcher = new Client(`http://localhost:${server.address().port}`) | ||
.compose(interceptors.cache()) | ||
|
||
after(async () => { | ||
server.close() | ||
await dispatcher.close() | ||
}) | ||
|
||
const url = `http://localhost:${server.address().port}` | ||
|
||
{ | ||
const res = await request(url, { dispatcher }) | ||
strictEqual(await res.body.text(), 'hello world 0') | ||
} | ||
|
||
{ | ||
const res = await request(url, { dispatcher }) | ||
strictEqual(await res.body.text(), 'hello world 0') | ||
} | ||
|
||
await sleep(1000) | ||
|
||
{ | ||
const res = await request(url, { dispatcher }) | ||
|
||
strictEqual(await res.body.text(), 'hello world 1') | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters