forked from vercel/next.js
-
Notifications
You must be signed in to change notification settings - Fork 3
Enhancements #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
JaclynCodes
wants to merge
8
commits into
Pond-Glyphs:canary
Choose a base branch
from
Symphonic-Joules:canary
base: canary
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Enhancements #5
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
7aa160c
Merge pull request #1 from Pond-Glyphs/canary
JaclynCodes e935208
CodeRabbit Generated Unit Tests: Expand test suites for four Next.js …
coderabbitai[bot] 691bf56
Merge pull request #4 from Symphonic-Joules/coderabbitai/utg/7aa160c
JaclynCodes 341d55f
Remove buildPassed job from build_and_deploy workflow
JaclynCodes e93d695
Add CodeQL analysis workflow configuration
JaclynCodes 8526f5f
Fix React Server Components CVE vulnerabilities
vercel[bot] 16b6c7c
Merge pull request #5 from Symphonic-Joules/vercel/react-server-compo…
JaclynCodes 9b85104
Update package.json
JaclynCodes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| # For most projects, this workflow file will not need changing; you simply need | ||
| # to commit it to your repository. | ||
| # | ||
| # You may wish to alter this file to override the set of languages analyzed, | ||
| # or to provide custom queries or build logic. | ||
| # | ||
| # ******** NOTE ******** | ||
| # We have attempted to detect the languages in your repository. Please check | ||
| # the `language` matrix defined below to confirm you have the correct set of | ||
| # supported CodeQL languages. | ||
| # | ||
| name: "CodeQL Advanced" | ||
|
|
||
| on: | ||
| push: | ||
| branches: [ "canary" ] | ||
| pull_request: | ||
| branches: [ "canary" ] | ||
| schedule: | ||
| - cron: '36 7 * * 5' | ||
|
|
||
| jobs: | ||
| analyze: | ||
| name: Analyze (${{ matrix.language }}) | ||
| # Runner size impacts CodeQL analysis time. To learn more, please see: | ||
| # - https://gh.io/recommended-hardware-resources-for-running-codeql | ||
| # - https://gh.io/supported-runners-and-hardware-resources | ||
| # - https://gh.io/using-larger-runners (GitHub.com only) | ||
| # Consider using larger runners or machines with greater resources for possible analysis time improvements. | ||
| runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }} | ||
| permissions: | ||
| # required for all workflows | ||
| security-events: write | ||
|
|
||
| # required to fetch internal or private CodeQL packs | ||
| packages: read | ||
|
|
||
| # only required for workflows in private repositories | ||
| actions: read | ||
| contents: read | ||
|
|
||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| include: | ||
| - language: actions | ||
| build-mode: none | ||
| - language: javascript-typescript | ||
| build-mode: none | ||
| - language: python | ||
| build-mode: none | ||
| - language: rust | ||
| build-mode: none | ||
| # CodeQL supports the following values keywords for 'language': 'actions', 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'rust', 'swift' | ||
| # Use `c-cpp` to analyze code written in C, C++ or both | ||
| # Use 'java-kotlin' to analyze code written in Java, Kotlin or both | ||
| # Use 'javascript-typescript' to analyze code written in JavaScript, TypeScript or both | ||
| # To learn more about changing the languages that are analyzed or customizing the build mode for your analysis, | ||
| # see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/customizing-your-advanced-setup-for-code-scanning. | ||
| # If you are analyzing a compiled language, you can modify the 'build-mode' for that language to customize how | ||
| # your codebase is analyzed, see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/codeql-code-scanning-for-compiled-languages | ||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v4 | ||
|
|
||
| # Add any setup steps before running the `github/codeql-action/init` action. | ||
| # This includes steps like installing compilers or runtimes (`actions/setup-node` | ||
| # or others). This is typically only required for manual builds. | ||
| # - name: Setup runtime (example) | ||
| # uses: actions/setup-example@v1 | ||
|
|
||
| # Initializes the CodeQL tools for scanning. | ||
| - name: Initialize CodeQL | ||
| uses: github/codeql-action/init@v4 | ||
| with: | ||
| languages: ${{ matrix.language }} | ||
| build-mode: ${{ matrix.build-mode }} | ||
| # If you wish to specify custom queries, you can do so here or in a config file. | ||
| # By default, queries listed here will override any specified in a config file. | ||
| # Prefix the list here with "+" to use these queries and those in the config file. | ||
|
|
||
| # For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs | ||
| # queries: security-extended,security-and-quality | ||
|
|
||
| # If the analyze step fails for one of the languages you are analyzing with | ||
| # "We were unable to automatically build your code", modify the matrix above | ||
| # to set the build mode to "manual" for that language. Then modify this step | ||
| # to build your code. | ||
| # ℹ️ Command-line programs to run using the OS shell. | ||
| # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun | ||
| - name: Run manual build steps | ||
| if: matrix.build-mode == 'manual' | ||
| shell: bash | ||
| run: | | ||
| echo 'If you are using a "manual" build mode for one or more of the' \ | ||
| 'languages you are analyzing, replace this with the commands to build' \ | ||
| 'your code, for example:' | ||
| echo ' make bootstrap' | ||
| echo ' make release' | ||
| exit 1 | ||
|
|
||
| - name: Perform CodeQL Analysis | ||
| uses: github/codeql-action/analyze@v4 | ||
| with: | ||
| category: "/language:${{matrix.language}}" |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,215 @@ | ||
| # Test Coverage Enhancements | ||
|
|
||
| This document summarizes the comprehensive test enhancements made to improve code coverage and test quality in the Next.js repository. | ||
|
|
||
| ## Enhanced Test Files | ||
|
|
||
| ### 1. `test/unit/router-add-base-path.test.ts` | ||
| **Original:** 9 lines with 1 basic test | ||
| **Enhanced:** ~140 lines with comprehensive coverage | ||
|
|
||
| **New Test Suites Added:** | ||
| - `with basePath set`: Tests basePath functionality with various scenarios | ||
| - Root path handling | ||
| - Nested paths | ||
| - Query string preservation | ||
| - Hash fragment preservation | ||
| - Complex query strings | ||
| - Special characters | ||
| - URL-encoded characters | ||
|
|
||
| - `with manual client basePath`: Tests manual basePath mode | ||
| - Behavior with manual mode enabled | ||
| - Required flag functionality | ||
|
|
||
| - `edge cases`: Comprehensive edge case testing | ||
| - Empty strings | ||
| - Relative paths | ||
| - Paths with only query strings | ||
| - Paths with only hashes | ||
| - Multiple slashes | ||
|
|
||
| **Coverage Improvements:** | ||
| - Added environment variable mocking with proper setup/teardown | ||
| - Tests for all basePath configuration combinations | ||
| - Edge case validation | ||
| - Query string and hash handling | ||
|
|
||
| ### 2. `test/unit/build-output-log.test.ts` | ||
| **Original:** 27 lines with 1 test for `warnOnce` | ||
| **Enhanced:** ~250 lines with comprehensive logging tests | ||
|
|
||
| **New Test Suites Added:** | ||
| - `warnOnce caching behavior`: Detailed cache mechanism testing | ||
| - Message combination caching | ||
| - Numeric arguments | ||
| - Boolean arguments | ||
| - Object arguments | ||
| - Empty/null/undefined handling | ||
| - Whitespace differences | ||
| - Long message handling | ||
|
|
||
| - `errorOnce`: Tests for error logging with caching | ||
| - Identical error suppression | ||
| - Multiple argument handling | ||
|
|
||
| - `logging functions`: Tests for all logging utilities | ||
| - `wait()` function | ||
| - `error()` function | ||
| - `warn()` function | ||
| - `ready()` function | ||
| - `info()` function | ||
| - `event()` function | ||
| - `trace()` function | ||
| - Empty message handling | ||
| - Multiple argument handling | ||
|
|
||
| **Coverage Improvements:** | ||
| - Console method mocking with proper restoration | ||
| - LRU cache behavior validation | ||
| - All logging function variations tested | ||
| - Edge cases for all argument types | ||
|
|
||
| ### 3. `test/unit/get-project-dir.test.ts` | ||
| **Original:** 5 lines with 1 import test | ||
| **Enhanced:** ~120 lines with functional and integration tests | ||
|
|
||
| **New Test Suites Added:** | ||
| - `getProjectDir function`: Core functionality testing | ||
| - Current directory resolution | ||
| - Provided directory resolution | ||
| - Relative path handling | ||
| - Case sensitivity handling | ||
| - Non-existent directory error handling | ||
| - Empty string handling | ||
|
|
||
| - `typo detection integration`: Tests for command typo detection | ||
| - Common typo detection (biuld → build) | ||
| - Single character typos (dve → dev) | ||
| - Distance threshold validation | ||
| - Closest match selection | ||
| - Case difference handling | ||
| - Exact match behavior | ||
| - Empty input handling | ||
| - Empty options handling | ||
|
|
||
| **Coverage Improvements:** | ||
| - Proper error handling tests | ||
| - Directory existence validation | ||
| - Integration with `detectTypo` utility | ||
| - Process environment management | ||
| - Real path resolution validation | ||
|
|
||
| ### 4. `test/unit/phaseConstants.test.ts` | ||
| **Original:** 16 lines with 1 basic constant check | ||
| **Enhanced:** ~150 lines with comprehensive constant validation | ||
|
|
||
| **New Test Suites Added:** | ||
| - `additional phase constants`: Tests for all phase constants | ||
| - PHASE_ANALYZE | ||
| - PHASE_TEST | ||
| - PHASE_INFO | ||
|
|
||
| - `phase constant types`: Type and convention validation | ||
| - String type validation | ||
| - Uniqueness validation | ||
| - Naming convention (kebab-case) validation | ||
|
|
||
| - `compiler constants`: Compiler configuration tests | ||
| - COMPILER_NAMES object structure | ||
| - COMPILER_INDEXES mapping | ||
| - Index uniqueness | ||
|
|
||
| - `adapter output types`: Adapter enum validation | ||
| - All AdapterOutputType enum values | ||
| - SCREAMING_SNAKE_CASE convention | ||
| - Value uniqueness | ||
|
|
||
| - `constant immutability`: Immutability testing | ||
| - Reassignment prevention | ||
| - Proper export validation | ||
|
|
||
| **Coverage Improvements:** | ||
| - All exported constants tested | ||
| - Naming convention validation | ||
| - Uniqueness guarantees | ||
| - Type safety validation | ||
| - Enum structure validation | ||
|
|
||
| ## Testing Patterns Used | ||
|
|
||
| ### 1. **Environment Variable Management** | ||
| ```typescript | ||
| beforeEach(() => { | ||
| process.env.__NEXT_ROUTER_BASEPATH = '/docs' | ||
| }) | ||
|
|
||
| afterEach(() => { | ||
| // Proper cleanup | ||
| delete process.env.__NEXT_ROUTER_BASEPATH | ||
| }) | ||
| ``` | ||
|
|
||
| ### 2. **Console Mocking** | ||
| ```typescript | ||
| const original = console.warn | ||
| beforeEach(() => { | ||
| console.warn = (m: any) => messages.push(m) | ||
| }) | ||
| afterEach(() => { | ||
| console.warn = original | ||
| }) | ||
| ``` | ||
|
|
||
| ### 3. **Edge Case Testing** | ||
| - Empty strings | ||
| - Null/undefined values | ||
| - Special characters | ||
| - Boundary conditions | ||
| - Error conditions | ||
|
|
||
| ### 4. **Integration Testing** | ||
| - Cross-module functionality | ||
| - Real path resolution | ||
| - Typo detection algorithms | ||
|
|
||
| ## Test Quality Improvements | ||
|
|
||
| 1. **Comprehensive Coverage**: All public APIs and edge cases covered | ||
| 2. **Proper Cleanup**: All tests include setup/teardown for resource management | ||
| 3. **Descriptive Names**: Clear test descriptions following "should..." pattern | ||
| 4. **Organized Structure**: Related tests grouped in describe blocks | ||
| 5. **Mock Management**: Proper mocking and restoration of system resources | ||
| 6. **Error Validation**: Both success and failure paths tested | ||
|
|
||
| ## Running the Enhanced Tests | ||
|
|
||
| ```bash | ||
| # Run all unit tests | ||
| pnpm test-unit | ||
|
|
||
| # Run specific test file | ||
| pnpm jest test/unit/router-add-base-path.test.ts | ||
|
|
||
| # Run with coverage | ||
| pnpm jest --coverage test/unit/ | ||
| ``` | ||
|
|
||
| ## Benefits | ||
|
|
||
| 1. **Increased Confidence**: Comprehensive tests catch regressions early | ||
| 2. **Documentation**: Tests serve as usage examples | ||
| 3. **Maintainability**: Well-structured tests are easier to update | ||
| 4. **Coverage**: Significantly improved code coverage metrics | ||
| 5. **Edge Cases**: Previously untested scenarios now validated | ||
|
|
||
| ## Summary Statistics | ||
|
|
||
| | File | Before | After | Increase | | ||
| |------|--------|-------|----------| | ||
| | router-add-base-path.test.ts | 9 lines, 1 test | ~140 lines, 25+ tests | ~1,400% | | ||
| | build-output-log.test.ts | 27 lines, 1 test | ~250 lines, 30+ tests | ~800% | | ||
| | get-project-dir.test.ts | 5 lines, 1 test | ~120 lines, 15+ tests | ~2,300% | | ||
| | phaseConstants.test.ts | 16 lines, 1 test | ~150 lines, 20+ tests | ~840% | | ||
|
|
||
| **Total Enhancement**: From 57 lines to ~660 lines, from 4 tests to 90+ comprehensive tests | ||
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,7 +11,7 @@ | |
| }, | ||
| "devDependencies": { | ||
| "rimraf": "6.0.1", | ||
| "next": "workspace:*", | ||
| "next": "15.5.8", | ||
| "playwright": "^1.40.0" | ||
| } | ||
| } | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,6 @@ | |
| "cross-env": "^7.0.3", | ||
| "pretty-ms": "^7.0.1", | ||
| "rimraf": "^3.0.2", | ||
| "next": "workspace:*" | ||
| "next": "15.5.8" | ||
| } | ||
| } | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,6 @@ | |
| "cross-env": "^7.0.3", | ||
| "pretty-ms": "^7.0.1", | ||
| "rimraf": "^3.0.2", | ||
| "next": "workspace:*" | ||
| "next": "15.5.8" | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The markdown table in the "Summary Statistics" section uses a leading
||on each row, which renders an extra empty column and is inconsistent with standard table syntax. Consider changing these lines to start with a single|so the header and rows render as a 4‑column table as intended.