Skip to content

Commit

Permalink
test: wip: fixed test teardown script
Browse files Browse the repository at this point in the history
  • Loading branch information
andreszorro committed Feb 22, 2024
1 parent 3f8aad2 commit 1d00699
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 9 deletions.
1 change: 1 addition & 0 deletions lib/templates/.gitkeep
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// empty
1 change: 1 addition & 0 deletions lib/templates/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const templatesMap = new Map([
["templates/test-template.hbs", testTemplate],
["templates/constant.hbs", constant],
["templates/containers/container.hbs", containersContainer],
["templates/.gitkeep", gitkeep],
["templates/decisions/.gitkeep", gitkeep],
["templates/docs/.gitkeep", gitkeep],
["templates/environments/deployment.hbs", environmentsDeployment],
Expand Down
35 changes: 32 additions & 3 deletions lib/utils/actions/add-many.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { afterAll, describe, expect, test } from "bun:test";
import { describe, expect, test } from "bun:test";
import { resolve } from "node:path";
import { $, file } from "bun";
import { ActionTypes } from ".";
Expand Down Expand Up @@ -56,7 +56,36 @@ describe("actions > addMany", () => {
);
expect(generatedFile2.size).toBeGreaterThan(0);
});
afterAll(async () => {
await $`rm -rf ${resolve(import.meta.dirname, ".test-generated")}`;
test("shared templates", async () => {
await $`rm -rf ${resolve(
import.meta.dirname,
".test-generated/scripts/update.sh",
)}`;

const result = await addMany(
{},
{
type: ActionTypes.AddMany,
templates,
templateFiles: "templates/**/.gitkeep",
rootPath: import.meta.dirname,
skipIfExists: true,
destination: ".test-generated",
},
);

expect(result).toBeTrue();
const generatedFile1 = file(
resolve(import.meta.dirname, ".test-generated/.gitkeep"),
);
expect(generatedFile1.size).toBeGreaterThan(0);
const generatedFile2 = file(
resolve(import.meta.dirname, ".test-generated/decisions/.gitkeep"),
);
expect(generatedFile2.size).toBeGreaterThan(0);
const generatedFile3 = file(
resolve(import.meta.dirname, ".test-generated/docs/.gitkeep"),
);
expect(generatedFile3.size).toBeGreaterThan(0);
});
});
7 changes: 2 additions & 5 deletions lib/utils/actions/add.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { afterAll, describe, expect, test } from "bun:test";
import { describe, expect, test } from "bun:test";
import { resolve } from "node:path";
import { $, file } from "bun";
import { file } from "bun";
import { ActionTypes } from ".";
import templates from "../../templates/bundle";
import { add } from "./add";
Expand Down Expand Up @@ -45,7 +45,4 @@ describe("actions > add", () => {
);
expect(generatedFile.size).toBeGreaterThan(0);
});
afterAll(async () => {
await $`rm -rf ${resolve(import.meta.dirname, ".test-generated")}`;
});
});
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
"bin": {
"bpdsl": "lib/main.ts"
},
"scripts": {
"test:dev": "bun test --watch --preload ./test-setup.ts",
"test": "bun test --preload ./test-setup.ts",
"test:ci": "bun test --preload ./test-setup.ts --coverage"
},
"type": "module",
"dependencies": {
"chalk": "^5.3.0",
Expand All @@ -31,6 +36,7 @@
"signal-exit": "3.x"
},
"lint-staged": {
"*": "bun biome ci"
"*": "bun biome ci",
"**/*.ts": "bun run test:ci"
}
}
10 changes: 10 additions & 0 deletions test-setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { afterAll } from "bun:test";
import { rm } from "node:fs/promises";
import { $ } from "bun";

afterAll(async () => {
const results = await $`find . -name .test-generated`.text();
for (const result of results.trim().split("\n")) {
await rm(result, { recursive: true });
}
});

0 comments on commit 1d00699

Please sign in to comment.