test: use exported response reader in proxy fixtures

This commit is contained in:
Sameh Khamis committed 2026-09-14 22:12:53 -07:00
1 parent 66eb6d6a7c
commit 2b09352463
1 file changed
+3 -1
+3 -1
View File
@@ -2,6 +2,7 @@ import test from 'node:test';
import assert from 'node:assert/strict'; import assert from 'node:assert/strict';
import { readFileSync } from 'node:fs'; import { readFileSync } from 'node:fs';
import path from 'node:path'; import path from 'node:path';
import { readResponseTextCapped } from './sources/httpBody.js';
const source = ['local.js', 'common/http.js', 'aircraft/enrichment.js', 'terrain.js', 'space/celestrak.js', 'space/launch-library.js', '../../src/data/spaceProviderRequests.js'] const source = ['local.js', 'common/http.js', 'aircraft/enrichment.js', 'terrain.js', 'space/celestrak.js', 'space/launch-library.js', '../../src/data/spaceProviderRequests.js']
.map(file => readFileSync(new URL(`../server/providers/${file}`, import.meta.url), 'utf8')) .map(file => readFileSync(new URL(`../server/providers/${file}`, import.meta.url), 'utf8'))
@@ -20,6 +21,7 @@ function extract(name) {
function fixture(name, overrides = {}, preview = false) { function fixture(name, overrides = {}, preview = false) {
const logs = []; const logs = [];
const deps = { const deps = {
readResponseTextCapped,
path, process: { cwd: () => '/fixture', env: {} }, path, process: { cwd: () => '/fixture', env: {} },
fsp: { fsp: {
readFile: async () => { throw new Error('cache absent'); }, readFile: async () => { throw new Error('cache absent'); },
@@ -34,7 +36,7 @@ function fixture(name, overrides = {}, preview = false) {
resolveTerrainHeightRequest: async () => { throw new Error(detail); }, resolveTerrainHeightRequest: async () => { throw new Error(detail); },
...overrides, ...overrides,
}; };
const helpers = ['readResponseTextCapped', 'coalesceProxyRequest', 'launchLibraryRequestHeaders', 'celestrakTleUrl', 'launchLibraryRecentUrl'].map(extract).join('\n'); const helpers = ['coalesceProxyRequest', 'launchLibraryRequestHeaders', 'celestrakTleUrl', 'launchLibraryRecentUrl'].map(extract).join('\n');
const plugin = new Function(...Object.keys(deps), `${helpers}\n${extract(name)}\nreturn ${name}();`)(...Object.values(deps)); const plugin = new Function(...Object.keys(deps), `${helpers}\n${extract(name)}\nreturn ${name}();`)(...Object.values(deps));
let middleware; let middleware;
plugin[preview ? 'configurePreviewServer' : 'configureServer']({ middlewares: { use(_route, handler) { middleware = handler; } } }); plugin[preview ? 'configurePreviewServer' : 'configureServer']({ middlewares: { use(_route, handler) { middleware = handler; } } });