cli
cli copied to clipboard
Add e2e tests for the `history` command
User story
As a developer I want to fully rely on the CI and a good test coverage so I confidently can change the codebase and realease continuously on a high frequent.
Acceptance criteria
The history command should cover the following tests:
-
e2e/cli-e2e/tet/history.e2e.ts
- it should get the last 2 commits in history produce reports in all formats and upload them -
e2e/cli-e2e/tet/history.e2e.ts
- it should ??? - Some plugins are filtered out, all (to check it returns empty array) and none (to check it returns identical array). Currently, only one out of three cases is covered for both plugins and categories.
Implementation details
Hints:
We did similar tests already in utils/scr/lib/git.integration.test.ts
.
Further more the implementation could look like this:
const git = simpleGit('examples/react-todos-app'); git.init();
... and always clean up afterwards.
In the E2E tests for the compare command, there we make changes to the example app and clean them up afterwards, that's quite similar. The only extra prerequisite is that there are no unstaged changes to the example app.
Snippet from old tests:
import { readdir } from 'node:fs/promises';
import { join } from 'node:path';
import { PluginReport, Report, reportSchema } from '@code-pushup/models';
import { cleanTestFolder } from '@code-pushup/test-setup';
import { executeProcess, readJsonFile } from '@code-pushup/utils';
describe('CLI history', () => {
/* eslint-disable @typescript-eslint/no-unused-vars */
const omitVariableData = ({
date,
duration,
version,
...report
}: Omit<Report, 'commit'> | PluginReport) => report;
const omitVariableReportData = ({ commit, ...report }: Report) =>
omitVariableData({
...report,
plugins: report.plugins.map(omitVariableData) as PluginReport[],
});
/* eslint-enable @typescript-eslint/no-unused-vars */
beforeEach(async () => {
await cleanTestFolder('tmp/e2e');
});
it('should run ESLint plugin and create report.json for the last 5 commits', async () => {
const { code, stderr } = await executeProcess({
command: 'code-pushup',
args: [
'history',
'--persist.outputDir=../../tmp/e2e/react-todos-app/history',
'--no-progress',
'--onlyPlugins=eslint',
'--forceCleanStatus',
],
cwd: 'examples/react-todos-app',
});
expect(code).toBe(0);
expect(stderr).toBe('');
const outputDirFromRoot = join('tmp', 'e2e', 'react-todos-app', 'history');
const reportPaths = await readdir(outputDirFromRoot);
const results = await Promise.all([
readJsonFile(join(outputDirFromRoot, reportPaths.at(0)!)),
readJsonFile(join(outputDirFromRoot, reportPaths.at(1)!)),
readJsonFile(join(outputDirFromRoot, reportPaths.at(2)!)),
readJsonFile(join(outputDirFromRoot, reportPaths.at(3)!)),
readJsonFile(join(outputDirFromRoot, reportPaths.at(4)!)),
]);
expect(results).toHaveLength(5);
expect(() => reportSchema.parse(results.at(0))).not.toThrow();
expect(() => reportSchema.parse(results.at(1))).not.toThrow();
expect(() => reportSchema.parse(results.at(2))).not.toThrow();
expect(() => reportSchema.parse(results.at(3))).not.toThrow();
expect(() => reportSchema.parse(results.at(4))).not.toThrow();
});
});