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

tests: added test matrix to github actions #151

Open
wants to merge 10 commits into
base: improvedCommandErrorDetection
Choose a base branch
from
41 changes: 41 additions & 0 deletions .github/workflows/test-matrix.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
on:
schedule:
- cron: 0 12 * * *

jobs:
test:
strategy:
matrix:
node: [18, 20, 22]
os: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }}
needs: format-and-lint
steps:
- name: Check out code
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}

- name: Install dependencies
run: npm ci

- name: Build
run: npm run build

- name: Run tests and generate coverage
run: npm run test:coverage

- name: Run e2e tests
run: npm run test:e2e --prefix=test

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }} # Required for private repos
# todo: use lcov-result-merge to combine more results
files: ./packages/core/coverage/lcov.info
flags: unit
fail_ci_if_error: true
12 changes: 3 additions & 9 deletions .github/workflows/verify-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,12 @@ jobs:
run: npm run build

- name: Install lac
run: npm i -g @brainhubeu/lac
run: npm i -g @brainhubeu/lac

- name: Run audit
#Add `--bail 1` flag when it will be available on npm
#Add `--bail 1` flag when it will be available on npm
run: lac --default-config




test:
runs-on: ubuntu-latest
needs: format-and-lint
Expand All @@ -72,10 +69,7 @@ jobs:
run: npm run test:coverage

- name: Run e2e tests
run: npm run test:e2e

- name: Run snapshot tests
run: npm run test:snapshot
run: npm run test:e2e --prefix=test

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
Expand Down
32 changes: 30 additions & 2 deletions test/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,21 @@ export const pnpmFixture = test.extend<TestContext>({
verbatimSymlinks: true,
});

await use(testDirectory);
const packageManagers = ["7.30.0", "8.6.0", "9.14.4"];
for (const packageManager of packageManagers) {
const packageJsonPath = path.join(testDirectory, "package.json");
const packageJson = JSON.parse(
await fs.readFile(packageJsonPath, "utf8"),
);
packageJson.packageManager = `pnpm@${packageManager}`;
await fs.writeFile(
packageJsonPath,
JSON.stringify(packageJson, null, 2),
"utf8",
);

await use(testDirectory);
}

await fs.rm(testDirectory, { recursive: true });
},
Expand All @@ -122,7 +136,21 @@ export const yarnFixture = test.extend<TestContext>({
recursive: true,
});

await use(testDirectory);
const packageManagers = ["1.22.22", "3.8.7"];
for (const packageManager of packageManagers) {
const packageJsonPath = path.join(testDirectory, "package.json");
const packageJson = JSON.parse(
await fs.readFile(packageJsonPath, "utf8"),
);
packageJson.packageManager = `yarn@${packageManager}`;
await fs.writeFile(
packageJsonPath,
JSON.stringify(packageJson, null, 2),
"utf8",
);

await use(testDirectory);
}

await fs.rm(testDirectory, { recursive: true });
},
Expand Down
2 changes: 1 addition & 1 deletion test/test/yarn.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as fs from "node:fs/promises";
import * as path from "node:path";
import type { JsonResults } from "@license-auditor/data";
import { describe, expect } from "vitest";
import { yarnFixture, yarnWithInvalidGithubDepFixture } from "../fixtures";
import { yarnFixture } from "../fixtures";
import { addToPackageJson } from "../utils/add-to-package-json";
import { getCliPath } from "../utils/get-cli-path";
import { readJsonFile } from "../utils/read-json-file";
Expand Down
2 changes: 1 addition & 1 deletion test/utils/run-cli-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export async function runCliCommand(command: CliCommand) {
});

cli.onExit((code) => {
resolve({ output: output.join("\n"), errorCode: code.exitCode });
resolve({ output: output.join(""), errorCode: code.exitCode });
});
} catch (error) {
reject(error);
Expand Down
Loading