Skip to content

Commit

Permalink
add vitest (#4982)
Browse files Browse the repository at this point in the history
* add vitest

* add changeset

* update design-tokens and isolate jest config

* fix types

* fixups

* fix gha

* attempt fix for cut off FilterDateRangePicker RTL stickersheet

* test: add delay to RTL

* KZN-2614-convert-remaining-jest-tests (#4985)

* migrate text jest tests to vitest

* migrate heading jest tests to vitest

* migrate textfield jest tests to vitest

* migrate VideoPlayer jest tests to vitest and interactive stories

* remove test for pauseplay, replaced with stories

* replace GenericNotification jest tests to interaction stories

* convert MenuTriggerProvider from jest to vitest

* convert DateInputWithIconButton from jest to vitest

* moved TitleBlockZen survey status tests to storybook

* lint fix

* remove flaky snapshots

* fix flaky notification play test

* intro timeout to wait for animation

* fix lint

* intro timeout to wait for animation

* intro borders around the video player to showcase aspectratio

* exclude the pauseplay story from chromatic

* exclude thee genericnotification interaction story from chromatic

* Update packages/components/src/Illustration/subcomponents/VideoPlayer/VideoPlayer.stories.tsx

* fix videoplayer stickersheet

* update generic notification to a story

* Update packages/components/src/Illustration/subcomponents/VideoPlayer/VideoPlayer.spec.tsx

Co-authored-by: Cassandra <[email protected]>

---------

Co-authored-by: Geoffrey Chong <[email protected]>
Co-authored-by: Cassandra <[email protected]>

* new vitest eslint and config

* fix eslint

* remove test cache

* fix turbo tests

* unshard

* unshard

* sharded up

* sharded up

* sharded up

* sharded up

* unsharded

* sharded up

* update gha test stories with shard number

* consolidated vite config

* make expecific eslint exceptions in vitest setup file

* consolidated naming of gha

* revert errorpage test

* remove useless delay

* fix svgo + vite config

* fixups

* skip incompatible scgo test

* revert removal of jest-dom

* rename unit gha tests

* fixups

* revert jest-axe removal

* add node ployfills to vite

* isolate the node polyfills to storybook config

---------

Co-authored-by: Geoffrey Chong <[email protected]>
Co-authored-by: Cassandra <[email protected]>
  • Loading branch information
3 people authored Sep 3, 2024
1 parent 1054201 commit a216c72
Show file tree
Hide file tree
Showing 130 changed files with 2,189 additions and 1,573 deletions.
2 changes: 2 additions & 0 deletions .changeset/clever-eagles-repeat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
2 changes: 2 additions & 0 deletions .changeset/dry-turkeys-lay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
30 changes: 15 additions & 15 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ module.exports = {
"sort-imports-es6-autofix",
"ssr-friendly",
"jsx-a11y",
"jest",
"vitest",
],
rules: {
"@typescript-eslint/adjacent-overload-signatures": "error",
Expand Down Expand Up @@ -177,19 +177,19 @@ module.exports = {
pathGroupsExcludedImportTypes: [],
},
],
"jest/consistent-test-it": ["error", { fn: "it" }],
"jest/expect-expect": "error",
"jest/no-commented-out-tests": "error",
"jest/no-conditional-expect": "error",
"jest/no-focused-tests": "error",
"jest/no-disabled-tests": "error",
"jest/no-standalone-expect": "error",
"jest/no-test-return-statement": "error",
"jest/prefer-equality-matcher": "error",
"jest/require-top-level-describe": "error",
"jest/valid-describe-callback": "error",
"jest/valid-expect": "error",
"jest/valid-title": "error",
"vitest/consistent-test-it": ["error", { fn: "it" }],
"vitest/expect-expect": "error",
"vitest/no-commented-out-tests": "error",
"vitest/no-conditional-expect": "error",
"vitest/no-focused-tests": "error",
"vitest/no-disabled-tests": "error",
"vitest/no-standalone-expect": "error",
"vitest/no-test-return-statement": "error",
"vitest/prefer-equality-matcher": "error",
"vitest/require-top-level-describe": "error",
"vitest/valid-describe-callback": "error",
"vitest/valid-expect": "error",
"vitest/valid-title": "error",
"jsdoc/check-alignment": "off",
"jsdoc/check-indentation": "off",
"jsdoc/newline-after-description": "off",
Expand Down Expand Up @@ -320,7 +320,7 @@ module.exports = {
},
},
{
files: ["**/bin/**", "jest.setup.ts"],
files: ["**/bin/**", "vitest.setup.ts"],
rules: {
"no-console": "off",
},
Expand Down
2 changes: 1 addition & 1 deletion .github/actions/branch-preview/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ runs:
body-includes: ":sparkles: Here is your branch preview! :sparkles:"

- name: Create or update comment
uses: peter-evans/create-or-update-comment@v3
uses: peter-evans/create-or-update-comment@v4
with:
comment-id: ${{ steps.findComment.outputs.comment-id }}
issue-number: ${{ inputs.prNumber }}
Expand Down
11 changes: 1 addition & 10 deletions .github/workflows/ci.yml → .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: ci
name: lint

on:
push:
Expand Down Expand Up @@ -53,12 +53,3 @@ jobs:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup
- run: pnpm lint:styles

jest:
if: github.head_ref != 'changeset-release/main'
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup
- run: pnpm test:ci
6 changes: 3 additions & 3 deletions .github/workflows/test-stories.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ jobs:
with:
artifactName: ${{ env.ARTIFACT_NAME }}
- name: Storybook tests (1/3)
run: pnpm -F @docs/storybook test -- --shard 1/3
run: pnpm turbo @docs/storybook#test:storybook -- --shard 1/3

storybook-tests-2:
name: "test-storybook"
Expand All @@ -78,7 +78,7 @@ jobs:
with:
artifactName: ${{ env.ARTIFACT_NAME }}
- name: Storybook tests (2/3)
run: pnpm -F @docs/storybook test -- --shard 2/3
run: pnpm turbo @docs/storybook#test:storybook -- --shard 2/3

storybook-tests-3:
name: "test-storybook"
Expand All @@ -94,7 +94,7 @@ jobs:
with:
artifactName: ${{ env.ARTIFACT_NAME }}
- name: Storybook tests (3/3)
run: pnpm -F @docs/storybook test -- --shard 3/3
run: pnpm turbo @docs/storybook#test:storybook -- --shard 3/3

chromatic:
needs: run-check
Expand Down
52 changes: 52 additions & 0 deletions .github/workflows/test-unit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: test unit

on:
push:
branches-ignore:
- main

# When Changesets opens a PR it does not trigger GitHub actions,
# because its token does not have permission to. This is a hack
# to allow one of us to trigger GitHub actions for a changesets PR
# by enabling automerge on the PR.
pull_request_target:
types:
- auto_merge_enabled
branches:
- main # the target branch of the PR
paths:
- "**/CHANGELOG.md" # only changesets releases touch changelogs

jobs:
unit-tests:
if: github.head_ref != 'changeset-release/main'
name: "vitest"
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup
- name: Unit tests (1/3)
run: pnpm test -- -- --run --shard=1/3

unit-tests-2:
if: github.head_ref != 'changeset-release/main'
name: "vitest"
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup
- name: Unit tests (2/3)
run: pnpm test -- -- --run --shard=2/3

unit-tests-3:
if: github.head_ref != 'changeset-release/main'
name: "vitest"
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup
- name: Unit tests (3/3)
run: pnpm test -- -- --run --shard=3/3
53 changes: 14 additions & 39 deletions docs/.storybook/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import path, { join, dirname } from "path"
import type { StorybookConfig } from "@storybook/react-vite"
import { mergeAlias } from "vite"
import { nodePolyfills } from "vite-plugin-node-polyfills"

/**
* This function is used to resolve the absolute path of a package.
Expand All @@ -25,6 +25,14 @@ const config: StorybookConfig = {
"storybook-addon-pseudo-states",
],
framework: "@storybook/react-vite",
core: {
builder: {
name: "@storybook/builder-vite",
options: {
viteConfigPath: path.resolve(__dirname, "../../vite.config.ts"),
},
},
},
staticDirs: [
{
from: "../assets",
Expand All @@ -46,43 +54,10 @@ const config: StorybookConfig = {
},
},
},
viteFinal: viteConfig => ({
...viteConfig,
resolve: {
alias: mergeAlias(
[
{
// this is required for the SCSS modules
find: /^~(.*)$/,
replacement: "$1",
},
{
// monorepo workspace aliases
find: /^\@kaizen(.*)$/,
replacement: path.resolve(__dirname, "../../packages$1"),
},
],
{
"~storybook": path.resolve(__dirname, "../"),
"~components": path.resolve(
__dirname,
"../../packages/components/src"
),
"~design-tokens": path.resolve(
__dirname,
"../../packages/design-tokens/src"
),
"~tailwind": path.resolve(__dirname, "../../packages/tailwind/src"),
// i18n-react-intl package attempts to import locales from this path.
// When rollup attempts to import from the 'find' path, it will be
// redirected to import from the replacement path (Same as KAIO rollup config).
"__@cultureamp/i18n-react-intl/locales": path.resolve(
__dirname,
"../../packages/components/locales"
),
}
),
},
}),
viteFinal: config => {
config?.plugins?.push(nodePolyfills())

return config
},
}
export default config
9 changes: 7 additions & 2 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"build:test": "storybook build --test",
"build:chromatic": "storybook build --webpack-stats-json",
"build:tailwind": "npx tailwindcss -i ./tailwind.css -o ./.storybook/preview.css",
"test": "test-storybook --skipTags='skip-test' --url http://127.0.0.1:6006",
"test:storybook": "test-storybook --skipTags='skip-test' --url http://127.0.0.1:6006",
"clean": "rimraf './storybook-static' './node_modules' '.turbo'"
},
"dependencies": {
Expand All @@ -24,6 +24,7 @@
"@kaizen/design-tokens": "workspace:*",
"@kaizen/tailwind": "workspace:*",
"@rollup/plugin-alias": "^5.1.0",
"@storybook/builder-vite": "^8.2.9",
"@storybook/manager-api": "^8.2.9",
"@storybook/react-vite": "^8.2.9",
"@storybook/test-runner": "^0.19.1",
Expand All @@ -33,10 +34,14 @@
"classnames": "^2.5.1",
"globals": "^15.9.0",
"highlight.js": "^11.10.0",
"jest-axe": "^9.0.0",
"sass": "^1.77.8",
"storybook": "^8.2.9",
"tailwindcss": "^3.4.10",
"vite": "^5.4.2"
"vite-plugin-node-polyfills": "^0.22.0"
},
"peerDependencies": {
"vite": ">=5.4.2"
},
"eslintConfig": {
"extends": [
Expand Down
17 changes: 0 additions & 17 deletions jest.config.ts

This file was deleted.

16 changes: 0 additions & 16 deletions jest.setup.ts

This file was deleted.

30 changes: 10 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,10 @@
"build": "pnpm turbo build",
"clean": "pnpm turbo clean && rimraf node_modules && pnpm store prune",
"test": "pnpm turbo test",
"test:ci": "pnpm turbo test:ci",
"jest:debug": "node --inspect-brk node_modules/.bin/jest --runInBand --no-cache",
"eslint-config": "pnpm eslint -c .eslintrc.js --max-warnings=0",
"lint": "pnpm lint:js && pnpm lint:md && pnpm lint:format && pnpm lint:styles",
"lint:ts": "pnpm turbo lint:ts",
"lint:js": "pnpm eslint-config '**/*.{ts,tsx,mjs,js}'",
"lint:md": "pnpm eslint-config '**/*.{md,mdx}'",
"lint:js": "pnpm eslint '**/*.{ts,tsx,mjs,js}' --max-warnings=0",
"lint:md": "pnpm eslint '**/*.{md,mdx}' --max-warnings=0",
"lint:format": "pnpm prettier --check '**/*'",
"lint:scss": "pnpm stylelint '**/*.scss' --config .stylelintrc-scss.json",
"lint:css": "pnpm stylelint '**/*.css' --config .stylelintrc-css.mjs",
Expand Down Expand Up @@ -58,12 +55,9 @@
"@storybook/test": "^8.2.9",
"@storybook/theming": "^8.2.9",
"@stylistic/eslint-plugin": "^2.6.4",
"@testing-library/dom": "^10.4.0",
"@testing-library/jest-dom": "^6.4.8",
"@testing-library/jest-dom": "^6.5.0",
"@testing-library/react": "^16.0.0",
"@testing-library/user-event": "^14.5.2",
"@types/jest": "^29.5.12",
"@types/jest-axe": "^3.5.9",
"@types/node": "^20.14.12",
"@types/react": "^18.3.4",
"@types/react-dom": "^18.3.0",
Expand All @@ -74,18 +68,13 @@
"eslint-config-prettier": "^9.1.0",
"eslint-import-resolver-typescript": "^3.6.1",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-jest": "^27.9.0",
"eslint-plugin-jsx-a11y": "^6.9.0",
"eslint-plugin-mdx": "^3.1.5",
"eslint-plugin-react": "^7.35.0",
"eslint-plugin-sort-imports-es6-autofix": "^0.6.0",
"eslint-plugin-ssr-friendly": "^1.3.0",
"eslint-plugin-storybook": "^0.8.0",
"jest": "^29.7.0",
"jest-axe": "^9.0.0",
"jest-canvas-mock": "^2.5.2",
"jest-environment-jsdom": "^29.7.0",
"jest-static-stubs": "^0.0.1",
"eslint-plugin-vitest": "^0.5.4",
"node-fetch": "^3.3.2",
"playwright": "^1.46.1",
"plop": "^4.0.1",
Expand All @@ -95,15 +84,16 @@
"stylelint": "^16.8.2",
"stylelint-config-standard": "^36.0.1",
"stylelint-config-standard-scss": "^13.1.0",
"ts-jest": "^29.2.4",
"ts-node": "^10.9.2",
"turbo": "^2.0.14",
"typescript": "^5.5.4"
"typescript": "^5.5.4",
"vite": "^5.4.2",
"vitest": "^2.0.5",
"vitest-axe": "^0.1.0"
},
"devDependenciesComments": {
"ts-node": "Required for jest",
"@storybook/*": "Required for Storybook stories across all packages",
"chromatic": "Required for Storybook stories across all packages",
"playwright": "Required for github actions setup"
"playwright": "Required for github actions setup",
"vite-plugin-node-polyfills": "Adds the node `assert` polyfill to Vite for prosemirror to run in storybook"
}
}
2 changes: 1 addition & 1 deletion packages/components/__tests__/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from "./renderWithIntl"
export * from "./reactIntlMock"
Loading

0 comments on commit a216c72

Please sign in to comment.