Skip to content

Commit

Permalink
test: add cli test to validate multiple manifest generation paths res…
Browse files Browse the repository at this point in the history
…ult in comparable output (#1642)

## Description

Adds a new `npm run test:int` (int == "integration") script to invoke a
new style of test -- integration tests -- where "integration" means
something like "wider in scope than unit tests" but "not requiring a
full K8s cluster" (general idea is to have a nice place for
non-k8s-required tests to land (e.g. client-side `pepr` CLI commands,
like init / build).

## Related Issue

Fixes #1654 

## 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

---------

Co-authored-by: Sam Mayer <[email protected]>
  • Loading branch information
btlghrants and samayer12 authored Jan 15, 2025
1 parent d5322f4 commit 64d6e41
Show file tree
Hide file tree
Showing 24 changed files with 1,358 additions and 129 deletions.
11 changes: 9 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": ["tsconfig.json"],
"project": ["tsconfig.eslint.json"],
"ecmaVersion": 2022
},
"rules": {
Expand All @@ -22,6 +22,12 @@
"no-invalid-this": "warn"
},
"overrides": [
{
"files": ["*.test.ts"],
"rules": {
"max-nested-callbacks": ["warn", { "max": 8 }]
}
},
{
"files": ["*.ts"],
"excludedFiles": "*.test.ts",
Expand All @@ -39,7 +45,8 @@
"pepr-test-module",
"build.mjs",
"journey",
"__mocks__"
"__mocks__",
"integration/testroot"
],
"root": true
}
127 changes: 0 additions & 127 deletions .github/workflows/cli-tests.yml

This file was deleted.

19 changes: 19 additions & 0 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,25 @@ jobs:
uses: codecov/codecov-action@1e68e06f1dbfde0e4cefc87efeba9e4643565303 # v5.1.2
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_ORG_TOKEN }}

integration:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

- name: Use Node.js 22
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
with:
node-version: 22
cache: "npm"
- name: Setup Helm
uses: azure/setup-helm@fe7b79cd5ee1e45176fcad797de68ecaf3ca4814 # v4.2.0
with:
version: v3.3.4

- run: npm ci
- run: npm run test:integration

journey:
runs-on: ubuntu-latest
steps:
Expand Down
2 changes: 2 additions & 0 deletions integration/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
testroot/
.npm/
52 changes: 52 additions & 0 deletions integration/cli/build.defaults.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2023-Present The Pepr Authors

import { beforeAll, describe, expect, it } from "@jest/globals";
import * as path from "node:path";
import * as fs from "node:fs/promises";
import { Workdir } from "../helpers/workdir";
import * as time from "../helpers/time";
import * as pepr from "../helpers/pepr";

const FILE = path.basename(__filename);
const HERE = __dirname;

describe("build", () => {
const workdir = new Workdir(`${FILE}`, `${HERE}/../testroot/cli`);

beforeAll(async () => {
await workdir.recreate();
});

describe("builds a module", () => {
const id = FILE.split(".").at(1);
const testModule = `${workdir.path()}/${id}`;

beforeAll(async () => {
await fs.rm(testModule, { recursive: true, force: true });
const argz = [
`--name ${id}`,
`--description ${id}`,
`--errorBehavior reject`,
"--confirm",
"--skip-post-init",
].join(" ");
await pepr.cli(workdir.path(), { cmd: `pepr init ${argz}` });
await pepr.tgzifyModule(testModule);
await pepr.cli(testModule, { cmd: `npm install` });
}, time.toMs("2m"));

describe("using default build options", () => {
it(
"builds",
async () => {
const build = await pepr.cli(testModule, { cmd: `pepr build` });
expect(build.exitcode).toBe(0);
expect(build.stderr.join("").trim()).toBe("");
expect(build.stdout.join("").trim()).toContain("K8s resource for the module saved");
},
time.toMs("1m"),
);
});
});
});
31 changes: 31 additions & 0 deletions integration/cli/build.help.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2023-Present The Pepr Authors

import { beforeAll, describe, expect, it } from "@jest/globals";
import * as path from "node:path";
import { Workdir } from "../helpers/workdir";
import * as pepr from "../helpers/pepr";
import * as time from "../helpers/time";

const FILE = path.basename(__filename);
const HERE = __dirname;

describe("build", () => {
const workdir = new Workdir(`${FILE}`, `${HERE}/../testroot/cli`);

beforeAll(async () => {
await workdir.recreate();
});

it(
"gives command line help",
async () => {
const argz = "--help";
const result = await pepr.cli(workdir.path(), { cmd: `pepr build ${argz}` });
expect(result.exitcode).toBe(0);
expect(result.stderr.join("").trim()).toBe("");
expect(result.stdout.at(0)).toMatch("Usage: pepr build");
},
time.toMs("30s"),
);
});
88 changes: 88 additions & 0 deletions integration/cli/build.noembed.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2023-Present The Pepr Authors

import { beforeAll, describe, expect, it } from "@jest/globals";
import * as path from "node:path";
import * as fs from "node:fs/promises";
import { existsSync } from "node:fs";
import { Workdir } from "../helpers/workdir";
import * as time from "../helpers/time";
import * as pepr from "../helpers/pepr";
import * as resource from "../helpers/resource";

const FILE = path.basename(__filename);
const HERE = __dirname;

describe("build", () => {
const workdir = new Workdir(`${FILE}`, `${HERE}/../testroot/cli`);

beforeAll(async () => {
await workdir.recreate();
});

describe("builds a module", () => {
const id = FILE.split(".").at(1);
const testModule = `${workdir.path()}/${id}`;

beforeAll(async () => {
await fs.rm(testModule, { recursive: true, force: true });
const argz = [
`--name ${id}`,
`--description ${id}`,
`--errorBehavior reject`,
"--confirm",
"--skip-post-init",
].join(" ");
await pepr.cli(workdir.path(), { cmd: `pepr init ${argz}` });
await pepr.tgzifyModule(testModule);
await pepr.cli(testModule, { cmd: `npm install` });
}, time.toMs("2m"));

describe("for use as a library", () => {
let packageJson;
let uuid: string;

it(
"builds",
async () => {
const argz = [`--no-embed`].join(" ");
const build = await pepr.cli(testModule, { cmd: `pepr build ${argz}` });
expect(build.exitcode).toBe(0);
expect(build.stderr.join("").trim()).toContain("Error: Cannot find module");
expect(build.stdout.join("").trim()).toContain("");

packageJson = await resource.fromFile(`${testModule}/package.json`);
uuid = packageJson.pepr.uuid;
},
time.toMs("1m"),
);

it(
"outputs appropriate configuration",
async () => {
const missing = [
`${testModule}/dist/pepr-${uuid}.js`,
`${testModule}/dist/pepr-${uuid}.js.map`,
`${testModule}/dist/pepr-${uuid}.js.LEGAL.txt`,
`${testModule}/dist/pepr-module-${uuid}.yaml`,
`${testModule}/dist/zarf.yaml`,
`${testModule}/dist/${uuid}-chart/`,
];
for (const path of missing) {
expect(existsSync(path)).toBe(false);
}

const found = [
`${testModule}/dist/pepr.js`,
`${testModule}/dist/pepr.js.map`,
`${testModule}/dist/pepr.js.LEGAL.txt`,
];
for (const path of found) {
expect(existsSync(path)).toBe(true);
}
},
time.toMs("1m"),
);
});
});
});
Loading

0 comments on commit 64d6e41

Please sign in to comment.