Skip to content

Commit

Permalink
Merge pull request #461 from dcastil/other/switch-test-suite-to-vitest
Browse files Browse the repository at this point in the history
Switch test suite to vitest
  • Loading branch information
dcastil authored Aug 18, 2024
2 parents 1bed05d + d4ef3ac commit 0c74ac3
Show file tree
Hide file tree
Showing 47 changed files with 403 additions and 1,892 deletions.
8 changes: 5 additions & 3 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,13 @@
},
"overrides": [
{
"files": ["tests/**/*.ts"],
"extends": ["plugin:jest/recommended", "plugin:jest/style"]
"files": ["./*.config.?(m|c)@(t|j)s", "./scripts/**/*.config.?(m|c)@(t|j)s"],
"rules": {
"import/no-default-export": "off"
}
},
{
"files": ["scripts/**/*.?(m|c)js"],
"files": ["scripts/**/*.?(m|c)@(t|j)s"],
"rules": {
"no-console": "off"
}
Expand Down
31 changes: 0 additions & 31 deletions .github/workflows/benchmarks.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
yarn-node-20-lock-
- run: yarn install --frozen-lockfile
- run: yarn lint
- run: yarn test --ci --coverage --maxWorkers=2
- run: yarn test
- run: yarn build
- uses: actions/upload-artifact@v4
with:
Expand Down
23 changes: 22 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,32 @@ jobs:
yarn-node-20-lock-
- run: yarn install --frozen-lockfile
- run: yarn lint
- run: yarn test --ci --coverage --maxWorkers=2
- run: yarn test
- run: yarn build
- uses: actions/upload-artifact@v4
with:
name: build-output
path: dist
if-no-files-found: error
- run: yarn test:exports
benchmark:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Use Node.js 20
uses: actions/setup-node@v4
with:
node-version: 20.11.1
- name: Use node_modules cache
uses: actions/cache@v4
with:
path: node_modules
key: yarn-node-20-lock-${{ hashFiles('yarn.lock') }}
restore-keys: |
yarn-node-20-lock-
- run: yarn install --frozen-lockfile
- name: Run benchmark
uses: CodSpeedHQ/action@v3
with:
token: ${{ secrets.CODSPEED_TOKEN }}
run: yarn bench
65 changes: 0 additions & 65 deletions benchmarks/twMerge.bench.ts

This file was deleted.

11 changes: 4 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@
"sideEffects": false,
"scripts": {
"build": "rollup --config scripts/rollup.config.mjs",
"bench": "vitest bench --run",
"test": "jest test --config scripts/jest.config.mjs --coverage",
"test:watch": "jest test --config scripts/jest.config.mjs --watch",
"bench": "vitest bench --config scripts/vitest.config.mts",
"test": "vitest --config scripts/vitest.config.mts --coverage",
"test:watch": "vitest --config scripts/vitest.config.mts",
"test:exports": "node scripts/test-built-package-exports.cjs && node scripts/test-built-package-exports.mjs",
"lint": "eslint --max-warnings 0 '**'",
"preversion": "if [ -n \"$DANYS_MACHINE\" ]; then git checkout main && git pull; fi",
Expand All @@ -68,21 +68,18 @@
"@rollup/plugin-babel": "^6.0.4",
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-typescript": "^11.1.6",
"@types/jest": "^29.5.12",
"@typescript-eslint/eslint-plugin": "^8.0.1",
"@typescript-eslint/parser": "^8.0.1",
"@vitest/coverage-v8": "^2.0.5",
"babel-plugin-annotate-pure-calls": "^0.4.0",
"babel-plugin-polyfill-regenerator": "^0.6.2",
"eslint": "^8.57.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-jest": "^28.6.0",
"globby": "^11.1.0",
"jest": "^29.7.0",
"prettier": "^3.3.3",
"rollup": "^4.19.1",
"rollup-plugin-delete": "^2.0.0",
"rollup-plugin-dts": "^6.1.1",
"ts-jest": "^29.2.3",
"tslib": "^2.6.3",
"typescript": "^5.5.4",
"vitest": "^2.0.5",
Expand Down
7 changes: 0 additions & 7 deletions scripts/jest.config.mjs

This file was deleted.

1 change: 0 additions & 1 deletion scripts/rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { dts } from 'rollup-plugin-dts'

import pkg from '../package.json' assert { type: 'json' }

// eslint-disable-next-line import/no-default-export
export default defineConfig([
// Default entry point
{
Expand Down
14 changes: 14 additions & 0 deletions scripts/vitest.config.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/// <reference types="vitest" />

import codspeedPlugin from '@codspeed/vitest-plugin'
import { defineConfig } from 'vitest/config'

export default defineConfig({
// When Codspeed plugin is enabled, benchmark results don't get logged. More info: https://github.com/CodSpeedHQ/codspeed-node/issues/36
plugins: process.env.CI ? [codspeedPlugin()] : undefined,
test: {
coverage: {
include: ['src/**/*.ts'],
},
},
})
2 changes: 2 additions & 0 deletions tests/arbitrary-properties.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { expect, test } from 'vitest'

import { twMerge } from '../src'

test('handles arbitrary property conflicts correctly', () => {
Expand Down
2 changes: 2 additions & 0 deletions tests/arbitrary-values.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { expect, test } from 'vitest'

import { twMerge } from '../src'

test('handles simple conflicts with arbitrary values correctly', () => {
Expand Down
2 changes: 2 additions & 0 deletions tests/arbitrary-variants.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { expect, test } from 'vitest'

import { twMerge } from '../src'

test('basic arbitrary variants', () => {
Expand Down
2 changes: 2 additions & 0 deletions tests/class-group-conflicts.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { expect, test } from 'vitest'

import { twMerge } from '../src'

test('merges classes from same group correctly', () => {
Expand Down
2 changes: 2 additions & 0 deletions tests/class-map.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { expect, test } from 'vitest'

import { getDefaultConfig } from '../src'
import { ClassPartObject, createClassMap } from '../src/lib/class-group-utils'

Expand Down
2 changes: 2 additions & 0 deletions tests/colors.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { expect, test } from 'vitest'

import { twMerge } from '../src'

test('handles color conflicts properly', () => {
Expand Down
2 changes: 2 additions & 0 deletions tests/conflicts-across-class-groups.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { expect, test } from 'vitest'

import { twMerge } from '../src'

test('handles conflicts across class groups correctly', () => {
Expand Down
2 changes: 2 additions & 0 deletions tests/content-utilities.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { expect, test } from 'vitest'

import { twMerge } from '../src'

test('merges content utilities correctly', () => {
Expand Down
2 changes: 2 additions & 0 deletions tests/create-tailwind-merge.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { expect, test } from 'vitest'

import { createTailwindMerge } from '../src'

test('createTailwindMerge works with single config function', () => {
Expand Down
2 changes: 2 additions & 0 deletions tests/default-config.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { expect, test } from 'vitest'

import { getDefaultConfig } from '../src'
import { Config, DefaultClassGroupIds, DefaultThemeGroupIds } from '../src/lib/types'

Expand Down
1 change: 1 addition & 0 deletions tests/docs-examples.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import fs from 'fs'

import globby from 'globby'
import { expect, test } from 'vitest'

import { twMerge } from '../src'

Expand Down
2 changes: 2 additions & 0 deletions tests/experimental-parse-class-name.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { expect, test } from 'vitest'

import { extendTailwindMerge } from '../src'

test('default case', () => {
Expand Down
2 changes: 2 additions & 0 deletions tests/extend-tailwind-merge.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { expect, test } from 'vitest'

import { extendTailwindMerge } from '../src'

test('extendTailwindMerge works correctly with single config', () => {
Expand Down
2 changes: 2 additions & 0 deletions tests/important-modifier.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { expect, test } from 'vitest'

import { twMerge } from '../src'

test('merges tailwind classes with important modifier correctly', () => {
Expand Down
4 changes: 3 additions & 1 deletion tests/lazy-initialization.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { expect, test, vi } from 'vitest'

import { createTailwindMerge, getDefaultConfig } from '../src'

test('lazy initialization', () => {
const initMock = jest.fn(getDefaultConfig)
const initMock = vi.fn(getDefaultConfig)
const twMerge = createTailwindMerge(initMock)

expect(initMock).not.toHaveBeenCalled()
Expand Down
2 changes: 2 additions & 0 deletions tests/merge-configs.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { expect, test } from 'vitest'

import { mergeConfigs } from '../src'

test('mergeConfigs has correct behavior', () => {
Expand Down
2 changes: 2 additions & 0 deletions tests/modifiers.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { expect, test } from 'vitest'

import { createTailwindMerge, twMerge } from '../src'

test('conflicts across prefix modifiers', () => {
Expand Down
2 changes: 2 additions & 0 deletions tests/negative-values.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { expect, test } from 'vitest'

import { twMerge } from '../src'

test('handles negative value conflicts correctly', () => {
Expand Down
2 changes: 2 additions & 0 deletions tests/non-conflicting-classes.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { expect, test } from 'vitest'

import { twMerge } from '../src'

test('merges non-conflicting classes correctly', () => {
Expand Down
2 changes: 2 additions & 0 deletions tests/non-tailwind-classes.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { expect, test } from 'vitest'

import { twMerge } from '../src'

test('does not alter non-tailwind classes', () => {
Expand Down
2 changes: 2 additions & 0 deletions tests/per-side-border-colors.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { expect, test } from 'vitest'

import { twMerge } from '../src'

test('merges classes with per-side border colors correctly', () => {
Expand Down
2 changes: 2 additions & 0 deletions tests/prefixes.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { expect, test } from 'vitest'

import { extendTailwindMerge } from '../src'

test('prefix working correctly', () => {
Expand Down
2 changes: 2 additions & 0 deletions tests/pseudo-variants.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { expect, test } from 'vitest'

import { twMerge } from '../src'

test('handles pseudo variants conflicts properly', () => {
Expand Down
5 changes: 4 additions & 1 deletion tests/public-api.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { expect, test } from 'vitest'

import {
ClassNameValue,
ClassValidator,
Expand All @@ -18,7 +20,7 @@ test('has correct export types', () => {
expect(twMerge).toStrictEqual(expect.any(Function))
expect(createTailwindMerge).toStrictEqual(expect.any(Function))
expect(getDefaultConfig).toStrictEqual(expect.any(Function))
expect(validators).toEqual({
expect(validators).toMatchObject({
isAny: expect.any(Function),
isArbitraryLength: expect.any(Function),
isArbitraryNumber: expect.any(Function),
Expand All @@ -33,6 +35,7 @@ test('has correct export types', () => {
isNumber: expect.any(Function),
isTshirtSize: expect.any(Function),
})
expect(Object.keys(validators)).toHaveLength(13)
expect(mergeConfigs).toStrictEqual(expect.any(Function))
expect(extendTailwindMerge).toStrictEqual(expect.any(Function))
expect(twJoin).toStrictEqual(expect.any(Function))
Expand Down
2 changes: 2 additions & 0 deletions tests/separators.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { expect, test } from 'vitest'

import { extendTailwindMerge } from '../src'

test('single character separator working correctly', () => {
Expand Down
Loading

0 comments on commit 0c74ac3

Please sign in to comment.