diff --git a/packages/knip/fixtures/plugins/cypress-builtin-reporter/cypress.config.ts b/packages/knip/fixtures/plugins/cypress-builtin-reporter/cypress.config.ts new file mode 100644 index 000000000..114f0257a --- /dev/null +++ b/packages/knip/fixtures/plugins/cypress-builtin-reporter/cypress.config.ts @@ -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, + }, +}); diff --git a/packages/knip/fixtures/plugins/cypress-builtin-reporter/cypress/support/commands.ts b/packages/knip/fixtures/plugins/cypress-builtin-reporter/cypress/support/commands.ts new file mode 100644 index 000000000..6bb5e9b42 --- /dev/null +++ b/packages/knip/fixtures/plugins/cypress-builtin-reporter/cypress/support/commands.ts @@ -0,0 +1,7 @@ +import { faker } from '@faker-js/faker'; + +function login() { + return faker; +} + +Cypress.Commands.add('login', login); diff --git a/packages/knip/fixtures/plugins/cypress-builtin-reporter/cypress/support/e2e.ts b/packages/knip/fixtures/plugins/cypress-builtin-reporter/cypress/support/e2e.ts new file mode 100644 index 000000000..2648ab502 --- /dev/null +++ b/packages/knip/fixtures/plugins/cypress-builtin-reporter/cypress/support/e2e.ts @@ -0,0 +1,2 @@ +import '@testing-library/cypress/add-commands'; +import './commands'; diff --git a/packages/knip/fixtures/plugins/cypress-builtin-reporter/node_modules/@nrwl/cypress/plugins/cypress-preset.js b/packages/knip/fixtures/plugins/cypress-builtin-reporter/node_modules/@nrwl/cypress/plugins/cypress-preset.js new file mode 100644 index 000000000..fe28e5a9e --- /dev/null +++ b/packages/knip/fixtures/plugins/cypress-builtin-reporter/node_modules/@nrwl/cypress/plugins/cypress-preset.js @@ -0,0 +1 @@ +export const nxE2EPreset = (p, c) => ({}); diff --git a/packages/knip/fixtures/plugins/cypress-builtin-reporter/node_modules/cypress/index.js b/packages/knip/fixtures/plugins/cypress-builtin-reporter/node_modules/cypress/index.js new file mode 100644 index 000000000..3ba0c71a6 --- /dev/null +++ b/packages/knip/fixtures/plugins/cypress-builtin-reporter/node_modules/cypress/index.js @@ -0,0 +1 @@ +export const defineConfig = c => c; diff --git a/packages/knip/fixtures/plugins/cypress-builtin-reporter/node_modules/cypress/package.json b/packages/knip/fixtures/plugins/cypress-builtin-reporter/node_modules/cypress/package.json new file mode 100644 index 000000000..7dcf54370 --- /dev/null +++ b/packages/knip/fixtures/plugins/cypress-builtin-reporter/node_modules/cypress/package.json @@ -0,0 +1,3 @@ +{ + "name": "cypress" +} diff --git a/packages/knip/fixtures/plugins/cypress-builtin-reporter/package.json b/packages/knip/fixtures/plugins/cypress-builtin-reporter/package.json new file mode 100644 index 000000000..04c572a7e --- /dev/null +++ b/packages/knip/fixtures/plugins/cypress-builtin-reporter/package.json @@ -0,0 +1,9 @@ +{ + "name": "@fixtures/cypress-builtin-reporter", + "devDependencies": { + "cypress": "*", + "cypress-multi-reporters": "*", + "mocha-junit-reporter": "*", + "mochawesome": "*" + } +} diff --git a/packages/knip/fixtures/plugins/cypress-builtin-reporter/reporter-config.json b/packages/knip/fixtures/plugins/cypress-builtin-reporter/reporter-config.json new file mode 100644 index 000000000..5b77b2335 --- /dev/null +++ b/packages/knip/fixtures/plugins/cypress-builtin-reporter/reporter-config.json @@ -0,0 +1,4 @@ +{ + "reporterEnabled": "mochawesome, mocha-junit-reporter , @testing-library/my-fake-reporter" +} + \ No newline at end of file diff --git a/packages/knip/src/plugins/cypress/helpers.ts b/packages/knip/src/plugins/cypress/helpers.ts index 10b8598b5..79e2950b6 100644 --- a/packages/knip/src/plugins/cypress/helpers.ts +++ b/packages/knip/src/plugins/cypress/helpers.ts @@ -7,6 +7,10 @@ interface ReporterConfig { reporterEnabled: string; } +// see https://docs.cypress.io/guides/tooling/reporters +const BUILT_IN_REPORTERS: ReadonlyArray = ['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; @@ -33,5 +37,5 @@ export const resolveDependencies = async (config: CypressConfig, options: Plugin } } } - return [...reporters]; + return [...reporters].filter(IS_NOT_BUILT_IN_REPORTER); }; diff --git a/packages/knip/test/plugins/cypress-builtin-reporter.test.ts b/packages/knip/test/plugins/cypress-builtin-reporter.test.ts new file mode 100644 index 000000000..b5b16385c --- /dev/null +++ b/packages/knip/test/plugins/cypress-builtin-reporter.test.ts @@ -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']); +});