Skip to content

Commit

Permalink
updating jest tests to vitest
Browse files Browse the repository at this point in the history
  • Loading branch information
elylucas committed Jul 11, 2023
1 parent 1ed0add commit 9365a94
Show file tree
Hide file tree
Showing 14 changed files with 2,883 additions and 226 deletions.
18 changes: 8 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
"@cypress/webpack-dev-server": "^1.6.0",
"@faker-js/faker": "6.1.2",
"@percy/cypress": "2.3.4",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^14.0.0",
"@types/bcryptjs": "2.4.2",
"@types/bluebird": "3.5.36",
"@types/connect-flash": "0.0.37",
Expand All @@ -65,7 +67,6 @@
"@types/express-session": "1.17.4",
"@types/faker": "5.5.9",
"@types/http-proxy-middleware": "0.19.3",
"@types/jest": "27.4.1",
"@types/json-server": "0.14.4",
"@types/jsonwebtoken": "8.5.8",
"@types/jwt-decode": "2.2.1",
Expand Down Expand Up @@ -95,6 +96,7 @@
"dotenv": "16.0.0",
"eslint": "^8.44.0",
"eslint-config-prettier": "8.5.0",
"eslint-config-react-app": "^7.0.1",
"eslint-plugin-cypress": "2.12.1",
"eslint-plugin-prettier": "^5.0.0",
"express": "4.17.3",
Expand All @@ -108,6 +110,7 @@
"graphql-tools": "8.2.7",
"husky": "7.0.4",
"istanbul-lib-coverage": "3.2.0",
"jsdom": "^22.1.0",
"json": "11.0.0",
"jwks-rsa": "2.0.5",
"lowdb": "1.0.0",
Expand All @@ -124,7 +127,8 @@
"ts-node": "10.7.0",
"typescript": "4.6.3",
"vite": "^4.4.2",
"vite-plugin-eslint": "^1.8.1"
"vite-plugin-eslint": "^1.8.1",
"vitest": "^0.33.0"
},
"resolutions": {
"@types/express": "4.17.2",
Expand Down Expand Up @@ -158,8 +162,8 @@
"test": "yarn cypress:open",
"test:headless": "yarn cypress:run",
"test:api": "yarn cypress:run --spec 'cypress/tests/api/*'",
"test:unit": "react-scripts test --runInBand",
"test:unit:ci": "react-scripts test --watchAll false --ci --runInBand",
"test:unit": "vitest",
"test:unit:ci": "vitest --run",
"test:component:ci": "yarn cypress:run:component",
"start:api": "yarn tsnode --files backend/app.ts",
"start:api:watch": "nodemon --exec yarn tsnode --watch 'backend' backend/app.ts",
Expand Down Expand Up @@ -200,12 +204,6 @@
"no-unused-expressions": 0
}
},
"jest": {
"watchPathIgnorePatterns": [
"<rootDir>/data/database.json",
"<rootDir>/data/database-seed.json"
]
},
"husky": {
"hooks": {
"pre-push": "yarn types"
Expand Down
3 changes: 1 addition & 2 deletions src/__tests__/bankaccounts.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/// <reference types="jest" />

import { describe, expect, it, beforeEach } from "vitest";
import { faker } from "@faker-js/faker";
import {
getBankAccountById,
Expand Down
1 change: 1 addition & 0 deletions src/__tests__/comments.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, expect, it, beforeEach } from "vitest";
import {
seedDatabase,
getTransactionsForUserContacts,
Expand Down
1 change: 1 addition & 0 deletions src/__tests__/contacts.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, expect, it, beforeEach } from "vitest";
import {
createContactForUser,
getContactsByUsername,
Expand Down
1 change: 1 addition & 0 deletions src/__tests__/generateSeedData.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, expect, it, beforeEach } from "vitest";
import {
buildDatabase,
userbaseSize,
Expand Down
1 change: 1 addition & 0 deletions src/__tests__/likes.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, expect, it, beforeEach } from "vitest";
import {
seedDatabase,
getTransactionsForUserContacts,
Expand Down
1 change: 1 addition & 0 deletions src/__tests__/notifications.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, expect, it, beforeEach } from "vitest";
import {
seedDatabase,
getTransactionsForUserContacts,
Expand Down
1 change: 1 addition & 0 deletions src/__tests__/transactions.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, expect, it, beforeEach } from "vitest";
import { map } from "lodash/fp";
import {
seedDatabase,
Expand Down
1 change: 1 addition & 0 deletions src/__tests__/users.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, expect, it, beforeEach } from "vitest";
import { seedDatabase, getAllUsers, searchUsers } from "../../backend/database";

import { User } from "../models";
Expand Down
7 changes: 7 additions & 0 deletions src/blah/abc.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { it, expect } from "vitest";

it("should pass", () => {
expect(true).toBe(true);
});

export {};
11 changes: 11 additions & 0 deletions src/setup-tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { expect, afterEach } from "vitest";
import { cleanup } from "@testing-library/react";
import matchers from "@testing-library/jest-dom/matchers";

// extends Vitest's expect method with methods from react-testing-library
expect.extend(matchers);

// runs a cleanup after each test case (e.g. clearing jsdom)
afterEach(() => {
cleanup();
});
1 change: 1 addition & 0 deletions src/utils/__tests__/transactionUtils.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, expect, test } from "vitest";
import {
isRequestTransaction,
getFakeAmount,
Expand Down
6 changes: 5 additions & 1 deletion vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ export default defineConfig(({ command, mode }) => {
build: {
outDir: "build",
},

plugins: [react(), eslint()],
test: {
environment: "jsdom",
setupFiles: "./src/setup-tests.js",
exclude: ["node_modules", "cypress", "dist"],
},
};
});
Loading

0 comments on commit 9365a94

Please sign in to comment.