Skip to content

Commit

Permalink
DEVPROD-6247: Use Vitest for Parsley (#122)
Browse files Browse the repository at this point in the history
  • Loading branch information
sophstad authored May 17, 2024
1 parent 547b1d9 commit 49ae6db
Showing 125 changed files with 3,753 additions and 3,723 deletions.
1 change: 1 addition & 0 deletions .evergreen/attach.yml
Original file line number Diff line number Diff line change
@@ -167,4 +167,5 @@ functions:
command: attach.xunit_results
params:
files:
- "./ui/bin/vite/*.xml"
- "./ui/bin/jest/*.xml"
4 changes: 2 additions & 2 deletions .evergreen/evergreen.yml
Original file line number Diff line number Diff line change
@@ -56,9 +56,9 @@ buildvariants:
- name: compile
- name: e2e_test_spruce
- name: lint
- name: snapshots
- name: snapshots-jest
- name: storybook
- name: test
- name: test-jest
- name: type_check
- name: deploy_prod_spruce
git_tag_only: true
27 changes: 25 additions & 2 deletions .evergreen/shared.yml
Original file line number Diff line number Diff line change
@@ -300,6 +300,14 @@ functions:
yarn serve
yarn-snapshot:
command: shell.exec
params:
working_dir: ui/${app_dir}
script: |
${PREPARE_SHELL}
yarn snapshot --reporter=default --reporter=junit --outputFile=../bin/vite/*.xml
yarn-snapshot-jest:
command: shell.exec
params:
working_dir: ui/${app_dir}
@@ -313,7 +321,15 @@ functions:
working_dir: ui
script: |
${PREPARE_SHELL}
yarn test --ci --testPathIgnorePatterns=snapshot.test.ts --selectProjects ${build_variant}
yarn test --project=${build_variant} --reporter=default --reporter=junit --outputFile=./bin/vite/junit.xml
yarn-test-jest:
command: shell.exec
params:
working_dir: ui
script: |
${PREPARE_SHELL}
yarn test:jest --ci --testPathIgnorePatterns=snapshot.test.ts --selectProjects ${build_variant}
yarn-tsc:
command: shell.exec
@@ -391,7 +407,10 @@ tasks:
- name: snapshots
commands:
- func: yarn-snapshot
- func: attach-test-results

- name: snapshots-jest
commands:
- func: yarn-snapshot-jest

- name: storybook
commands:
@@ -401,6 +420,10 @@ tasks:
commands:
- func: yarn-test

- name: test-jest
commands:
- func: yarn-test-jest

- name: type_check
commands:
- func: symlink
12 changes: 0 additions & 12 deletions apps/parsley/config/jest/cssTransform.js

This file was deleted.

11 changes: 0 additions & 11 deletions apps/parsley/config/jest/jest.setup.ts

This file was deleted.

32 changes: 0 additions & 32 deletions apps/parsley/config/jest/setupTests.ts

This file was deleted.

40 changes: 0 additions & 40 deletions apps/parsley/config/jest/svgTransform.js

This file was deleted.

32 changes: 32 additions & 0 deletions apps/parsley/config/vitest/setupTests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// jest-dom adds custom jest matchers for asserting on DOM nodes. Works for vitest too!
import "@testing-library/jest-dom";

// The following two variables are dummy values used in auth.test.tsx.
process.env.REACT_APP_EVERGREEN_URL = "http://test-evergreen.com";
process.env.REACT_APP_GRAPHQL_URL = "http://test-graphql.com";
process.env.REACT_APP_SPRUCE_URL = "http://test-spruce.com";

if (process.env.CI) {
// Avoid printing debug statements when running tests.
vi.spyOn(console, "debug").mockImplementation(() => {});

// Avoid printing error statements when running tests.
vi.spyOn(console, "error").mockImplementation(() => {});

// Avoid printing analytics events when running tests, but print any other console.log statements.
const consoleLog = console.log;
console.log = (message: string) => {
if (message.startsWith("ANALYTICS EVENT")) {
return;
}
consoleLog(message);
};
}

// Workaround for a bug in @testing-library/react.
// It prevents Vitest's fake timers from functioning with user-event.
// https://github.com/testing-library/react-testing-library/issues/1197
globalThis.jest = {
...globalThis.jest,
advanceTimersByTime: vi.advanceTimersByTime.bind(vi),
};
42 changes: 0 additions & 42 deletions apps/parsley/jest.config.ts

This file was deleted.

23 changes: 6 additions & 17 deletions apps/parsley/package.json
Original file line number Diff line number Diff line change
@@ -28,12 +28,12 @@
"prepare": "yarn --cwd='../..' prepare",
"prettier": "prettier --write",
"preview": "serve -s dist -p 4173",
"snapshot": "jest snapshot.test.ts --watchAll=false",
"snapshot": "vitest run snapshot.test.ts",
"start": "vite",
"verify-backend": "./scripts/verify-backend.sh",
"storybook": "storybook dev -p 6006",
"storybook:build": "env-cmd -e local -r .env-cmdrc.local.json storybook build",
"test": "yarn --cwd='../..' test --selectProjects parsley --watchAll=false",
"test": "yarn --cwd='../..' test --project=parsley",
"postversion": "scripts/push-version.sh"
},
"dependencies": {
@@ -85,11 +85,9 @@
},
"devDependencies": {
"@emotion/babel-plugin": "11.11.0",
"@emotion/jest": "11.11.0",
"@graphql-codegen/cli": "5.0.2",
"@graphql-codegen/typescript": "4.0.1",
"@graphql-codegen/typescript-operations": "4.0.1",
"@graphql-tools/jest-transform": "2.0.0",
"@sentry/vite-plugin": "2.16.0",
"@storybook/addon-actions": "7.6.9",
"@storybook/addon-essentials": "7.6.9",
@@ -99,11 +97,9 @@
"@storybook/react-vite": "7.6.9",
"@storybook/testing-library": "0.2.2",
"@styled/typescript-styled-plugin": "1.0.1",
"@testing-library/jest-dom": "6.4.2",
"@testing-library/react": "14.1.2",
"@testing-library/user-event": "14.5.1",
"@types/jest": "29.5.12",
"@types/jest-specific-snapshot": "0.5.9",
"@testing-library/jest-dom": "6.4.5",
"@testing-library/react": "15.0.7",
"@testing-library/user-event": "14.5.2",
"@types/js-cookie": "3.0.6",
"@types/lodash.debounce": "4.0.7",
"@types/new-relic-browser": "1.230.4",
@@ -120,27 +116,20 @@
"eslint-config-evg": "*",
"eslint-plugin-prettier": "5.1.3",
"eslint-plugin-sort-keys-plus": "^1.3.1",
"jest": "29.7.0",
"jest-environment-jsdom": "29.6.4",
"jest-junit": "15.0.0",
"jest-specific-snapshot": "8.0.0",
"jest-watch-typeahead": "2.2.2",
"prettier": "3.2.2",
"prompts": "2.4.2",
"replace-in-file": "7.1.0",
"rollup-plugin-visualizer": "5.9.0",
"serve": "14.2.1",
"storybook": "7.6.9",
"storybook-addon-apollo-client": "5.0.0",
"ts-jest": "29.1.2",
"ts-node": "10.9.1",
"typescript": "5.1.3",
"vite": "5.2.11",
"vite-plugin-checker": "0.6.4",
"vite-plugin-env-compatible": "2.0.1",
"vite-tsconfig-paths": "4.3.2",
"web-streams-polyfill": "^3.2.1",
"whatwg-fetch": "3.6.17"
"vitest": "1.6.0"
},
"engines": {
"node": ">=20.10.0"
5 changes: 2 additions & 3 deletions apps/parsley/src/analytics/addPageAction.ts
Original file line number Diff line number Diff line change
@@ -26,19 +26,18 @@ export const addPageAction = <A extends ActionType, P extends Properties>(
{ name, ...actionProps }: A,
properties: P & RequiredProperties,
) => {
const { newrelic } = window;
const { search } = window.location;
const attributesToSend = {
...properties,
...parseQueryString(search),
...actionProps,
};

if (typeof newrelic !== "object") {
if (typeof window?.newrelic !== "object") {
// These will only print when new relic is not available such as during local development
console.log("ANALYTICS EVENT ", { attributesToSend, name });
return;
}

newrelic.addPageAction(name, attributesToSend);
window.newrelic.addPageAction(name, attributesToSend);
};
8 changes: 4 additions & 4 deletions apps/parsley/src/analytics/useAnalyticAttributes.ts
Original file line number Diff line number Diff line change
@@ -2,19 +2,19 @@ import { useEffect } from "react";
import { useLogContext } from "context/LogContext";

export const useAnalyticAttributes = () => {
const { newrelic } = window;

const { logMetadata } = useLogContext();
const { logType, renderingType } = logMetadata || {};

const userId = localStorage.getItem("userId");

useEffect(() => {
if (typeof newrelic !== "object") {
if (typeof window?.newrelic !== "object") {
console.debug("Setting logType: ", logType);
console.debug("Setting userId: ", userId);
return;
}

const { newrelic } = window;
if (logType !== undefined) {
newrelic.setCustomAttribute("logType", logType);
}
@@ -24,5 +24,5 @@ export const useAnalyticAttributes = () => {
if (renderingType !== undefined) {
newrelic.setCustomAttribute("renderingType", renderingType);
}
}, [userId, logType, newrelic, renderingType]);
}, [userId, logType, renderingType]);
};
4 changes: 2 additions & 2 deletions apps/parsley/src/components/Accordion/Accordion.test.tsx
Original file line number Diff line number Diff line change
@@ -37,7 +37,7 @@ describe("accordion", () => {

it("calls onToggle when accordion is toggled", async () => {
const user = userEvent.setup();
const onToggle = jest.fn();
const onToggle = vi.fn();
render(
<Accordion onToggle={onToggle} title="accordion title">
accordion content
@@ -87,7 +87,7 @@ describe("accordion", () => {
);
});
it("when controlled, accordion should call a callback when the user toggles it open or closed", async () => {
const onToggle = jest.fn();
const onToggle = vi.fn();
const user = userEvent.setup();
render(
<Accordion onToggle={onToggle} open title="accordion title">
Loading

0 comments on commit 49ae6db

Please sign in to comment.