diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-21 20:56:19 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-21 20:56:19 +0000 |
commit | 0b6210cd37b68b94252cb798598b12974a20e1c1 (patch) | |
tree | e371686554a877842d95aa94f100bee552ff2a8e /test/fetch/issue-1447.js | |
parent | Initial commit. (diff) | |
download | node-undici-0b6210cd37b68b94252cb798598b12974a20e1c1.tar.xz node-undici-0b6210cd37b68b94252cb798598b12974a20e1c1.zip |
Adding upstream version 5.28.2+dfsg1+~cs23.11.12.3.upstream/5.28.2+dfsg1+_cs23.11.12.3upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | test/fetch/issue-1447.js | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/test/fetch/issue-1447.js b/test/fetch/issue-1447.js new file mode 100644 index 0000000..503b344 --- /dev/null +++ b/test/fetch/issue-1447.js @@ -0,0 +1,46 @@ +'use strict' + +const { test, skip } = require('tap') +const { nodeMajor } = require('../../lib/core/util') + +if (nodeMajor === 16) { + skip('esbuild uses static blocks with --keep-names which node 16.8 does not have') + process.exit() +} + +const undici = require('../..') +const { fetch: theoreticalGlobalFetch } = require('../../undici-fetch') + +test('Mocking works with both fetches', async (t) => { + const mockAgent = new undici.MockAgent() + const body = JSON.stringify({ foo: 'bar' }) + + mockAgent.disableNetConnect() + undici.setGlobalDispatcher(mockAgent) + const pool = mockAgent.get('https://example.com') + + pool.intercept({ + path: '/path', + method: 'POST', + body (bodyString) { + t.equal(bodyString, body) + return true + } + }).reply(200, { ok: 1 }).times(2) + + const url = new URL('https://example.com/path').href + + // undici fetch from node_modules + await undici.fetch(url, { + method: 'POST', + body + }) + + // the global fetch bundled with esbuild + await theoreticalGlobalFetch(url, { + method: 'POST', + body + }) + + t.end() +}) |