Files
bun.sh/test/js/bun/shell/util.ts
Jarred Sumner 291a39bd3f Do not run shell tests outside test scope (#10199)
* Do not run tests outside test scope

* Fix tests

* Fix type errors and remove potentially precarious uses of unreachable

* yoops

* Remove all instances of "Ruh roh"

---------

Co-authored-by: Zack Radisic <56137411+zackradisic@users.noreply.github.com>
2024-04-16 14:03:02 -07:00

38 lines
1.1 KiB
TypeScript

import { describe, test, afterAll, beforeAll, expect } from "bun:test";
import { ShellOutput } from "bun";
import { ShellPromise } from "bun";
import { tempDirWithFiles } from "harness";
import { join } from "node:path";
import * as fs from "node:fs";
import { createTestBuilder } from "./test_builder";
export { createTestBuilder };
declare module "bun" {
// Define the additional methods
interface Shell {
parse: (strings: TemplateStringsArray, ...expressions: any[]) => string; // Define the return type for parse
lex: (strings: TemplateStringsArray, ...expressions: any[]) => string; // Define the return type for lex
}
}
const defaultRedirect = {
__unused: 0,
append: false,
stderr: false,
stdin: false,
stdout: false,
duplicate_out: false,
};
export const redirect = (opts?: Partial<typeof defaultRedirect>): typeof defaultRedirect =>
opts === undefined
? defaultRedirect
: {
...defaultRedirect,
...opts,
};
export const sortedShellOutput = (output: string | string[]): string[] =>
(Array.isArray(output) ? output : output.split("\n").filter(s => s.length > 0)).sort();