Skip to content

Commit bad778e

Browse files
committed
chore: update more setup files
1 parent 39b524c commit bad778e

File tree

5 files changed

+52
-148
lines changed

5 files changed

+52
-148
lines changed

bun.lockb

10.3 KB
Binary file not shown.

bunfig.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[test]
2+
preload = ["./setup.ts"]

lint.ts

Lines changed: 0 additions & 146 deletions
This file was deleted.

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
"test": "bun test",
55
"fmt": "bun x prettier -w **/*.sh .sample/run.sh new.sh **/*.ts **/*.md *.md && terraform fmt **/*.tf .sample/main.tf",
66
"fmt:ci": "bun x prettier --check **/*.sh .sample/run.sh new.sh **/*.ts **/*.md *.md && terraform fmt -check **/*.tf .sample/main.tf",
7-
"lint": "bun run lint.ts && ./terraform_validate.sh",
87
"update-version": "./update-version.sh"
98
},
109
"devDependencies": {
@@ -25,4 +24,4 @@
2524
"prettier-plugin-terraform-formatter"
2625
]
2726
}
28-
}
27+
}

setup.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { readableStreamToText, spawn } from "bun";
2+
import { afterAll } from "bun:test";
3+
4+
async function removeStatefiles(): Promise<void> {
5+
const process = spawn([
6+
"find",
7+
".",
8+
"-type",
9+
"f",
10+
"-o",
11+
"-name",
12+
"*.tfstate",
13+
"-o",
14+
"-name",
15+
"*.tfstate.lock.info",
16+
"-delete",
17+
]);
18+
await process.exited;
19+
}
20+
21+
async function removeOldContainers(): Promise<void> {
22+
let process = spawn([
23+
"docker",
24+
"ps",
25+
"-a",
26+
"-q",
27+
"--filter",
28+
"label=modules-test",
29+
]);
30+
let containerIDsRaw = await readableStreamToText(process.stdout);
31+
let exitCode = await process.exited;
32+
if (exitCode !== 0) {
33+
throw new Error(containerIDsRaw);
34+
}
35+
containerIDsRaw = containerIDsRaw.trim();
36+
if (containerIDsRaw === "") {
37+
return;
38+
}
39+
process = spawn(["docker", "rm", "-f", ...containerIDsRaw.split("\n")]);
40+
const stdout = await readableStreamToText(process.stdout);
41+
exitCode = await process.exited;
42+
if (exitCode !== 0) {
43+
throw new Error(stdout);
44+
}
45+
}
46+
47+
afterAll(async () => {
48+
await Promise.all([removeStatefiles(), removeOldContainers()]);
49+
});

0 commit comments

Comments
 (0)