diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8b0a7b8..ff1ef2b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -74,3 +74,4 @@ jobs: -Dsonar.projectVersion=${{ steps.package.outputs.version }} -Dsonar.javascript.lcov.reportPaths=coverage/lcov.info -Dsonar.coverage.exclusions=**/*.test.ts + -sonar.cpd.exclusions=**/*.test.ts diff --git a/src/alias/sa.test.ts b/src/alias/sa.test.ts index f7fb9c1..7ae75db 100644 --- a/src/alias/sa.test.ts +++ b/src/alias/sa.test.ts @@ -1,14 +1,9 @@ import { it, expect, describe } from 'vitest' import { testCommandResult } from '../../.vitest/helpers' +import { addCases } from '../cli/swpm/commands/add.test' describe('sa', () => { - it.each([ - ['npm', 'npm add vite'], - ['yarn', 'yarn add vite'], - ['yarn@berry', 'yarn add vite'], - ['pnpm', 'pnpm add vite'], - ['bun', 'bun add vite'] - ])('%s', (pkg, expected) => { + it.each(addCases)('%s', (pkg, expected) => { const result = testCommandResult(`sa vite --test ${pkg}`) expect(result).toBe(expected) }) diff --git a/src/alias/sad.test.ts b/src/alias/sad.test.ts index cb2a732..5d31fdc 100644 --- a/src/alias/sad.test.ts +++ b/src/alias/sad.test.ts @@ -1,14 +1,9 @@ import { it, expect, describe } from 'vitest' import { testCommandResult } from '../../.vitest/helpers' +import { addDevCases } from '../cli/swpm/commands/add.test' describe('sad', () => { - it.each([ - ['npm', 'npm add vite --save-dev'], - ['yarn', 'yarn add vite --dev'], - ['yarn@berry', 'yarn add vite --dev'], - ['pnpm', 'pnpm add vite --save-dev'], - ['bun', 'bun add vite --dev'] - ])('%s', (pkg, expected) => { + it.each(addDevCases)('%s', (pkg, expected) => { const result = testCommandResult(`sad vite --test ${pkg}`) expect(result).toBe(expected) }) diff --git a/src/alias/sae.test.ts b/src/alias/sae.test.ts index d4a0705..cd6dcb5 100644 --- a/src/alias/sae.test.ts +++ b/src/alias/sae.test.ts @@ -1,14 +1,9 @@ import { it, expect, describe } from 'vitest' import { testCommandResult } from '../../.vitest/helpers' +import { addSaveExact } from '../cli/swpm/commands/add.test' describe('sae', () => { - it.each([ - ['npm', 'npm add vite --save-exact'], - ['yarn', 'yarn add vite --exact'], - ['yarn@berry', 'yarn add vite --exact'], - ['pnpm', 'pnpm add vite --save-exact'], - ['bun', 'bun add vite --exact'] - ])('%s', (pkg, expected) => { + it.each(addSaveExact)('%s', (pkg, expected) => { const result = testCommandResult(`sae vite --test ${pkg}`) expect(result).toBe(expected) }) diff --git a/src/alias/sag.test.ts b/src/alias/sag.test.ts index bdb15ec..2f29761 100644 --- a/src/alias/sag.test.ts +++ b/src/alias/sag.test.ts @@ -1,26 +1,11 @@ import { it, expect, describe } from 'vitest' import { testCommandResult } from '../../.vitest/helpers' +import { addPackageCases, addVoltaCases } from '../cli/swpm/commands/add.test' describe('sag', () => { - const voltaCases = [ - ['npm', 'volta install vite'], - ['yarn', 'volta install vite'], - ['yarn@berry', 'volta install vite'], - ['pnpm', 'volta install vite'], - ['bun', 'volta install vite'] - ] - - const packageCases = [ - ['npm', 'npm add vite --location=global'], - ['yarn', 'yarn global add vite'], - ['yarn@berry', 'yarn global add vite'], - ['pnpm', 'pnpm add vite --global'], - ['bun', 'bun add vite --global'] - ] - const voltaVersion = testCommandResult('volta --version') - it.each(voltaVersion ? voltaCases : packageCases)('%s', (pkg, expected) => { + it.each(voltaVersion ? addVoltaCases : addPackageCases)('%s', (pkg, expected) => { const result = testCommandResult(`sag vite --test ${pkg}`) expect(result).toBe(expected) }) diff --git a/src/alias/si.test.ts b/src/alias/si.test.ts index ffbf14c..9630ea1 100644 --- a/src/alias/si.test.ts +++ b/src/alias/si.test.ts @@ -1,40 +1,23 @@ import { it, expect, describe } from 'vitest' import { testCommandResult } from '../../.vitest/helpers' +import { installCases, installFrozenCases, installLockCases } from '../cli/swpm/commands/install.test' describe('si', () => { - it.each([ - ['npm', 'npm install'], - ['yarn', 'yarn install'], - ['yarn@berry', 'yarn install'], - ['pnpm', 'pnpm install'], - ['bun', 'bun install'] - ])('%s', (pkg, expected) => { + it.each(installCases)('%s', (pkg, expected) => { const result = testCommandResult(`si --test ${pkg}`) expect(result).toBe(expected) }) }) describe('si --frozen', () => { - it.each([ - ['npm', 'npm ci'], - ['yarn', 'yarn install --frozen-lockfile'], - ['yarn@berry', 'yarn install --immutable'], - ['pnpm', 'pnpm install --frozen-lockfile'], - ['bun', 'bun install --frozen-lockfile'] - ])('%s', (pkg, expected) => { + it.each(installFrozenCases)('%s', (pkg, expected) => { const result = testCommandResult(`si --frozen --test ${pkg}`) expect(result).toBe(expected) }) }) describe('si --package-lock', () => { - it.each([ - ['npm', 'npm install --no-package-lock'], - ['yarn', 'yarn install --no-lockfile'], - ['yarn@berry', 'yarn install --no-lockfile'], - ['pnpm', ''], // not available - ['bun', 'bun install --no-save'] - ])('%s', (pkg, expected) => { + it.each(installLockCases)('%s', (pkg, expected) => { const result = testCommandResult(`si --package-lock --test ${pkg}`) expect(result).toBe(expected) }) diff --git a/src/alias/sif.test.ts b/src/alias/sif.test.ts index ef33095..b70e468 100644 --- a/src/alias/sif.test.ts +++ b/src/alias/sif.test.ts @@ -1,14 +1,9 @@ import { it, expect, describe } from 'vitest' import { testCommandResult } from '../../.vitest/helpers' +import { installFrozenCases } from '../cli/swpm/commands/install.test' describe('sif', () => { - it.each([ - ['npm', 'npm ci'], - ['yarn', 'yarn install --frozen-lockfile'], - ['yarn@berry', 'yarn install --immutable'], - ['pnpm', 'pnpm install --frozen-lockfile'], - ['bun', 'bun install --frozen-lockfile'] - ])('%s', (pkg, expected) => { + it.each(installFrozenCases)('%s', (pkg, expected) => { const result = testCommandResult(`sif --test ${pkg}`) expect(result).toBe(expected) }) diff --git a/src/alias/sr.test.ts b/src/alias/sr.test.ts index 560f5e9..aec675a 100644 --- a/src/alias/sr.test.ts +++ b/src/alias/sr.test.ts @@ -1,7 +1,7 @@ import { it, expect, describe } from 'vitest' import { testCommandResult } from '../../.vitest/helpers' -describe('sif', () => { +describe('sr', () => { it.each([ ['npm', 'npm run dev -- --port 3030'], ['yarn', 'yarn run dev --port 3030'], diff --git a/src/alias/srg.test.ts b/src/alias/srg.test.ts index d1f8e4b..6959b4f 100644 --- a/src/alias/srg.test.ts +++ b/src/alias/srg.test.ts @@ -1,14 +1,9 @@ import { it, expect, describe } from 'vitest' import { testCommandResult } from '../../.vitest/helpers' +import { removeGlobalCases } from '../cli/swpm/commands/remove.test' describe('srg', () => { - it.each([ - ['npm', 'npm uninstall vite --location=global'], - ['yarn', 'yarn global remove vite'], - ['yarn@berry', 'yarn global remove vite'], - ['pnpm', 'pnpm uninstall vite --global'], - ['bun', 'bun remove vite --global'] - ])('%s', (pkg, expected) => { + it.each(removeGlobalCases)('%s', (pkg, expected) => { const result = testCommandResult(`srg vite --test ${pkg}`) expect(result).toBe(expected) }) diff --git a/src/alias/srm.test.ts b/src/alias/srm.test.ts index d42e350..712f551 100644 --- a/src/alias/srm.test.ts +++ b/src/alias/srm.test.ts @@ -1,14 +1,9 @@ import { it, expect, describe } from 'vitest' import { testCommandResult } from '../../.vitest/helpers' +import { removeCases } from '../cli/swpm/commands/remove.test' describe('srm', () => { - it.each([ - ['npm', 'npm uninstall vite'], - ['yarn', 'yarn remove vite'], - ['yarn@berry', 'yarn remove vite'], - ['pnpm', 'pnpm uninstall vite'], - ['bun', 'bun remove vite'] - ])('%s', (pkg, expected) => { + it.each(removeCases)('%s', (pkg, expected) => { const result = testCommandResult(`srm vite --test ${pkg}`) expect(result).toBe(expected) }) diff --git a/src/alias/sug.test.ts b/src/alias/sug.test.ts index 14abc23..af74668 100644 --- a/src/alias/sug.test.ts +++ b/src/alias/sug.test.ts @@ -1,14 +1,9 @@ import { it, expect, describe } from 'vitest' import { testCommandResult } from '../../.vitest/helpers' +import { upgradeCases } from '../cli/swpm/commands/upgrade.test' describe('sug', () => { - it.each([ - ['npm', 'npm add vite@latest'], - ['yarn', 'yarn upgrade vite --latest'], - ['yarn@berry', 'yarn up vite'], - ['pnpm', 'pnpm update vite --latest'], - ['bun', ''] - ])('%s', (pkg, expected) => { + it.each(upgradeCases)('%s', (pkg, expected) => { const result = testCommandResult(`sug vite --test ${pkg}`) expect(result).toBe(expected) }) diff --git a/src/alias/sui.test.ts b/src/alias/sui.test.ts index 13e6231..5f0af43 100644 --- a/src/alias/sui.test.ts +++ b/src/alias/sui.test.ts @@ -1,14 +1,9 @@ import { it, expect, describe } from 'vitest' import { testCommandResult } from '../../.vitest/helpers' +import { interactiveCases } from '../cli/swpm/commands/interactive.test' describe('sui', () => { - it.each([ - ['npm', ''], - ['yarn', 'yarn upgrade-interactive'], - ['yarn@berry', 'yarn upgrade-interactive'], - ['pnpm', 'pnpm upgrade --interactive'], - ['bun', ''] - ])('%s', (pkg, expected) => { + it.each(interactiveCases)('%s', (pkg, expected) => { const result = testCommandResult(`sui --test ${pkg}`) expect(result).toBe(expected) }) diff --git a/src/alias/sup.test.ts b/src/alias/sup.test.ts index 1b897cc..a181a3f 100644 --- a/src/alias/sup.test.ts +++ b/src/alias/sup.test.ts @@ -1,14 +1,9 @@ import { it, expect, describe } from 'vitest' import { testCommandResult } from '../../.vitest/helpers' +import { updateCases } from '../cli/swpm/commands/update.test' describe('sup', () => { - it.each([ - ['npm', 'npm update vite'], - ['yarn', 'yarn upgrade vite'], - ['yarn@berry', 'yarn semver up vite'], - ['pnpm', 'pnpm update vite'], - ['bun', 'bun update vite'] - ])('%s', (pkg, expected) => { + it.each(updateCases)('%s', (pkg, expected) => { const result = testCommandResult(`sup vite --test ${pkg}`) expect(result).toBe(expected) }) diff --git a/src/cli/swpm/commands/add.test.ts b/src/cli/swpm/commands/add.test.ts index 8227937..1f09ced 100644 --- a/src/cli/swpm/commands/add.test.ts +++ b/src/cli/swpm/commands/add.test.ts @@ -1,27 +1,31 @@ import { it, expect, describe } from 'vitest' import { testCommandResult } from '../../../../.vitest/helpers' +export const addCases = [ + ['npm', 'npm add vite'], + ['yarn', 'yarn add vite'], + ['yarn@berry', 'yarn add vite'], + ['pnpm', 'pnpm add vite'], + ['bun', 'bun add vite'] +] + describe('add', () => { - it.each([ - ['npm', 'npm add vite'], - ['yarn', 'yarn add vite'], - ['yarn@berry', 'yarn add vite'], - ['pnpm', 'pnpm add vite'], - ['bun', 'bun add vite'] - ])('%s', (pkg, expected) => { + it.each(addCases)('%s', (pkg, expected) => { const result = testCommandResult(`swpm add vite --test ${pkg}`) expect(result).toBe(expected) }) }) +export const addDevCases = [ + ['npm', 'npm add vite --save-dev'], + ['yarn', 'yarn add vite --dev'], + ['yarn@berry', 'yarn add vite --dev'], + ['pnpm', 'pnpm add vite --save-dev'], + ['bun', 'bun add vite --dev'] +] + describe('add --save-dev', () => { - it.each([ - ['npm', 'npm add vite --save-dev'], - ['yarn', 'yarn add vite --dev'], - ['yarn@berry', 'yarn add vite --dev'], - ['pnpm', 'pnpm add vite --save-dev'], - ['bun', 'bun add vite --dev'] - ])('%s', (pkg, expected) => { + it.each(addDevCases)('%s', (pkg, expected) => { const result = testCommandResult(`swpm add vite --save-dev --test ${pkg}`) expect(result).toBe(expected) }) @@ -53,39 +57,41 @@ describe('add --save-peer', () => { }) }) +export const addSaveExact = [ + ['npm', 'npm add vite --save-exact'], + ['yarn', 'yarn add vite --exact'], + ['yarn@berry', 'yarn add vite --exact'], + ['pnpm', 'pnpm add vite --save-exact'], + ['bun', 'bun add vite --exact'] +] + describe('add --save-exact', () => { - it.each([ - ['npm', 'npm add vite --save-exact'], - ['yarn', 'yarn add vite --exact'], - ['yarn@berry', 'yarn add vite --exact'], - ['pnpm', 'pnpm add vite --save-exact'], - ['bun', 'bun add vite --exact'] - ])('%s', (pkg, expected) => { + it.each(addSaveExact)('%s', (pkg, expected) => { const result = testCommandResult(`swpm add vite --save-exact --test ${pkg}`) expect(result).toBe(expected) }) }) -describe('add --global', () => { - const voltaCases = [ - ['npm', 'volta install vite'], - ['yarn', 'volta install vite'], - ['yarn@berry', 'volta install vite'], - ['pnpm', 'volta install vite'], - ['bun', 'volta install vite'] - ] +export const addVoltaCases = [ + ['npm', 'volta install vite'], + ['yarn', 'volta install vite'], + ['yarn@berry', 'volta install vite'], + ['pnpm', 'volta install vite'], + ['bun', 'volta install vite'] +] - const packageCases = [ - ['npm', 'npm add vite --location=global'], - ['yarn', 'yarn global add vite'], - ['yarn@berry', 'yarn global add vite'], - ['pnpm', 'pnpm add vite --global'], - ['bun', 'bun add vite --global'] - ] +export const addPackageCases = [ + ['npm', 'npm add vite --location=global'], + ['yarn', 'yarn global add vite'], + ['yarn@berry', 'yarn global add vite'], + ['pnpm', 'pnpm add vite --global'], + ['bun', 'bun add vite --global'] +] +describe('add --global', () => { const voltaVersion = testCommandResult('volta --version') - it.each(voltaVersion ? voltaCases : packageCases)('%s', (pkg, expected) => { + it.each(voltaVersion ? addVoltaCases : addPackageCases)('%s', (pkg, expected) => { const result = testCommandResult(`swpm add vite --global --test ${pkg}`) expect(result).toBe(expected) }) diff --git a/src/cli/swpm/commands/install.test.ts b/src/cli/swpm/commands/install.test.ts index 4f4ad02..a074606 100644 --- a/src/cli/swpm/commands/install.test.ts +++ b/src/cli/swpm/commands/install.test.ts @@ -1,40 +1,46 @@ import { it, expect, describe } from 'vitest' import { testCommandResult } from '../../../../.vitest/helpers' +export const installCases = [ + ['npm', 'npm install'], + ['yarn', 'yarn install'], + ['yarn@berry', 'yarn install'], + ['pnpm', 'pnpm install'], + ['bun', 'bun install'] +] + describe('install', () => { - it.each([ - ['npm', 'npm install'], - ['yarn', 'yarn install'], - ['yarn@berry', 'yarn install'], - ['pnpm', 'pnpm install'], - ['bun', 'bun install'] - ])('%s', (pkg, expected) => { + it.each(installCases)('%s', (pkg, expected) => { const result = testCommandResult(`swpm install --test ${pkg}`) expect(result).toBe(expected) }) }) +export const installFrozenCases = [ + ['npm', 'npm ci'], + ['yarn', 'yarn install --frozen-lockfile'], + ['yarn@berry', 'yarn install --immutable'], + ['pnpm', 'pnpm install --frozen-lockfile'], + ['bun', 'bun install --frozen-lockfile'] +] + describe('install --frozen', () => { - it.each([ - ['npm', 'npm ci'], - ['yarn', 'yarn install --frozen-lockfile'], - ['yarn@berry', 'yarn install --immutable'], - ['pnpm', 'pnpm install --frozen-lockfile'], - ['bun', 'bun install --frozen-lockfile'] - ])('%s', (pkg, expected) => { + it.each(installFrozenCases)('%s', (pkg, expected) => { const result = testCommandResult(`swpm install --frozen --test ${pkg}`) expect(result).toBe(expected) }) }) +export const installLockCases = [ + ['npm', 'npm install --no-package-lock'], + ['yarn', 'yarn install --no-lockfile'], + ['yarn@berry', 'yarn install --no-lockfile'], + ['pnpm', ''], // not available + ['bun', 'bun install --no-save'] +] + describe('install --package-lock', () => { - it.each([ - ['npm', 'npm install --no-package-lock'], - ['yarn', 'yarn install --no-lockfile'], - ['yarn@berry', 'yarn install --no-lockfile'], - ['pnpm', ''], // not available - ['bun', 'bun install --no-save'] - ])('%s', (pkg, expected) => { + it.each(installLockCases)('%s', (pkg, expected) => { const result = testCommandResult(`swpm install --package-lock --test ${pkg}`) expect(result).toBe(expected) }) diff --git a/src/cli/swpm/commands/interactive.test.ts b/src/cli/swpm/commands/interactive.test.ts index f4d1778..b74f256 100644 --- a/src/cli/swpm/commands/interactive.test.ts +++ b/src/cli/swpm/commands/interactive.test.ts @@ -1,14 +1,16 @@ import { it, expect, describe } from 'vitest' import { testCommandResult } from '../../../../.vitest/helpers' +export const interactiveCases = [ + ['npm', ''], + ['yarn', 'yarn upgrade-interactive'], + ['yarn@berry', 'yarn upgrade-interactive'], + ['pnpm', 'pnpm upgrade --interactive'], + ['bun', ''] +] + describe('interactive', () => { - it.each([ - ['npm', ''], - ['yarn', 'yarn upgrade-interactive'], - ['yarn@berry', 'yarn upgrade-interactive'], - ['pnpm', 'pnpm upgrade --interactive'], - ['bun', ''] - ])('%s', (pkg, expected) => { + it.each(interactiveCases)('%s', (pkg, expected) => { const result = testCommandResult(`swpm interactive --test ${pkg}`) expect(result).toBe(expected) }) diff --git a/src/cli/swpm/commands/remove.test.ts b/src/cli/swpm/commands/remove.test.ts index a01f7e0..5b6ade3 100644 --- a/src/cli/swpm/commands/remove.test.ts +++ b/src/cli/swpm/commands/remove.test.ts @@ -1,14 +1,16 @@ import { it, expect, describe } from 'vitest' import { testCommandResult } from '../../../../.vitest/helpers' +export const removeCases = [ + ['npm', 'npm uninstall vite'], + ['yarn', 'yarn remove vite'], + ['yarn@berry', 'yarn remove vite'], + ['pnpm', 'pnpm uninstall vite'], + ['bun', 'bun remove vite'] +] + describe('remove', () => { - it.each([ - ['npm', 'npm uninstall vite'], - ['yarn', 'yarn remove vite'], - ['yarn@berry', 'yarn remove vite'], - ['pnpm', 'pnpm uninstall vite'], - ['bun', 'bun remove vite'] - ])('%s', (pkg, expected) => { + it.each(removeCases)('%s', (pkg, expected) => { const result = testCommandResult(`swpm remove vite --test ${pkg}`) expect(result).toBe(expected) }) @@ -53,14 +55,16 @@ describe('remove --save-peer', () => { }) }) +export const removeGlobalCases = [ + ['npm', 'npm uninstall vite --location=global'], + ['yarn', 'yarn global remove vite'], + ['yarn@berry', 'yarn global remove vite'], + ['pnpm', 'pnpm uninstall vite --global'], + ['bun', 'bun remove vite --global'] +] + describe('remove --global', () => { - it.each([ - ['npm', 'npm uninstall vite --location=global'], - ['yarn', 'yarn global remove vite'], - ['yarn@berry', 'yarn global remove vite'], - ['pnpm', 'pnpm uninstall vite --global'], - ['bun', 'bun remove vite --global'] - ])('%s', (pkg, expected) => { + it.each(removeGlobalCases)('%s', (pkg, expected) => { const result = testCommandResult(`swpm remove vite --global --test ${pkg}`) expect(result).toBe(expected) }) diff --git a/src/cli/swpm/commands/update.test.ts b/src/cli/swpm/commands/update.test.ts index 48f4bc6..37b9e46 100644 --- a/src/cli/swpm/commands/update.test.ts +++ b/src/cli/swpm/commands/update.test.ts @@ -1,14 +1,16 @@ import { it, expect, describe } from 'vitest' import { testCommandResult } from '../../../../.vitest/helpers' +export const updateCases = [ + ['npm', 'npm update vite'], + ['yarn', 'yarn upgrade vite'], + ['yarn@berry', 'yarn semver up vite'], + ['pnpm', 'pnpm update vite'], + ['bun', 'bun update vite'] +] + describe('update', () => { - it.each([ - ['npm', 'npm update vite'], - ['yarn', 'yarn upgrade vite'], - ['yarn@berry', 'yarn semver up vite'], - ['pnpm', 'pnpm update vite'], - ['bun', 'bun update vite'] - ])('%s', (pkg, expected) => { + it.each(updateCases)('%s', (pkg, expected) => { const result = testCommandResult(`swpm update vite --test ${pkg}`) expect(result).toBe(expected) }) diff --git a/src/cli/swpm/commands/upgrade.test.ts b/src/cli/swpm/commands/upgrade.test.ts index 36b11c8..1783aed 100644 --- a/src/cli/swpm/commands/upgrade.test.ts +++ b/src/cli/swpm/commands/upgrade.test.ts @@ -1,14 +1,16 @@ import { it, expect, describe } from 'vitest' import { testCommandResult } from '../../../../.vitest/helpers' +export const upgradeCases = [ + ['npm', 'npm add vite@latest'], + ['yarn', 'yarn upgrade vite --latest'], + ['yarn@berry', 'yarn up vite'], + ['pnpm', 'pnpm update vite --latest'], + ['bun', ''] +] + describe('upgrade', () => { - it.each([ - ['npm', 'npm add vite@latest'], - ['yarn', 'yarn upgrade vite --latest'], - ['yarn@berry', 'yarn up vite'], - ['pnpm', 'pnpm update vite --latest'], - ['bun', ''] - ])('%s', (pkg, expected) => { + it.each(upgradeCases)('%s', (pkg, expected) => { const result = testCommandResult(`swpm upgrade vite --test ${pkg}`) expect(result).toBe(expected) })