mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 10:28:47 +00:00
Fix lots of tests without cygwin
This commit is contained in:
@@ -123,7 +123,9 @@ describe("optionalDependencies", () => {
|
||||
savesLockfile: !rootOptional,
|
||||
});
|
||||
|
||||
expect(err).toContain("warn: GET http://localhost:4873/this-package-does-not-exist-in-the-registry - ");
|
||||
expect(err).toMatch(
|
||||
`warn: GET http://localhost:${port}/this-package-does-not-exist-in-the-registry/-/this-package-does-not-exist-in-the-registry-1.0.0.tgz - `,
|
||||
);
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -455,7 +457,7 @@ registry = "http://localhost:${port}"
|
||||
const lockfile = await parseLockfile(packageDir);
|
||||
for (const pkg of Object.values(lockfile.packages) as any) {
|
||||
if (pkg.tag === "npm") {
|
||||
expect(pkg.resolution.resolved).toContain("http://localhost:4873");
|
||||
expect(pkg.resolution.resolved).toContain(`http://localhost:${port}`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -476,7 +478,7 @@ cache = "${cacheDir}"
|
||||
const npmLockfile = await parseLockfile(packageDir);
|
||||
for (const pkg of Object.values(npmLockfile.packages) as any) {
|
||||
if (pkg.tag === "npm") {
|
||||
expect(pkg.resolution.resolved).not.toContain("http://localhost:4873");
|
||||
expect(pkg.resolution.resolved).not.toContain(`http://localhost:${port}`);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -57,30 +57,8 @@ export function nodeExe(): string | null {
|
||||
return which("node") || null;
|
||||
}
|
||||
|
||||
export function bashExe(): string {
|
||||
const bash = which("bash");
|
||||
if (!bash) {
|
||||
throw new Error("Failed to find 'bash'");
|
||||
}
|
||||
return bash;
|
||||
}
|
||||
|
||||
export function pwshExe(): string {
|
||||
if (!isWindows) {
|
||||
throw new Error("Powershell is only supported on Windows");
|
||||
}
|
||||
const pwsh = which("pwsh") || which("powershell");
|
||||
if (!pwsh) {
|
||||
throw new Error("Failed to find 'pwsh' or 'powershell'");
|
||||
}
|
||||
return pwsh;
|
||||
}
|
||||
|
||||
export function shellExe(): string {
|
||||
if (isWindows) {
|
||||
return bashExe() || pwshExe();
|
||||
}
|
||||
return bashExe();
|
||||
return isWindows ? "pwsh" : "bash";
|
||||
}
|
||||
|
||||
export function gc(force = true) {
|
||||
|
||||
@@ -2231,12 +2231,19 @@ describe("expect()", () => {
|
||||
expect(thisFile).toHaveLength(thisFileSize);
|
||||
expect(thisFile).toHaveLength(Bun.file(__filename).size);
|
||||
|
||||
const { join } = require("path");
|
||||
const { tmpdir } = require("os");
|
||||
const { mkdtempSync, writeFileSync } = require("fs");
|
||||
const tmpDir = mkdtempSync(join(tmpdir(), "jest-extended-"));
|
||||
const tmpFile = join(tmpDir, "empty.txt");
|
||||
writeFileSync(tmpFile, "");
|
||||
|
||||
// empty file should have length 0
|
||||
require("fs").writeFileSync("/tmp/empty.txt", "");
|
||||
expect(Bun.file("/tmp/empty.txt")).toHaveLength(0);
|
||||
|
||||
// if a file doesn't exist, it should throw (not return 0 size)
|
||||
expect(() => expect(Bun.file("/does-not-exist/file.txt")).toHaveLength(0)).toThrow();
|
||||
const emptyFile = join(tmpDir, "does-not-exist.txt");
|
||||
expect(() => expect(Bun.file(emptyFile)).toHaveLength(0)).toThrow();
|
||||
|
||||
// Blob
|
||||
expect(new Blob(ANY([1, 2, 3]))).toHaveLength(3);
|
||||
|
||||
@@ -45,18 +45,22 @@ describe("jest-extended", () => {
|
||||
new Uint8Array(),
|
||||
new Object(),
|
||||
Buffer.from(""),
|
||||
...(isBun ? [Bun.file("/tmp/empty.txt")] : []),
|
||||
new Headers(),
|
||||
new URLSearchParams(),
|
||||
new FormData(),
|
||||
(function* () {})(),
|
||||
];
|
||||
if (isBun) {
|
||||
const { join } = require("path");
|
||||
const { tmpdir } = require("os");
|
||||
const { mkdtempSync, writeFileSync } = require("fs");
|
||||
const tmpDir = mkdtempSync(join(tmpdir(), "jest-extended-"));
|
||||
const tmpFile = join(tmpDir, "empty.txt");
|
||||
values.push(Bun.file(tmpFile));
|
||||
writeFileSync(tmpFile, "");
|
||||
}
|
||||
for (const value of values) {
|
||||
test(label(value), () => {
|
||||
if (value && typeof value === "object" && value instanceof Blob) {
|
||||
require("fs").writeFileSync("/tmp/empty.txt", "");
|
||||
}
|
||||
|
||||
expect(value).toBeEmpty();
|
||||
});
|
||||
}
|
||||
|
||||
18
test/js/third_party/st.test.ts
vendored
18
test/js/third_party/st.test.ts
vendored
@@ -1,22 +1,22 @@
|
||||
import { bunExe } from "bun:harness";
|
||||
import { bunEnv } from "harness";
|
||||
import { bunExe, bunEnv } from "harness";
|
||||
import { expect, it } from "bun:test";
|
||||
import * as path from "node:path";
|
||||
import { join, dirname } from "node:path";
|
||||
|
||||
it("works", async () => {
|
||||
const fixture_path = path.join(import.meta.dirname, "_fixtures", "st.ts");
|
||||
const fixture_path = join(import.meta.dirname, "_fixtures", "st.ts");
|
||||
const fixture_data = await Bun.file(fixture_path).text();
|
||||
let { stdout, stderr, exited } = Bun.spawn({
|
||||
cmd: [bunExe(), "run", fixture_path],
|
||||
cwd: path.dirname(fixture_path),
|
||||
cwd: dirname(fixture_path),
|
||||
stdout: "pipe",
|
||||
stdin: "ignore",
|
||||
stderr: "pipe",
|
||||
env: bunEnv,
|
||||
});
|
||||
// err = await new Response(stderr).text();
|
||||
// expect(err).toBeEmpty();
|
||||
let out = await new Response(stdout).text();
|
||||
let [code, err, out] = await Promise.all([exited, new Response(stderr).text(), new Response(stdout).text()]);
|
||||
if (code !== 0) {
|
||||
expect(err).toBeEmpty();
|
||||
}
|
||||
expect(out).toEqual(fixture_data + "\n");
|
||||
expect(await exited).toBe(0);
|
||||
expect(code).toBe(0);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user