Skip to content

Commit

Permalink
chore: test cleanup of unneeded folders (#1449)
Browse files Browse the repository at this point in the history
## Description

When running `npm test` the `pepr-test-module` is created with journey
tests are run on module. This is a common place to test new features in
the controller. However, there was legacy folders being left in the
`dist` folder after the test ended. This PR cleans up the legacy folders
that are no longer needed after the test ends and not relevant for
controller testing.

End to End Test:  <!-- if applicable -->  
(See [Pepr Excellent
Examples](https://github.com/defenseunicorns/pepr-excellent-examples))

## Related Issue

Fixes #1361 
<!-- or -->
Relates to #

## Type of change

- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [x] Other (security config, docs update, etc)

## Checklist before merging
- [x] Unit,
[Journey](https://github.com/defenseunicorns/pepr/tree/main/journey),
[E2E Tests](https://github.com/defenseunicorns/pepr-excellent-examples),
[docs](https://github.com/defenseunicorns/pepr/tree/main/docs),
[adr](https://github.com/defenseunicorns/pepr/tree/main/adr) added or
updated as needed
- [x] [Contributor Guide
Steps](https://docs.pepr.dev/main/contribute/#submitting-a-pull-request)
followed

Signed-off-by: Case Wylie <cmwylie19@defenseunicorns.com>
  • Loading branch information
cmwylie19 authored Nov 20, 2024
1 parent feff8ee commit 5d85820
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 5 deletions.
9 changes: 7 additions & 2 deletions journey/entrypoint-wasm.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2023-Present The Pepr Authors

import { describe, jest } from "@jest/globals";
import { describe, jest, afterAll } from "@jest/globals";
import { peprBuild } from "./pepr-build-wasm";

import { removeFolder } from "./utils";
import { outputDir } from "./pepr-build-wasm";
// Unmock unit test things
jest.deepUnmock("pino");

// Allow 5 minutes for the tests to run
jest.setTimeout(1000 * 60 * 5);

afterAll(async () => {
await removeFolder(outputDir);
});

describe(
"Journey: `npx pepr build -r gchr.io/defenseunicorns -o dist/pepr-test-module/child/folder`",
peprBuild,
Expand Down
9 changes: 6 additions & 3 deletions journey/entrypoint.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2023-Present The Pepr Authors

import { beforeAll, describe, jest } from "@jest/globals";
import { beforeAll, afterAll, describe, jest } from "@jest/globals";

import { before } from "./before";
import { peprBuild } from "./pepr-build";
import { peprDeploy } from "./pepr-deploy";
import { peprDev } from "./pepr-dev";
import { peprFormat } from "./pepr-format";
import { peprInit } from "./pepr-init";

import { removeFolder } from "./utils";
import { outputDir } from "./pepr-build-wasm";
// Unmock unit test things
jest.deepUnmock("pino");

Expand All @@ -20,7 +21,9 @@ jest.setTimeout(1000 * 60 * 5);

// Configure the test environment before running the tests
beforeAll(before);

afterAll(async () => {
await removeFolder(outputDir);
});
describe("Journey: `npx pepr init`", peprInit);

describe("Journey: `npx pepr format`", peprFormat);
Expand Down
23 changes: 23 additions & 0 deletions journey/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2023-Present The Pepr Authors
import { promises as fs } from "fs";
import { resolve, join } from "path";

/**
* Removes a folder and all its contents recursively.
* @param folderPath - The path to the folder to remove.
*/
export async function removeFolder(folderPath: string): Promise<void> {
const dir = resolve(folderPath);

try {
await fs.access(dir);
await fs.rm(dir, { recursive: true, force: true });
} catch (error) {
if ((error as NodeJS.ErrnoException).code === "ENOENT") {
// Folder is not there, do nothing
} else {
throw error;
}
}
}

0 comments on commit 5d85820

Please sign in to comment.