diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5444e9c3..97f4f29e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,6 +27,7 @@ jobs: env: CYPRESS_INSTALL_BINARY: 0 - run: pnpm build + - run: pnpm test:unit # Use cache to share the output across different jobs # No need to cache node_modules because they are all bundled diff --git a/__test__/getCommand.spec.ts b/__test__/getCommand.spec.ts new file mode 100644 index 00000000..63c86a99 --- /dev/null +++ b/__test__/getCommand.spec.ts @@ -0,0 +1,20 @@ +import { it, describe, expect } from 'vitest' +import getCommand from '../utils/getCommand' + +describe('getCommand', () => { + it('should generate the correct command for yarn', () => { + expect(getCommand('yarn', 'install')).toBe('yarn') + expect(getCommand('yarn', 'dev')).toBe('yarn dev') + expect(getCommand('yarn', 'build')).toBe('yarn build') + }) + it('should generate the correct command for npm', () => { + expect(getCommand('npm', 'install')).toBe('npm install') + expect(getCommand('npm', 'dev')).toBe('npm run dev') + expect(getCommand('npm', 'build')).toBe('npm run build') + }) + it('should generate the correct command for pnpm', () => { + expect(getCommand('pnpm', 'install')).toBe('pnpm install') + expect(getCommand('pnpm', 'dev')).toBe('pnpm dev') + expect(getCommand('pnpm', 'build')).toBe('pnpm build') + }) +}) diff --git a/__test__/sortDependencies.spec.ts b/__test__/sortDependencies.spec.ts new file mode 100644 index 00000000..29becf4f --- /dev/null +++ b/__test__/sortDependencies.spec.ts @@ -0,0 +1,47 @@ +import { it, describe, expect } from 'vitest' +import sortDependencies from '../utils/sortDependencies' + +describe('sortDependencies', () => { + it('should sort dependencies and dev dependencies', () => { + const packageJson = { + dependencies: { + vue: '^3.3.4', + 'vue-router': '^4.2.5', + pinia: '^2.1.7' + }, + devDependencies: { + '@vitejs/plugin-vue-jsx': '^3.0.2', + jsdom: '^22.1.0', + 'start-server-and-test': '^2.0.1', + vite: '^4.4.11', + '@vue/test-utils': '^2.4.1', + cypress: '^13.3.1', + eslint: '^8.49.0', + '@vitejs/plugin-vue': '^4.4.0', + 'eslint-plugin-cypress': '^2.15.1', + 'eslint-plugin-vue': '^9.17.0', + vitest: '^0.34.6' + } + } + expect(sortDependencies(packageJson)).toStrictEqual({ + dependencies: { + pinia: '^2.1.7', + vue: '^3.3.4', + 'vue-router': '^4.2.5' + }, + devDependencies: { + '@vitejs/plugin-vue': '^4.4.0', + '@vitejs/plugin-vue-jsx': '^3.0.2', + '@vue/test-utils': '^2.4.1', + cypress: '^13.3.1', + eslint: '^8.49.0', + 'eslint-plugin-cypress': '^2.15.1', + 'eslint-plugin-vue': '^9.17.0', + jsdom: '^22.1.0', + 'start-server-and-test': '^2.0.1', + vite: '^4.4.11', + vitest: '^0.34.6' + } + }) + }) +}) diff --git a/package.json b/package.json index 77944b7c..eacecba3 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,7 @@ "snapshot": "zx ./scripts/snapshot.mjs", "pretest": "run-s build snapshot", "test": "zx ./scripts/test.mjs", + "test:unit": "vitest", "prepublishOnly": "zx ./scripts/prepublish.mjs" }, "repository": { @@ -51,6 +52,7 @@ "npm-run-all2": "^6.1.1", "prettier": "^3.1.0", "prompts": "^2.4.2", + "vitest": "^0.34.6", "zx": "^7.2.3" }, "lint-staged": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 6a9d6d97..ca5f384d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -56,6 +56,9 @@ importers: prompts: specifier: ^2.4.2 version: 2.4.2 + vitest: + specifier: ^0.34.6 + version: 0.34.6(jsdom@22.1.0) zx: specifier: ^7.2.3 version: 7.2.3 diff --git a/vitest.config.ts b/vitest.config.ts new file mode 100644 index 00000000..6a1eda40 --- /dev/null +++ b/vitest.config.ts @@ -0,0 +1,7 @@ +import { defineConfig } from 'vitest/config' + +export default defineConfig({ + test: { + include: ['__test__/**.spec.ts'] + } +})