mirror of
https://github.com/oven-sh/bun
synced 2026-02-02 15:08:46 +00:00
Update ci_info with more CI detection (#23708)
Fixes ENG-21481 Updates ci_info to include more CIs. It makes it codegen the ci detection based on the json from the ci-info package. Also it supports setting CI=true to force ci detected. --------- Co-authored-by: pfg <pfg@pfg.pw> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
5
test/cli/env/ci-info.fixture.ts
vendored
Normal file
5
test/cli/env/ci-info.fixture.ts
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
import { test, expect } from "bun:test";
|
||||
|
||||
test.only("only", () => {
|
||||
expect(1 + 1).toBe(2);
|
||||
});
|
||||
48
test/cli/env/ci-info.test.ts
vendored
Normal file
48
test/cli/env/ci-info.test.ts
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
import { describe, expect, test } from "bun:test";
|
||||
import { bunEnv, bunExe } from "../../harness";
|
||||
|
||||
const cleanEnv = { ...bunEnv };
|
||||
delete cleanEnv.GITHUB_ACTIONS;
|
||||
delete cleanEnv.GITLAB_CI;
|
||||
delete cleanEnv.CIRCLECI;
|
||||
delete cleanEnv.TRAVIS;
|
||||
delete cleanEnv.BUILDKITE;
|
||||
delete cleanEnv.JENKINS_URL;
|
||||
delete cleanEnv.BUILD_ID;
|
||||
delete cleanEnv.CI;
|
||||
|
||||
async function performTest(env: Record<string, string | undefined>, result: "deny-only" | "allow-only") {
|
||||
await using proc = Bun.spawn({
|
||||
cmd: [bunExe(), "test", "./ci-info.fixture.ts"],
|
||||
env,
|
||||
cwd: import.meta.dir,
|
||||
stdout: "pipe",
|
||||
stderr: "pipe",
|
||||
});
|
||||
|
||||
const [stdout, stderr, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]);
|
||||
|
||||
// test.only should work (not throw) when CI=false
|
||||
if (result === "deny-only") {
|
||||
expect(stderr).toContain(".only is disabled in CI environments");
|
||||
expect(exitCode).toBe(1);
|
||||
} else {
|
||||
expect(stderr).toContain("1 pass");
|
||||
expect(exitCode).toBe(0);
|
||||
}
|
||||
}
|
||||
|
||||
describe("CI detection", () => {
|
||||
test("Without CI env vars, test.only should work", async () => {
|
||||
await performTest(cleanEnv, "allow-only");
|
||||
});
|
||||
test("CI=false disables CI detection even with GITHUB_ACTIONS=true", async () => {
|
||||
await performTest({ ...cleanEnv, CI: "false", GITHUB_ACTIONS: "true" }, "allow-only");
|
||||
});
|
||||
test("CI=true enables CI detection even with no CI env vars", async () => {
|
||||
await performTest({ ...cleanEnv, CI: "true" }, "deny-only");
|
||||
});
|
||||
test("CI=true enables CI detection with GITHUB_ACTIONS=true", async () => {
|
||||
await performTest({ ...cleanEnv, CI: "true", GITHUB_ACTIONS: "true" }, "deny-only");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user