|
| 1 | +import { it, describe, expect } from 'vitest' |
| 2 | +import { getAdditionalConfigs } from '../utils/renderEslint' |
| 3 | + |
| 4 | +describe('renderEslint', () => { |
| 5 | + it('should get additional dependencies and config with no test flags', () => { |
| 6 | + const additionalConfigs = getAdditionalConfigs({ |
| 7 | + needsVitest: false, |
| 8 | + needsCypress: false, |
| 9 | + needsCypressCT: false, |
| 10 | + needsPlaywright: false |
| 11 | + }) |
| 12 | + expect(additionalConfigs).toStrictEqual([]) |
| 13 | + }) |
| 14 | + |
| 15 | + it('should get additional dependencies and config with for vitest', () => { |
| 16 | + const additionalConfigs = getAdditionalConfigs({ |
| 17 | + needsVitest: true, |
| 18 | + needsCypress: false, |
| 19 | + needsCypressCT: false, |
| 20 | + needsPlaywright: false |
| 21 | + }) |
| 22 | + expect(additionalConfigs).toHaveLength(1) |
| 23 | + const [additionalVitestConfig] = additionalConfigs |
| 24 | + expect(additionalVitestConfig.devDependencies['@vitest/eslint-plugin']).not.toBeUndefined() |
| 25 | + expect(additionalVitestConfig.afterVuePlugin).toHaveLength(1) |
| 26 | + const [additionalVitestPlugin] = additionalVitestConfig.afterVuePlugin! |
| 27 | + expect(additionalVitestPlugin.importer).toBe(`import pluginVitest from '@vitest/eslint-plugin'`) |
| 28 | + expect(additionalVitestPlugin.content).toContain('...pluginVitest.configs.recommended') |
| 29 | + expect(additionalVitestPlugin.content).toContain("files: ['src/**/__tests__/*']") |
| 30 | + }) |
| 31 | + |
| 32 | + it('should get additional dependencies and config with for cypress', () => { |
| 33 | + const additionalConfigs = getAdditionalConfigs({ |
| 34 | + needsVitest: false, |
| 35 | + needsCypress: true, |
| 36 | + needsCypressCT: false, |
| 37 | + needsPlaywright: false |
| 38 | + }) |
| 39 | + expect(additionalConfigs).toHaveLength(1) |
| 40 | + const [additionalCypressConfig] = additionalConfigs |
| 41 | + expect(additionalCypressConfig.devDependencies['eslint-plugin-cypress']).not.toBeUndefined() |
| 42 | + expect(additionalCypressConfig.afterVuePlugin).toHaveLength(1) |
| 43 | + const [additionalCypressPlugin] = additionalCypressConfig.afterVuePlugin! |
| 44 | + expect(additionalCypressPlugin.importer).toBe( |
| 45 | + "import pluginCypress from 'eslint-plugin-cypress/flat'" |
| 46 | + ) |
| 47 | + expect(additionalCypressPlugin.content).toContain('...pluginCypress.configs.recommended') |
| 48 | + expect(additionalCypressPlugin.content).toContain( |
| 49 | + "'cypress/e2e/**/*.{cy,spec}.{js,ts,jsx,tsx}'" |
| 50 | + ) |
| 51 | + expect(additionalCypressPlugin.content).toContain("'cypress/support/**/*.{js,ts,jsx,tsx}'") |
| 52 | + }) |
| 53 | + |
| 54 | + it('should get additional dependencies and config with for cypress with component testing', () => { |
| 55 | + const additionalConfigs = getAdditionalConfigs({ |
| 56 | + needsVitest: false, |
| 57 | + needsCypress: true, |
| 58 | + needsCypressCT: true, |
| 59 | + needsPlaywright: false |
| 60 | + }) |
| 61 | + expect(additionalConfigs).toHaveLength(1) |
| 62 | + const [additionalCypressConfig] = additionalConfigs |
| 63 | + expect(additionalCypressConfig.devDependencies['eslint-plugin-cypress']).not.toBeUndefined() |
| 64 | + expect(additionalCypressConfig.afterVuePlugin).toHaveLength(1) |
| 65 | + const [additionalCypressPlugin] = additionalCypressConfig.afterVuePlugin! |
| 66 | + expect(additionalCypressPlugin.importer).toBe( |
| 67 | + "import pluginCypress from 'eslint-plugin-cypress/flat'" |
| 68 | + ) |
| 69 | + expect(additionalCypressPlugin.content).toContain('...pluginCypress.configs.recommended') |
| 70 | + expect(additionalCypressPlugin.content).toContain("'**/__tests__/*.{cy,spec}.{js,ts,jsx,tsx}'") |
| 71 | + expect(additionalCypressPlugin.content).toContain( |
| 72 | + "'cypress/e2e/**/*.{cy,spec}.{js,ts,jsx,tsx}'" |
| 73 | + ) |
| 74 | + expect(additionalCypressPlugin.content).toContain("'cypress/support/**/*.{js,ts,jsx,tsx}'") |
| 75 | + }) |
| 76 | + |
| 77 | + it('should get additional dependencies and config with for playwright', () => { |
| 78 | + const additionalConfigs = getAdditionalConfigs({ |
| 79 | + needsVitest: false, |
| 80 | + needsCypress: false, |
| 81 | + needsCypressCT: false, |
| 82 | + needsPlaywright: true |
| 83 | + }) |
| 84 | + expect(additionalConfigs).toHaveLength(1) |
| 85 | + const [additionalPlaywrightConfig] = additionalConfigs |
| 86 | + expect( |
| 87 | + additionalPlaywrightConfig.devDependencies['eslint-plugin-playwright'] |
| 88 | + ).not.toBeUndefined() |
| 89 | + expect(additionalPlaywrightConfig.afterVuePlugin).toHaveLength(1) |
| 90 | + const [additionalPlaywrightPlugin] = additionalPlaywrightConfig.afterVuePlugin! |
| 91 | + expect(additionalPlaywrightPlugin.importer).toBe( |
| 92 | + "import pluginPlaywright from 'eslint-plugin-playwright'" |
| 93 | + ) |
| 94 | + expect(additionalPlaywrightPlugin.content).toContain( |
| 95 | + "...pluginPlaywright.configs['flat/recommended']" |
| 96 | + ) |
| 97 | + expect(additionalPlaywrightPlugin.content).toContain( |
| 98 | + "files: ['e2e/**/*.{test,spec}.{js,ts,jsx,tsx}']" |
| 99 | + ) |
| 100 | + }) |
| 101 | +}) |
0 commit comments