-
Notifications
You must be signed in to change notification settings - Fork 293
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(test): fix tests for axios/fetch/etc (#1252)
Fixes this 503 error ``` ● should execute "ncc run axios.js" /tmp/node_modules/axios/dist/node/axios.cjs:2019 reject(new AxiosError( ^ AxiosError: Request failed with status code 503 ``` https://github.com/vercel/ncc/actions/runs/13335750022/job/37250445802?pr=1250#step:10:278
- Loading branch information
Showing
4 changed files
with
20 additions
and
24 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,10 +1,10 @@ | ||
const axios = require("axios"); | ||
|
||
(async () => { | ||
const { data } = await axios({ | ||
url: "https://dog.ceo/api/breeds/image/random" | ||
const { status } = await axios({ | ||
url: "https://example.vercel.sh" | ||
}); | ||
if (data.status !== "success") { | ||
if (status !== 200) { | ||
throw new Error("Unexpected response: " + JSON.stringify(data)); | ||
} | ||
})(); |
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 |
---|---|---|
@@ -1,9 +1,8 @@ | ||
const fetch = require("isomorphic-unfetch"); | ||
|
||
(async () => { | ||
const res = await fetch("https://dog.ceo/api/breeds/image/random"); | ||
const data = await res.json() | ||
if (data.status !== "success") { | ||
throw new Error("Unexpected response: " + JSON.stringify(data)); | ||
} | ||
})(); | ||
const { status } = await fetch("https://example.vercel.sh"); | ||
if (status !== 200) { | ||
throw new Error(`Unexpected status: ${status}`); | ||
} | ||
})(); |
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 |
---|---|---|
@@ -1,15 +1,13 @@ | ||
import { get } from "request"; | ||
|
||
const url = "https://dog.ceo/api/breeds/image/random"; | ||
|
||
export default () => { | ||
return new Promise((resolve, reject) => { | ||
get(url, { json: true }, (err, resp, body) => { | ||
(async () => { | ||
await new Promise((resolve, reject) => { | ||
get("https://example.vercel.sh", { json: false }, (err, res) => { | ||
if (err) return reject(err); | ||
if (body.status != "success") { | ||
return reject(new Error("Bad api response: " + JSON.stringify(body))); | ||
if (res.statusCode !== 200) { | ||
return reject(new Error(`Bad status: ${res.statusCode}`)); | ||
} | ||
resolve('asdf'); | ||
resolve(true); | ||
}); | ||
}); | ||
}; | ||
})(); |
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 |
---|---|---|
@@ -1,14 +1,13 @@ | ||
const request = require("request"); | ||
const url = "https://dog.ceo/api/breeds/image/random"; | ||
|
||
(async () => { | ||
await new Promise((resolve, reject) => { | ||
request.get(url, { json: true }, (err, resp, body) => { | ||
request.get("https://example.vercel.sh", { json: false }, (err, res) => { | ||
if (err) return reject(err); | ||
if (body.status != "success") { | ||
return reject(new Error("Bad api response: " + JSON.stringify(body))); | ||
if (res.statusCode !== 200) { | ||
return reject(new Error(`Bad status: ${res.statusCode}`)); | ||
} | ||
resolve(); | ||
resolve(true); | ||
}); | ||
}); | ||
})(); | ||
})(); |