Skip to content

Commit

Permalink
Remove node-fetch dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
mnot committed Jan 21, 2025
1 parent d85b82a commit dda5ccd
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 26 deletions.
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
"dependencies": {
"liquidjs": "^10.9.2",
"marked": "^15.0.0",
"node-fetch": "3.1.1",
"node-fetch-with-proxy": "^0.1.6",
"npm": "^11.0.0"
},
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion test-browser.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import * as display from './test-engine/lib/display.mjs'
import baseTests from './tests/index.mjs'

runTests(baseTests, fetch, true)
runTests(baseTests, true)
.then(function() {
let resultsTarget = document.getElementById('results')
display.renderTestResults(baseTests, getResults(), testUUIDs, resultsTarget, true)
Expand Down
3 changes: 1 addition & 2 deletions test-engine/cli.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { runTests, getResults } from './client/runner.mjs'
import { determineTestResult } from './lib/results.mjs'
import { GREEN, NC } from './lib/defines.mjs'
import fetch from 'node-fetch-with-proxy'
import tests from '../tests/index.mjs'

const baseUrl = process.env.npm_config_base || process.env.npm_package_config_base
Expand All @@ -27,7 +26,7 @@ if (testId !== '') {
testsToRun = tests
}

await runTests(testsToRun, fetch, false, baseUrl).catch(err => {
await runTests(testsToRun, false, baseUrl).catch(err => {
console.error(err)
process.exit(1)
})
Expand Down
11 changes: 0 additions & 11 deletions test-engine/client/config.mjs
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
export let fetch = null
export let useBrowserCache = false
export let baseUrl = ''
export const requestTimeout = 10 // seconds

export function setFetch (call) {
if (call !== undefined) {
if ('bind' in call) {
fetch = call.bind(fetch)
} else {
fetch = call
}
}
}

export function setUseBrowserCache (bool) {
if (bool !== undefined) useBrowserCache = bool
}
Expand Down
2 changes: 1 addition & 1 deletion test-engine/client/fetching.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export function init (idx, reqConfig, prevResp) {
init.headers.push(['Cache-Control', 'nothing-to-see-here']) // ditto
}
if ('request_method' in reqConfig) init.method = reqConfig.request_method
if ('request_headers' in reqConfig) init.headers = reqConfig.request_headers
if ('request_headers' in reqConfig) init.headers = init.headers.concat(reqConfig.request_headers)
if ('magic_ims' in reqConfig && reqConfig.magic_ims === true) {
for (let i = 0; i < init.headers.length; i++) {
const header = init.headers[i]
Expand Down
3 changes: 1 addition & 2 deletions test-engine/client/runner.mjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import * as config from './config.mjs'
import { makeTest, testResults } from './test.mjs'

export async function runTests (tests, myFetch, browserCache, base, chunkSize = 50) {
config.setFetch(myFetch)
export async function runTests (tests, browserCache, base, chunkSize = 25) {
config.setBaseUrl(base)
config.setUseBrowserCache(browserCache)

Expand Down
10 changes: 5 additions & 5 deletions test-engine/client/test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export async function makeTest (test) {
}, config.requestTimeout * 1000)
init.signal = controller.signal
if (test.dump === true) clientUtils.logRequest(url, init, reqNum)
return config.fetch(url, init)
return fetch(url, init)
.then(response => {
responses.push(response)
return checkResponse(test, requests, idx, response)
Expand Down Expand Up @@ -61,6 +61,10 @@ export async function makeTest (test) {
}
}

function handleError (err) {
console.error(`ERROR: ${uuid} ${err.name} ${err.message}`)
}

return clientUtils.putTestConfig(uuid, requests)
.catch(handleError)
.then(runNextStep)
Expand Down Expand Up @@ -293,7 +297,3 @@ function checkServerRequests (requests, responses, serverState) {
}
}
}

function handleError (err) {
console.error(`ERROR: ${err}`)
}
4 changes: 2 additions & 2 deletions test-engine/client/utils.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export async function putTestConfig (uuid, requests) {
headers: [['content-type', 'application/json']],
body: JSON.stringify(requests)
}
return config.fetch(`${config.baseUrl}/config/${uuid}`, init)
return fetch(`${config.baseUrl}/config/${uuid}`, init)
.then(response => {
if (response.status !== 201) {
let headers = ''
Expand All @@ -44,7 +44,7 @@ export async function putTestConfig (uuid, requests) {
}

export async function getServerState (uuid) {
return config.fetch(`${config.baseUrl}/state/${uuid}`)
return fetch(`${config.baseUrl}/state/${uuid}`)
.then(response => {
if (response.status === 200) {
return response.text()
Expand Down

0 comments on commit dda5ccd

Please sign in to comment.