Skip to content

Commit

Permalink
refactor(deps): adds vitest (#26)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: replaces jest config for vitest

* refactor(config): renames composite action.yml
  • Loading branch information
csantiago132 authored Oct 8, 2024
1 parent fc298ff commit f948c0f
Show file tree
Hide file tree
Showing 15 changed files with 1,538 additions and 941 deletions.
6 changes: 3 additions & 3 deletions .github/actions/test/action.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: 'Jest Test'
description: 'Runs Jest tests'
name: 'Vite Test'
description: 'Runs Vite tests'

runs:
using: 'composite'
steps:
- name: Run Jest
- name: Vite Test
run: pnpm run test
shell: bash
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ jobs:
- name: Lint
uses: kurocado-studio/styleguide/.github/actions/lint@main

- name: Jest
- name: Test
uses: kurocado-studio/styleguide/.github/actions/test@main
2,317 changes: 1,480 additions & 837 deletions package-lock.json

Large diffs are not rendered by default.

26 changes: 10 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,8 @@
"./commitlint": "./src/commitlint/index.js",
"./release/app": "./src/semantic-release/semanticRelease.app.js",
"./release/npm": "./src/semantic-release/semanticRelease.npm.js",
"./eslint/base": "./src/eslint/eslint.base.js",
"./eslint/browser": "./src/eslint/eslint.browser.js",
"./eslint/jest": "./src/eslint/eslint.jest.js",
"./eslint/node": "./src/eslint/eslint.node.js",
"./eslint/playwright": "./src/eslint/eslint.playwright.js",
"./eslint/react": "./src/eslint/eslint.react.js",
"./eslint/testingLibrary": "./src/eslint/eslint.testingLibrary.js",
"./eslint/vitest": "./src/eslint/eslint.vitest.js",
"./prettier": "./src/prettier/index.js",
"./vitest/react": "./src/vitest/vite.react.js",
"./tsconfig/base": "./src/tsconfig/tsconfig.base.json",
"./tsconfig/node": "./src/tsconfig/tsconfig.node.json",
"./tsconfig/web": "./src/tsconfig/tsconfig.web.json"
Expand All @@ -37,7 +30,7 @@
"src/.github",
"src/commitlint",
"src/eslint",
"src/jest",
"src/vitest",
"src/prettier",
"src/semantic-release",
"src/tsconfig"
Expand Down Expand Up @@ -65,15 +58,15 @@
"@rushstack/eslint-patch": "^1.7.2",
"@semantic-release/changelog": "^6.0.3",
"@semantic-release/git": "^10.0.1",
"@testing-library/jest-dom": "^6.5.0",
"@testing-library/react": "^16.0.1",
"@trivago/prettier-plugin-sort-imports": "^4.3.0",
"@types/jest": "^29.5.13",
"@types/jest-axe": "^3.5.9",
"@types/lodash-es": "^4.17.12",
"@types/react": "^18.3.11",
"@typescript-eslint/eslint-plugin": "^7.1.1",
"@typescript-eslint/parser": "^7.1.1",
"@vitejs/plugin-react": "^4.3.2",
"c8": "^10.1.2",
"eslint-config-prettier": "^9.1.0",
"eslint-import-resolver-alias": "^1.1.2",
"eslint-import-resolver-typescript": "^3.6.1",
Expand All @@ -89,13 +82,13 @@
"eslint-plugin-tsdoc": "^0.2.17",
"eslint-plugin-unicorn": "^51.0.1",
"eslint-plugin-vitest": "^0.3.22",
"jest-axe": "^9.0.0",
"jest-environment-jsdom": "^29.7.0",
"jsdom": "^25.0.1",
"lint-staged": "^15.2.10",
"prettier-plugin-packagejson": "^2.4.12",
"prettier-plugin-sort-imports": "^1.8.6",
"semantic-release-github-pullrequest": "^1.3.0",
"url-join": "^4.0.1"
"url-join": "^4.0.1",
"vitest-axe": "^0.1.0"
},
"engines": {
"node": ">=18.18"
Expand All @@ -105,10 +98,11 @@
"@commitlint/config-conventional": "^19.0.3",
"eslint": "^8.57.0",
"husky": "^9.0.11",
"jest": "^29.7.0",
"prettier": "^3.3.3",
"semantic-release": "^23.0.2",
"typescript": "^5.3.3"
"typescript": "^5.3.3",
"vite": "^5.4.8",
"vitest": "^2.1.2"
},
"publishConfig": {
"access": "public"
Expand Down
10 changes: 10 additions & 0 deletions src/eslint/constants.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
const SPEC_PREFIX = 'spec';
const TEST_PREFIX = 'test';

module.exports = {
ECMA_VERSION: 2021,
JAVASCRIPT_FILES: ['*.js?(x)', '*.mjs'],
JAVASCRIPT_TEST_FILES: [
`*.${TEST_PREFIX}.js?(x)`,
`*.${SPEC_PREFIX}.js?(x)`,
`*.${TEST_PREFIX}.mjs?(x)`,
`*.${SPEC_PREFIX}.mjs?(x)`,
],
TYPESCRIPT_FILES: ['*.ts?(x)'],
TYPESCRIPT_TEST_FILES: [`*.${TEST_PREFIX}.ts?(x)`, `*.${SPEC_PREFIX}.ts?(x)`],
};
10 changes: 10 additions & 0 deletions src/eslint/eslint.base.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
const {
ECMA_VERSION,
JAVASCRIPT_FILES,
JAVASCRIPT_TEST_FILES,
TYPESCRIPT_FILES,
TYPESCRIPT_TEST_FILES,
} = require('./constants');
const unicorn = require('./rules/base/unicorn');
const vitest = require('./rules/vitest');

/**
* @see https://github.com/eslint/eslint/issues/3458
Expand Down Expand Up @@ -50,6 +53,13 @@ module.exports = {
tsconfigRootDir: __dirname,
},
},
{
env: { node: true },
extends: ['plugin:vitest/recommended'],
files: [...TYPESCRIPT_TEST_FILES, ...JAVASCRIPT_TEST_FILES],
plugins: ['vitest'],
rules: vitest.rules,
},
],
parserOptions: {
ecmaVersion: ECMA_VERSION,
Expand Down
1 change: 1 addition & 0 deletions src/eslint/rules/base/unicorn.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module.exports = {
'error',
{
case: 'pascalCase',
ignore: ['\\.spec\\.tsx', '\\.test\\.tsx'],
},
],
},
Expand Down
6 changes: 0 additions & 6 deletions src/eslint/rules/jest/index.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
module.exports = {
extends: ['plugin:vitest/recommended'],
rules: {
/**
* Disallow duplicate setup and teardown hooks.
Expand Down
24 changes: 0 additions & 24 deletions src/jest/jest.config.base.js

This file was deleted.

21 changes: 0 additions & 21 deletions src/jest/jest.config.node.js

This file was deleted.

16 changes: 0 additions & 16 deletions src/jest/jest.config.react.js

This file was deleted.

16 changes: 0 additions & 16 deletions src/jest/jest.config.remix.js

This file was deleted.

5 changes: 5 additions & 0 deletions src/vitest/setup.react.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { expect } from 'vitest';
import 'vitest-axe/extend-expect';
import * as matchers from 'vitest-axe/matchers';

expect.extend(matchers);
18 changes: 18 additions & 0 deletions src/vitest/vite.react.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import react from '@vitejs/plugin-react';
import { defineConfig } from 'vite';

// needed this way by vitest
// eslint-disable-next-line import/no-default-export
export default defineConfig({
plugins: [react()],
test: {
coverage: {
provider: 'c8',
reporter: ['text', 'html'],
},
css: true,
environment: 'jsdom',
globals: true,
setupFiles: './setup.react.js',
},
});

0 comments on commit f948c0f

Please sign in to comment.