Skip to content

Commit

Permalink
test: fix e2e tests
Browse files Browse the repository at this point in the history
inspiration from #810

Signed-off-by: Vojtech Masek <[email protected]>
  • Loading branch information
vmasek committed Sep 6, 2024
1 parent 60fe192 commit cd2ca75
Show file tree
Hide file tree
Showing 12 changed files with 29 additions and 26 deletions.
4 changes: 2 additions & 2 deletions e2e/cli-e2e/tests/collect.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ describe('CLI collect', () => {
expect(code).toBe(0);
const md = await readTextFile('tmp/e2e/react-todos-app/report.md');

expect(md).toContain('# Code PushUp Report');
expect(md).toContain('# Code PushUp report');
expect(md).toContain(exampleCategoryTitle);
expect(md).toContain(exampleAuditTitle);
});
Expand All @@ -174,7 +174,7 @@ describe('CLI collect', () => {

expect(code).toBe(0);

expect(stdout).toContain('Code PushUp Report');
expect(stdout).toContain('Code PushUp report');
expect(stdout).not.toContain('Generated reports');
expect(stdout).toContain(exampleCategoryTitle);
expect(stdout).toContain(exampleAuditTitle);
Expand Down
2 changes: 1 addition & 1 deletion e2e/nx-plugin-e2e/tests/executor-cli.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ async function addTargetToWorkspace(
...projectCfg,
targets: {
...projectCfg.targets,
['code-pushup']: {
'code-pushup': {
executor: '@code-pushup/nx-plugin:autorun',
},
},
Expand Down
21 changes: 13 additions & 8 deletions e2e/nx-plugin-e2e/tests/plugin-create-nodes.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,12 @@ describe('nx-plugin', () => {
expect(code).toBe(0);

expect(projectJson.targets).toEqual({
'code-pushup': expect.objectContaining({
executor: 'XYZ:autorun',
options: expect.any(Object),
configurations: expect.any(Object),
'code-pushup--configuration': expect.objectContaining({
executor: 'nx:run-commands',
options: {
command:
'nx g XYZ:configuration --skipTarget --targetName="code-pushup" --project="my-lib"',
},
parallelism: true,
}),
});
Expand Down Expand Up @@ -146,7 +148,7 @@ describe('nx-plugin', () => {
expect(code).toBe(0);

expect(projectJson.targets).toStrictEqual({
['code-pushup']: expect.objectContaining({
'code-pushup': expect.objectContaining({
configurations: {},
executor: `@code-pushup/nx-plugin:autorun`,
options: {},
Expand Down Expand Up @@ -208,9 +210,12 @@ describe('nx-plugin', () => {

expect(code).toBe(0);

expect(projectJson.targets).toStrictEqual({
['code-pushup']: expect.objectContaining({
// FIXME: output has empty configurations object so this passes
expect(projectJson.targets).toEqual({
'code-pushup': expect.objectContaining({
executor: 'XYZ:autorun',
options: expect.any(Object),
configurations: expect.any(Object),
}),
});
});
Expand All @@ -232,7 +237,7 @@ describe('nx-plugin', () => {
expect(code).toBe(0);

expect(projectJson.targets).toStrictEqual({
['code-pushup']: expect.objectContaining({
'code-pushup': expect.objectContaining({
executor: `@code-pushup/nx-plugin:autorun`,
options: {
projectPrefix: 'cli',
Expand Down
8 changes: 4 additions & 4 deletions packages/cli/docs/custom-plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ Execute the CLI with `npx code-pushup collect` and you should the following outp
<summary> <b>stdout of CLI for the above code</b> (collapsed for brevity) </summary>

```sh
Code PushUp Report - @code-pushup/[email protected]
Code PushUp report - @code-pushup/[email protected]

My plugin audits
● My audit 0
Expand Down Expand Up @@ -240,7 +240,7 @@ Now we can execute the CLI with `npx code-pushup collect` and see a similar outp
<summary> <b>stdout of CLI for the above code</b> (collapsed for brevity) </summary>

```sh
Code PushUp Report - @code-pushup/[email protected]
Code PushUp report - @code-pushup/[email protected]

File size plugin audits
● File size audit 2 files
Expand Down Expand Up @@ -371,7 +371,7 @@ Now we can execute the CLI with `npx code-pushup collect --no-progress` and see
<summary> <b>stdout of CLI for the above code</b> (collapsed for brevity) </summary>

```sh
Code PushUp Report - @code-pushup/[email protected]
Code PushUp report - @code-pushup/[email protected]

Chrome Lighthosue audits
● Largest Contentful Paint 0
Expand Down Expand Up @@ -656,7 +656,7 @@ Test the output by running `npx code-pushup collect`.
<summary> <b>stdout of basic lighthouse plugin</b> (collapsed for brevity) </summary>

```sh
Code PushUp Report - @code-pushup/[email protected]
Code PushUp report - @code-pushup/[email protected]

Chrome Lighthouse audits
● Largest Contentful Paint 1,3 s
Expand Down
3 changes: 1 addition & 2 deletions packages/cli/src/lib/yargs-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,8 @@ export function yargsCli<T = unknown>(
// take minimum of TERMINAL_WIDTH or full width of the terminal
.wrap(Math.max(TERMINAL_WIDTH, cli.terminalWidth()))
.help('help', descriptionStyle('Show help'))
.alias('h', 'help')
.showHelpOnFail(false)
.version('version', dim`Show version`, version)
.alias('h', 'help')
.check(args => {
const persist = args['persist'] as PersistConfig | undefined;
return persist == null || validatePersistFormat(persist);
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/lib/implementation/persist.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ describe('persistReport', () => {
});

const mdReport = await readFile(join(MEMFS_VOLUME, 'report.md'), 'utf8');
expect(mdReport).toContain('Code PushUp Report');
expect(mdReport).toContain('Code PushUp report');

await expect(() =>
readFile(join(MEMFS_VOLUME, 'report.json'), 'utf8'),
Expand All @@ -82,7 +82,7 @@ describe('persistReport', () => {
});

const mdReport = await readFile(join(MEMFS_VOLUME, 'report.md'), 'utf8');
expect(mdReport).toContain('Code PushUp Report');
expect(mdReport).toContain('Code PushUp report');
expect(mdReport).toMatch(
/\|\s*🏷 Category\s*\|\s* Score\s*\|\s*🛡 Audits\s*\|/,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ No unsafe any assignment [📖 Docs](https://web.dev/lcp)
`;

exports[`generateMdReport > should render complete md report 1`] = `
"# Code PushUp Report
"# Code PushUp report
| 🏷 Category | ⭐ Score | 🛡 Audits |
| :-------------------------- | :----------: | :-------: |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Code PushUp Report - @code-pushup/[email protected]
Code PushUp report - @code-pushup/[email protected]


ESLint audits
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Code PushUp Report - @code-pushup/[email protected]
Code PushUp report - @code-pushup/[email protected]


ESLint audits
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/src/lib/reports/__snapshots__/report.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Code PushUp Report
# Code PushUp report

| 🏷 Category | ⭐ Score | 🛡 Audits |
| :-------------------------------- | :-------: | :-------: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ describe('generateMdReport', () => {
it('should render all sections of the report', () => {
const md = generateMdReport(baseScoredReport);
// report title
expect(md).toMatch('# Code PushUp Report');
expect(md).toMatch('# Code PushUp report');
// categories section heading
expect(md).toMatch(/\|\s*🏷 Category\s*\|\s* Score\s*\|\s*🛡 Audits\s*\|/);
// categories section heading
Expand All @@ -544,7 +544,7 @@ describe('generateMdReport', () => {
it('should skip categories section if empty', () => {
const md = generateMdReport({ ...baseScoredReport, categories: [] });
expect(md).not.toMatch('## 🏷 Categories');
expect(md).toMatch('# Code PushUp Report\n\n## 🛡️ Audits');
expect(md).toMatch('# Code PushUp report\n\n## 🛡️ Audits');
});

it('should render complete md report', () => {
Expand Down
1 change: 0 additions & 1 deletion testing/test-setup/src/lib/test-folder.setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export async function teardownTestFolder(dirName: string) {
force: true,
// eslint-disable-next-line no-magic-numbers
maxRetries: 3,
// eslint-disable-next-line no-magic-numbers
retryDelay: 100,
});
} catch (error: unknown) {
Expand Down

0 comments on commit cd2ca75

Please sign in to comment.