Repository navigation
[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
Closed
devin-ai-integration[bot] wants to merge 1 commit into
devin-ai-integration[bot] wants to merge 1 commit into
Conversation
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Coverage audit: the repo had no test runner — no
jest/vitestdependency, notestscript, and no config. The 46 existingsrc/**/index.test.jsfiles are dead code: theyimport { shallow } from "enzyme"withenzyme-adapter-react-16(seesrc/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:slugify.jsgetCurrentPage.jsgetActiveServiceMesh.jscurrencies.jsbuild-collections.jsimageValidate.jsredirects.jsuseHasMounted.jsusedataList.jspaginate.jssrc/utilsoverall: 0% -> 97.6% statements, 100% branches (39 tests, 9 suites, ~1s).Setup details:
jest.config.jsusesjsdomand only picks up**/__tests__/**/*.test.js, so the legacy enzyme files are left untouched rather than failing the suite.babel-preset-gatsbytotargets: { node: "current" }; with the repo's browser targets the preset injectscore-js/modules/*imports that aren't installed, and every suite fails to resolve.useHasMounted,usedataList) usecreateRoot+actfromreactdirectly, avoiding a new testing-library dependency.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 testand committing tests work at all:pretestscript (eslint --ignore-path .gitignore .):--ignore-pathwas removed in ESLint 9, so it aborted anynpm testinvocation.--no-warn-ignoredto the ESLint command in.lintstagedrc.js.eslint.config.jsignores**/*.test.jsandsrc/utils/, so with--max-warnings=0the pre-commit hook failed on any staged test file (pre-existing for the legacy tests too).Not covered, deliberately:
src/utils/paginate.jsis broken code, not just untested —setCurrentPageis not defined or imported, so calling it always throwsReferenceError. Nothing in the repo imports it. Happy to delete it in this PR if you'd prefer.Signed commits
Link to Devin session: https://app.devin.ai/sessions/6d93d15f5b444effa06fd52e61c6d516
Requested by: @NSTKrishna