Skip to content

update test suites #1668

@sydneywalcoff

Description

@sydneywalcoff

Dependency

Overview

Create React App(CRA) deprecated and we had to migrate to Vite for future sustainability. However many of our test suites from #1241 use testing packages from CRA. We need to translate these test suites to use Vite-compatible tests.

Action Items

Update the test suites using the new test library:

Root folder

  • install vitest and @vitest/types npm packages
  • uninstall jest
  • update scripts in package.json so running npm run test uses vitestcommand instead of react-scripts test
  • update vite.config.ts file to add this to defineConfig in addition to plugins
    • some projects would have a separate vitest.config.ts file, but don't think we need one in this case
    • setupTests.js file already set up with @testing-library/jest-dom import
    • Jest has their globals API enabled by default, but Vitest doesn't, so needs to be included in the config
    • to replicate Jest's behavior of running hooks (like beforeEach, used in input button/routing tests) sequentially in Vitest, you can configure Vitest's sequence.hooks to 'list' in the test object
  test: {
    globals: true,
    environment: "jsdom",
    setupFiles: "./src/setupTests.js",
    sequence: {
      hooks: 'list',
    },
  • update tsconfig.json to add "types": ["vitest"], under compilerOptions

Individual test files

  • add import { describe, test, expect, vi } from 'vitest';
  • use vi.fn() instead of jest.fn() to mock functions

There may be additional updates needed based on the specifics of each test file, but this should get us most of the way there.

Resources/Notes

Vitest - Jest migration docs

Metadata

Metadata

Assignees

No one assigned

    Labels

    DevOpstype of development task related to Process, Github Actions, and DeploymentdependencyThe issue or reason why this issue is in the iceboxfeature: technical standardsaccessibility, usability, unit testing, etc.issue level: missingissue type I: requestSmallest type of issue; Typically can be completed by one personpriority: mediumrole: developmentanything related to codesize: 3ptCan be done in 13-18 hours

    Type

    No type

    Projects

    Status

    Icebox

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions