Skip to content

Commit

Permalink
webpro-nl#798 exclude built-in cypress reporters from dependency check
Browse files Browse the repository at this point in the history
  • Loading branch information
duncan-thacker committed Oct 4, 2024
1 parent 69c021b commit 49ab5ce
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { nxE2EPreset } from '@nrwl/cypress/plugins/cypress-preset';
import { defineConfig } from 'cypress';

const cypressJsonConfig = {};

export default defineConfig({
reporter: "junit",
e2e: {
...nxE2EPreset(__dirname, {}),
...cypressJsonConfig,
},
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { faker } from '@faker-js/faker';

function login() {
return faker;
}

Cypress.Commands.add('login', login);
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import '@testing-library/cypress/add-commands';
import './commands';

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "@fixtures/cypress",
"devDependencies": {
"cypress": "*",
"cypress-multi-reporters": "*",
"mocha-junit-reporter": "*",
"mochawesome": "*"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"reporterEnabled": "mochawesome, mocha-junit-reporter , @testing-library/my-fake-reporter"
}

6 changes: 5 additions & 1 deletion packages/knip/src/plugins/cypress/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ interface ReporterConfig {
reporterEnabled: string;
}

// see https://docs.cypress.io/guides/tooling/reporters
const BUILT_IN_REPORTERS: ReadonlyArray<string> = ['spec', 'junit', 'teamcity'] as const;
const IS_NOT_BUILT_IN_REPORTER = (reporter: string) => !BUILT_IN_REPORTERS.includes(reporter);

export const resolveDependencies = async (config: CypressConfig, options: PluginOptions) => {
const { reporter } = config;
const { configFileDir } = options;
Expand All @@ -33,5 +37,5 @@ export const resolveDependencies = async (config: CypressConfig, options: Plugin
}
}
}
return [...reporters];
return [...reporters].filter(IS_NOT_BUILT_IN_REPORTER);
};
16 changes: 16 additions & 0 deletions packages/knip/test/plugins/cypress-builtin-reporter.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { test } from 'bun:test';
import assert from 'node:assert/strict';
import { main } from '../../src/index.js';
import { resolve } from '../../src/util/path.js';
import baseArguments from '../helpers/baseArguments.js';

const cwd = resolve('fixtures/plugins/cypress-multi-reporter');

test('Exclude built-in cypress reporters from dependency checks', async () => {
const { issues, counters } = await main({
...baseArguments,
cwd,
});

assert(!issues.unlisted['cypress.config.ts']['junit']);
});

0 comments on commit 49ab5ce

Please sign in to comment.