Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix sloppily written test #10976

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions packages/bun-internal-test/src/runner.node.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,23 @@ uncygwinTempDir();
const cwd = resolve(fileURLToPath(import.meta.url), "../../../../");
process.chdir(cwd);

function makeRunningBunInstallInWrongDirectoryFailInCI() {
const paths = [join(cwd, "package.json"), join(cwd, "test", "package.json")];

for (const current of paths) {
const inputPackageJSON = JSON.parse(readFileSync(current, "utf-8"));
inputPackageJSON.scripts ??= {};
inputPackageJSON.scripts.prepublish =
inputPackageJSON.scripts.preinstall =
inputPackageJSON.scripts.postinstall =
inputPackageJSON.scripts.install =
`echo "Ran bun install in the wrong directory. This is a bug in your test. Please fix your test." && exit 42`;
writeFileSync(current, JSON.stringify(inputPackageJSON, null, 2));
}
}

makeRunningBunInstallInWrongDirectoryFailInCI();

const ci = !!process.env["GITHUB_ACTIONS"];
const enableProgressBar = false;

Expand Down
1 change: 1 addition & 0 deletions test/harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const isLinux = process.platform === "linux";
export const isPosix = isMacOS || isLinux;
export const isWindows = process.platform === "win32";
export const isIntelMacOS = isMacOS && process.arch === "x64";
export const isBunCI = !!process.env.BUN_FEATURE_FLAG_INTERNAL_FOR_TESTING;

export const bunEnv: NodeJS.ProcessEnv = {
...process.env,
Expand Down
32 changes: 16 additions & 16 deletions test/js/third_party/stripe.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { bunExe } from "bun:harness";
import { bunEnv, tmpdirSync } from "harness";
import { expect, it } from "bun:test";
import { bunEnv, isBunCI, tmpdirSync } from "harness";
import * as path from "node:path";
import { createTest } from "node-harness";
const { describe, expect, it, beforeAll, afterAll, createDoneDotAll } = createTest(import.meta.path);

it.skipIf(!process.env.TEST_INFO_STRIPE)("should be able to query a charge", async () => {
it.skipIf(!isBunCI && !process.env.TEST_INFO_STRIPE)("should be able to query a charge", async () => {
Comment on lines -7 to +6
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what issues did you have running it locally?

const package_dir = tmpdirSync("bun-test-");

await Bun.write(
Expand All @@ -16,26 +15,23 @@ it.skipIf(!process.env.TEST_INFO_STRIPE)("should be able to query a charge", asy
}),
);

let { stdout, stderr } = Bun.spawn({
let { exited } = Bun.spawn({
cmd: [bunExe(), "install"],
stdout: "pipe",
stdout: "inherit",
cwd: package_dir,
stdin: "ignore",
stderr: "pipe",
stderr: "inherit",
env: bunEnv,
});
let err = await new Response(stderr).text();
expect(err).not.toContain("panic:");
expect(err).not.toContain("error:");
expect(err).not.toContain("warn:");
let out = await new Response(stdout).text();
expect(await exited).toBe(0);
Copy link
Contributor

@nektro nektro May 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it was done the other way so that you can see what the error was when it failed and nothing when it succeeds


// prettier-ignore
const [access_token, charge_id, account_id] = process.env.TEST_INFO_STRIPE?.split(",");

const fixture_path = path.join(package_dir, "index.js");
await Bun.write(
fixture_path,
String.raw`
`
const Stripe = require("stripe");
const stripe = Stripe("${access_token}");

Expand All @@ -48,16 +44,20 @@ it.skipIf(!process.env.TEST_INFO_STRIPE)("should be able to query a charge", asy
});
`,
);
let stdout, stderr;

({ stdout, stderr } = Bun.spawn({
({ stdout, stderr, exited } = Bun.spawn({
cmd: [bunExe(), "run", fixture_path],
stdout: "pipe",
stdin: "ignore",
stderr: "pipe",
cwd: package_dir,
env: bunEnv,
}));
out = await new Response(stdout).text();
let out = await new Response(stdout).text();
expect(out).toBeEmpty();
err = await new Response(stderr).text();
let err = await new Response(stderr).text();
expect(err).toContain(`error: No such charge: '${charge_id}'\n`);

expect(await exited).toBe(1);
});
Loading