Skip to content

[tests] Add Jest runner and unit tests for src/utils (0% -> 97% coverage) - #1

Closed
devin-ai-integration[bot] wants to merge 1 commit into
masterfrom
devin/1787802590-utils-unit-tests
Closed

devin-ai-integration[bot] wants to merge 1 commit into
masterfrom
devin/1787802590-utils-unit-tests

Conversation

@devin-ai-integration

Copy link
Copy Markdown

Description

Coverage audit: the repo had no test runner — no jest/vitest dependency, no test script, and no config. The 46 existing src/**/index.test.js files are dead code: they import { shallow } from "enzyme" with enzyme-adapter-react-16 (see src/setupTests.js) while the site is on React 18, and none of those packages are installed. Effective coverage of the whole repo was 0%.

This PR adds a runner and covers the lowest-hanging, highest-value zero-coverage modules — the pure logic in src/utils:

module coverage
slugify.js 100%
getCurrentPage.js 100%
getActiveServiceMesh.js 100%
currencies.js 100%
build-collections.js 100%
imageValidate.js 100%
redirects.js 100%
useHasMounted.js 100%
usedataList.js 100%
paginate.js 0% (see below)

src/utils overall: 0% -> 97.6% statements, 100% branches (39 tests, 9 suites, ~1s).

Setup details:

  • jest.config.js uses jsdom and only picks up **/__tests__/**/*.test.js, so the legacy enzyme files are left untouched rather than failing the suite.
  • The transform pins babel-preset-gatsby to targets: { node: "current" }; with the repo's browser targets the preset injects core-js/modules/* imports that aren't installed, and every suite fails to resolve.
  • Hook tests (useHasMounted, usedataList) use createRoot + act from react directly, avoiding a new testing-library dependency.
  • Added npm test / npm run test:coverage, and a "Run unit tests" step to .github/workflows/checks.yml.

Notes for Reviewers

Two incidental fixes needed to make npm test and committing tests work at all:

  • Removed the stale pretest script (eslint --ignore-path .gitignore .): --ignore-path was removed in ESLint 9, so it aborted any npm test invocation.
  • Added --no-warn-ignored to the ESLint command in .lintstagedrc.js. eslint.config.js ignores **/*.test.js and src/utils/, so with --max-warnings=0 the pre-commit hook failed on any staged test file (pre-existing for the legacy tests too).

Not covered, deliberately: src/utils/paginate.js is broken code, not just untested —

export const paginate = (pageNumber) => { setCurrentPage(pageNumber); };

setCurrentPage is not defined or imported, so calling it always throws ReferenceError. Nothing in the repo imports it. Happy to delete it in this PR if you'd prefer.

Signed commits

  • Yes, I signed my commits.

Link to Devin session: https://app.devin.ai/sessions/6d93d15f5b444effa06fd52e61c6d516
Requested by: @NSTKrishna

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@devin-ai-integration

Copy link
Copy Markdown
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant