Skip to content

Commit

Permalink
chore(test): migrate from jest to vitest (#1945)
Browse files Browse the repository at this point in the history
* chore(test): migrate from jest to vitest

* fix(i18n): update test

* fix: tests

* fix: improve solution

---------

Co-authored-by: Dorian Maliszewski <[email protected]>
  • Loading branch information
philibea and DorianMaliszewski authored Apr 25, 2024
1 parent 067dd9f commit d654667
Show file tree
Hide file tree
Showing 114 changed files with 2,835 additions and 789 deletions.
3 changes: 2 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
node_modules/
dist/
build/
__typetests__/
__typetests__/
packages_deprecated/
7 changes: 5 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,14 @@
{
"files": [
"packages/jest-helpers/**/*.ts{x,}",
"**/__tests__/**/*.ts{x,}"
"**/__tests__/**/*.ts{x,}",
"vitest.setup.ts",
"*.config.ts"
],
"rules": {
"import/no-extraneous-dependencies": "off",
"react/jsx-key": "off"
"react/jsx-key": "off",
"import/no-relative-packages": "off"
}
}
]
Expand Down
1 change: 1 addition & 0 deletions .github/renovate.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"reviewersSampleSize": 2,
"semanticCommitScope": "deps",
"semanticCommitType": "chore",
"ignorePaths": ["packages_deprecated/**/package.json"],
"packageRules": [
{
"matchDepTypes": ["engines", "peerDependencies"],
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ jobs:
- run: pnpm run build
- run: pnpm run test:coverage
- uses: codecov/[email protected]
with:
files: packages/**/coverage/cobertura-coverage.xml
token: ${{ secrets.CODECOV_TOKEN }}
verbose: true

test-types:
runs-on: ubuntu-22.04
Expand Down
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@ yarn-debug.log*
yarn-error.log*
*.log

# turbo
packages/*/.turbo
packages/*/dist

#vite
vite.config.ts.*
vitest.config.ts.*

# Yalc
yalc.lock
Expand Down
14 changes: 6 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,33 +21,32 @@
"@changesets/cli": "2.27.1",
"@commitlint/cli": "19.2.2",
"@commitlint/config-conventional": "19.2.2",
"@jest/globals": "29.7.0",
"@scaleway/eslint-config-react": "workspace:*",
"@scaleway/tsconfig": "workspace:*",
"@testing-library/jest-dom": "6.4.2",
"@testing-library/react": "15.0.2",
"@types/jest": "29.5.12",
"@types/node": "20.12.7",
"@types/react-dom": "18.2.25",
"@types/react": "18.2.79",
"@types/react-dom": "18.2.25",
"@vitejs/plugin-react": "4.2.1",
"@vitest/coverage-istanbul": "^1.5.1",
"browserslist": "4.23.0",
"builtin-modules": "3.3.0",
"cross-env": "7.0.3",
"esbuild-plugin-browserslist": "0.11.1",
"eslint": "8.57.0",
"happy-dom": "^14.7.1",
"husky": "9.0.11",
"jest-environment-jsdom": "29.7.0",
"jest-junit": "16.0.0",
"jest-localstorage-mock": "2.4.26",
"jest": "29.7.0",
"lint-staged": "15.2.2",
"mockdate": "3.0.5",
"prettier": "3.2.5",
"read-pkg": "9.0.1",
"tstyche": "1.1.0 ",
"typescript": "5.4.5",
"vite": "5.2.10",
"vitest": "1.5.0",
"vitest-localstorage-mock": "0.1.2",
"wait-for-expect": "3.0.2"
},
"scripts": {
Expand All @@ -56,8 +55,7 @@
"build": "pnpm recursive run build",
"commit": "npx git-cz -a",
"format": "prettier --write '**/*.{ts,tsx,js,json,md,mdx}'",
"test": "TZ=UTC jest",
"test:watch": "pnpm run test --watch",
"test": "pnpm recursive run test:unit",
"test:coverage": "pnpm run test --coverage",
"test:types": "tstyche",
"release": "pnpm build && pnpm changeset publish",
Expand Down
20 changes: 20 additions & 0 deletions packages/changesets-renovate/__mocks__/simple-git.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// eslint-disable-next-line import/no-extraneous-dependencies
import { vi } from 'vitest'

export const defaultGitValues = {
branch: () => ({
current: '',
}),
show: () => {},
diffSummary: () => {},
revparse: () => {},
add: () => {},
commit: () => {},
push: () => {},
}

export const mockSimpleGit = vi.fn(() => defaultGitValues)

const simpleGit = () => mockSimpleGit()

export { simpleGit }
4 changes: 3 additions & 1 deletion packages/changesets-renovate/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
"type:generate": "tsc --declaration -p tsconfig.build.json",
"build": "vite build --config vite.config.ts && pnpm run type:generate",
"build:profile": "npx vite-bundle-visualizer -c vite.config.ts",
"lint": "eslint --report-unused-disable-directives --cache --cache-strategy content --ext ts,tsx ."
"lint": "eslint --report-unused-disable-directives --cache --cache-strategy content --ext ts,tsx .",
"test:unit": "vitest --run --config vite.config.ts",
"test:unit:coverage": "pnpm test:unit --coverage"
},
"repository": {
"type": "git",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`generate changeset file > should generate changeset file, but skip commit and push 1`] = `
[MockFunction spy] {
"calls": [
[
".changeset/renovate-test.md",
"---
'packageName': patch
---
Updated dependency \`package\` to \`version\`.
Updated dependency \`package2\` to \`version2\`.
",
],
],
"results": [
{
"type": "return",
"value": undefined,
},
],
}
`;
exports[`generate changeset file > should generate changeset file, commit and push 1`] = `
[MockFunction spy] {
"calls": [
[
".changeset/renovate-test.md",
"---
'packageName': patch
---
Updated dependency \`package\` to \`version\`.
Updated dependency \`package2\` to \`version2\`.
",
],
],
"results": [
{
"type": "return",
"value": undefined,
},
],
}
`;
Loading

0 comments on commit d654667

Please sign in to comment.