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

Make CI green: Fix flaky rm tests #10692

Closed
wants to merge 2 commits 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
11 changes: 8 additions & 3 deletions test/js/bun/shell/commands/rm.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,15 @@ const BUN = process.argv0;
const DEV_NULL = process.platform === "win32" ? "NUL" : "/dev/null";

describe("bunshell rm", () => {
TestBuilder.command`echo ${packagejson()} > package.json; ${BUN} install &> ${DEV_NULL}; rm -rf node_modules/`
.ensureTempDir()
let node_modules_dir: string = TestBuilder.tmpdir();
beforeAll(async () => {
console.log("Installing node_modules...");
await $`echo ${packagejson()} > package.json; ${BUN} install &> ${DEV_NULL}`.cwd(node_modules_dir).throws(true);
});

TestBuilder.command`rm -rf node_modules/`
.ensureTempDir(node_modules_dir)
.doesNotExist("node_modules")
.timeout(10 * 1000)
.runAsTest("node_modules");

test("force", async () => {
Expand Down
9 changes: 7 additions & 2 deletions test/js/bun/shell/test_builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,13 @@ export function createTestBuilder(path: string) {
* - All FS functions on the `TestBuilder` will use this temp directory.
* @returns
*/
ensureTempDir(): this {
this.getTempDir();
ensureTempDir(dir?: string): this {
if (dir !== undefined) {
this.tempdir = dir;
if (this.promise.type === "ok") this.promise.val.cwd(this.tempdir);
} else {
this.getTempDir();
}
return this;
}

Expand Down