mirror of
https://github.com/oven-sh/bun
synced 2026-02-12 03:48:56 +00:00
test(publish): ci names in user-agent (#14328)
This commit is contained in:
@@ -21,6 +21,7 @@ import {
|
||||
toHaveBins,
|
||||
toMatchNodeModulesAt,
|
||||
writeShebangScript,
|
||||
stderrForInstall,
|
||||
} from "harness";
|
||||
import { join, resolve, sep } from "path";
|
||||
import { readdirSorted } from "../dummy.registry";
|
||||
@@ -548,10 +549,14 @@ describe("publish", async () => {
|
||||
setAuthHeader?: boolean;
|
||||
otpFail?: boolean;
|
||||
npmNotice?: boolean;
|
||||
expectedCI?: string;
|
||||
}) {
|
||||
return async function (req: Request) {
|
||||
const { token, setAuthHeader = true, otpFail = false, npmNotice = false } = opts;
|
||||
if (req.url.includes("otp-pkg")) {
|
||||
if (opts.expectedCI) {
|
||||
expect(req.headers.get("user-agent")).toContain("ci/" + opts.expectedCI);
|
||||
}
|
||||
if (req.headers.get("npm-otp") === token) {
|
||||
if (otpFail) {
|
||||
return new Response(
|
||||
@@ -698,6 +703,47 @@ describe("publish", async () => {
|
||||
expect(exitCode).toBe(0);
|
||||
expect(err).toContain(`note: visit http://localhost:${mockRegistry.port}/auth to login`);
|
||||
});
|
||||
|
||||
const fakeCIEnvs = [
|
||||
{ ci: "expo-application-services", envs: { EAS_BUILD: "hi" } },
|
||||
{ ci: "codemagic", envs: { CM_BUILD_ID: "hi" } },
|
||||
{ ci: "vercel", envs: { "NOW_BUILDER": "hi" } },
|
||||
];
|
||||
for (const envInfo of fakeCIEnvs) {
|
||||
test(`CI user agent name: ${envInfo.ci}`, async () => {
|
||||
const token = await generateRegistryUser(`otp-${envInfo.ci}`, "otp");
|
||||
using mockRegistry = Bun.serve({
|
||||
port: 0,
|
||||
fetch: mockRegistryFetch({ token, expectedCI: envInfo.ci }),
|
||||
});
|
||||
|
||||
const bunfig = `
|
||||
[install]
|
||||
cache = false
|
||||
registry = { url = "http://localhost:${mockRegistry.port}", token = "${token}" }`;
|
||||
|
||||
await Promise.all([
|
||||
rm(join(import.meta.dir, "packages", "otp-pkg-4"), { recursive: true, force: true }),
|
||||
write(join(packageDir, "bunfig.toml"), bunfig),
|
||||
write(
|
||||
join(packageDir, "package.json"),
|
||||
JSON.stringify({
|
||||
name: "otp-pkg-4",
|
||||
version: "4.4.4",
|
||||
dependencies: {
|
||||
"otp-pkg-4": "4.4.4",
|
||||
},
|
||||
}),
|
||||
),
|
||||
]);
|
||||
|
||||
const { out, err, exitCode } = await publish(
|
||||
{ ...env, ...envInfo.envs, ...{ BUILDKITE: undefined, GITHUB_ACTIONS: undefined } },
|
||||
packageDir,
|
||||
);
|
||||
expect(exitCode).toBe(0);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
test("can publish a package then install it", async () => {
|
||||
@@ -7873,7 +7919,7 @@ for (const forceWaiterThread of isLinux ? [false, true] : [false]) {
|
||||
env: testEnv,
|
||||
});
|
||||
|
||||
let err = await Bun.readableStreamToText(stderr);
|
||||
let err = stderrForInstall(await Bun.readableStreamToText(stderr));
|
||||
expect(err).toContain("Saved lockfile");
|
||||
expect(err).not.toContain("not found");
|
||||
expect(err).not.toContain("error:");
|
||||
@@ -7906,7 +7952,7 @@ for (const forceWaiterThread of isLinux ? [false, true] : [false]) {
|
||||
env: testEnv,
|
||||
}));
|
||||
|
||||
err = await Bun.readableStreamToText(stderr);
|
||||
err = stderrForInstall(await Bun.readableStreamToText(stderr));
|
||||
expect(err).not.toContain("Saved lockfile");
|
||||
expect(err).not.toContain("not found");
|
||||
expect(err).not.toContain("error:");
|
||||
@@ -7940,7 +7986,7 @@ for (const forceWaiterThread of isLinux ? [false, true] : [false]) {
|
||||
env: testEnv,
|
||||
});
|
||||
|
||||
const err = await Bun.readableStreamToText(stderr);
|
||||
const err = stderrForInstall(await Bun.readableStreamToText(stderr));
|
||||
expect(err).toContain("Saved lockfile");
|
||||
expect(err).not.toContain("not found");
|
||||
expect(err).not.toContain("error:");
|
||||
@@ -7980,7 +8026,7 @@ for (const forceWaiterThread of isLinux ? [false, true] : [false]) {
|
||||
env: testEnv,
|
||||
});
|
||||
|
||||
let err = await Bun.readableStreamToText(stderr);
|
||||
let err = stderrForInstall(await Bun.readableStreamToText(stderr));
|
||||
expect(err).toContain("Saved lockfile");
|
||||
expect(err).not.toContain("not found");
|
||||
expect(err).not.toContain("error:");
|
||||
@@ -8067,7 +8113,7 @@ for (const forceWaiterThread of isLinux ? [false, true] : [false]) {
|
||||
env: testEnv,
|
||||
});
|
||||
|
||||
let err = await Bun.readableStreamToText(stderr);
|
||||
let err = stderrForInstall(await Bun.readableStreamToText(stderr));
|
||||
expect(err).toContain("Saved lockfile");
|
||||
expect(err).not.toContain("not found");
|
||||
expect(err).not.toContain("error:");
|
||||
@@ -8102,7 +8148,7 @@ for (const forceWaiterThread of isLinux ? [false, true] : [false]) {
|
||||
env: testEnv,
|
||||
}));
|
||||
|
||||
err = await Bun.readableStreamToText(stderr);
|
||||
err = stderrForInstall(await Bun.readableStreamToText(stderr));
|
||||
expect(err).not.toContain("Saved lockfile");
|
||||
expect(err).not.toContain("not found");
|
||||
expect(err).not.toContain("error:");
|
||||
@@ -8140,7 +8186,7 @@ for (const forceWaiterThread of isLinux ? [false, true] : [false]) {
|
||||
env: testEnv,
|
||||
});
|
||||
|
||||
let err = await Bun.readableStreamToText(stderr);
|
||||
let err = stderrForInstall(await Bun.readableStreamToText(stderr));
|
||||
expect(err).toContain("Saved lockfile");
|
||||
expect(err).not.toContain("not found");
|
||||
expect(err).not.toContain("error:");
|
||||
@@ -8187,7 +8233,7 @@ for (const forceWaiterThread of isLinux ? [false, true] : [false]) {
|
||||
env: testEnv,
|
||||
}));
|
||||
|
||||
err = await Bun.readableStreamToText(stderr);
|
||||
err = stderrForInstall(await Bun.readableStreamToText(stderr));
|
||||
expect(err).toContain("Saved lockfile");
|
||||
expect(err).not.toContain("not found");
|
||||
expect(err).not.toContain("error:");
|
||||
|
||||
@@ -1006,7 +1006,7 @@ export async function runBunInstall(
|
||||
});
|
||||
expect(stdout).toBeDefined();
|
||||
expect(stderr).toBeDefined();
|
||||
let err = (await new Response(stderr).text()).replace(/warn: Slow filesystem.*/g, "");
|
||||
let err = stderrForInstall(await new Response(stderr).text());
|
||||
expect(err).not.toContain("panic:");
|
||||
if (!options?.allowErrors) {
|
||||
expect(err).not.toContain("error:");
|
||||
@@ -1022,6 +1022,11 @@ export async function runBunInstall(
|
||||
return { out, err, exited };
|
||||
}
|
||||
|
||||
// stderr with `slow filesystem` warning removed
|
||||
export function stderrForInstall(err: string) {
|
||||
return err.replace(/warn: Slow filesystem.*/g, "");
|
||||
}
|
||||
|
||||
export async function runBunUpdate(
|
||||
env: NodeJS.ProcessEnv,
|
||||
cwd: string,
|
||||
|
||||
Reference in New Issue
Block a user