Skip to content
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

Replace unit test framework from floss to vitest #2396

Merged
merged 13 commits into from
Oct 22, 2024

Conversation

luzhuang
Copy link
Contributor

@luzhuang luzhuang commented Oct 18, 2024

Please check if the PR fulfills these requirements

  • The commit message follows our guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)

What is the current behavior? (You can also link to an open issue here)

What is the new behavior (if this is a feature change)?

Does this PR introduce a breaking change? (What changes might users need to make in their application due to this PR?)

Other information:

Summary by CodeRabbit

  • New Features

    • Transitioned to the Vitest testing framework for improved testing capabilities across multiple test files.
    • Introduced a new configuration file for Vitest to enhance project-specific testing setups.
    • Added a new coverage script for streamlined testing and coverage reporting.
    • Enhanced CI workflow with Cypress test integration and improved artifact handling for test failures.
    • Updated the @galacean/engine-e2e project version and fixed the vite dependency version.
  • Bug Fixes

    • Corrected indentation in CI workflow configuration for better clarity.
  • Chores

    • Removed unused dependencies and streamlined the testing framework setup by eliminating unnecessary imports.
    • Updated test scripts in package.json to simplify coverage reporting and improve consistency in testing practices.
    • Transitioned file handling in tests to asynchronous operations for improved performance.

@luzhuang luzhuang added the test unit test label Oct 18, 2024
@luzhuang luzhuang added this to the 1.4 milestone Oct 18, 2024
@luzhuang luzhuang requested a review from GuoLei1990 October 18, 2024 02:41
Copy link

coderabbitai bot commented Oct 18, 2024

Caution

Review failed

The pull request is closed.

Walkthrough

The pull request introduces updates to the CI workflow and the testing framework, transitioning from Chai to Vitest. Key modifications include the removal of the codecov job in the CI configuration, changes to test scripts in package.json, and the introduction of a new Vitest configuration file. Several unused dependencies have been removed, and existing classes have been reformatted for improved readability without altering functionality.

Changes

File Path Change Summary
.github/workflows/ci.yml Removed codecov job; corrected indentation in build job; modified e2e job to run Cypress tests with new artifact upload steps.
package.json Updated test script to run vitest; added coverage script; added pretest script; removed several devDependencies and added new dependencies for vitest and playwright.
packages/core/src/animation/Keyframe.ts Reformatted the generic type parameter T in the Keyframe class declaration for improved readability without changing logic.
packages/core/src/animation/internal/animationCurveOwner/AnimationCurveOwner.ts Reformatted conditional expressions in evaluateCrossFadeValue and crossFadeFromPoseAndApplyValue methods for clarity while preserving logic.
tests/src/shader-lab/Preprocessor.test.ts Updated import statements and changed testing framework from Chai to Vitest, including asynchronous file reading.
tests/src/shader-lab/test-case/index.ts Transitioned to asynchronous file handling, updated import statements, and simplified path management.
tests/vitest.config.ts Added a new Vitest configuration file to set up project-specific configurations, including dependency optimizations and browser settings.
e2e/package.json Updated version number and changed vite dependency from caret version to fixed version.

Possibly related PRs

Suggested labels

enhancement

Suggested reviewers

  • gz65555

Poem

In the land of code where rabbits play,
Our tests now hop in a brand new way.
With Vitest's charm, we leap and bound,
Chai's old ways no longer found.
Coverage and structure, all set to shine,
Hooray for our changes, oh how divine! 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@luzhuang luzhuang changed the title Test/refactor test: change floss to vitest Oct 18, 2024
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 14

🧹 Outside diff range and nitpick comments (93)
tests/src/math/Rect.test.ts (2)

2-2: Approve import change with a minor suggestion.

The transition from Chai to Vitest is a good move for standardizing the testing framework. This change aligns well with the refactoring objectives.

Consider adding a blank line after the import statements for better readability:

 import { Rect } from "@galacean/engine-math";
 import { describe, expect, it } from "vitest";
+
 describe("Rect test", () => {

Line range hint 6-38: Update assertion syntax to Vitest conventions.

While the test structure is good, the assertion syntax still follows Chai conventions. To fully align with Vitest, consider updating the assertions.

Replace .to.eq() with .toBe() for primitive value comparisons. For example:

-    expect(a.x).to.eq(0);
+    expect(a.x).toBe(0);

Apply this change throughout the test file. Here's an example of how the "set" test should look:

it("set", () => {
  const a = new Rect();
  a.set(0, 0, 1, 1);
  expect(a.x).toBe(0);
  expect(a.y).toBe(0);
  expect(a.width).toBe(1);
  expect(a.height).toBe(1);
});

Make similar changes for the "clone" and "cloneTo" tests.

tests/src/math/Plane.test.ts (1)

2-2: LGTM! Consider adding test import for consistency.

The change from Chai to Vitest is appropriate and aligns with the PR objectives. The explicit import of describe, expect, and it from Vitest is a good practice.

Consider also importing test from Vitest for consistency, even if it's not used in this file. This can help maintain a standard import across all test files:

import { describe, expect, it, test } from "vitest";
tests/src/core/base/Time.test.ts (3)

2-2: LGTM! Consider destructuring import for consistency.

The import statement has been correctly updated to use Vitest instead of Chai. This change aligns with the transition to the Vitest testing framework.

For consistency with other files and improved readability, consider using a destructured import:

import { describe, beforeAll, expect, it } from "vitest";

6-6: LGTM! Consider using arrow function for consistency.

The before hook has been correctly updated to beforeAll, which is the appropriate Vitest equivalent. This change maintains the same setup logic while adapting to the new testing framework.

For consistency with modern JavaScript practices and to avoid potential this binding issues, consider using an arrow function:

beforeAll(async () => {
  engine = await WebGLEngine.create({ canvas: document.createElement("canvas") });
});

Line range hint 11-28: Consider updating assertion syntax to Vitest style.

While the import and setup have been updated to use Vitest, the assertion syntax still follows the Chai style (to.be.equal). Vitest supports a more concise syntax that could improve readability and consistency with the new testing framework.

Consider updating the assertions to use Vitest's syntax. For example:

expect(engine.time.frameCount).toBe(0);
expect(engine.time.elapsedTime).toBe(0);
expect(engine.time.deltaTime).toBe(0);
// ... and so on for other assertions

This change would complete the transition to Vitest and potentially make the tests more readable.

tests/src/math/Ray.test.ts (2)

2-2: LGTM! Consider importing test for consistency.

The transition from Chai to Vitest is implemented correctly. The import statement includes all necessary functions for the current test structure.

For consistency with Vitest's documentation and common usage patterns, consider also importing test alongside describe, expect, and it. While it is an alias for test, using test is more explicit and aligns with Vitest's recommended style:

import { describe, expect, it, test } from "vitest";

This change would allow for more flexibility in test writing styles within the project.


Line range hint 4-38: LGTM! Consider adding type annotations for improved type safety.

The test structure is compatible with Vitest, and all assertions have been preserved. This ensures that the same functionalities are still being tested after the framework transition.

To further improve the code quality and take advantage of TypeScript's type system, consider adding type annotations to the test variables. This can help catch potential type-related issues early and improve code readability. For example:

it("ray-plane", () => {
  const ray: Ray = new Ray(new Vector3(0, 0, 0), new Vector3(0, 1, 0));
  const plane: Plane = new Plane(new Vector3(0, 1, 0), -3);

  expect(ray.intersectPlane(plane)).to.eq(-plane.distance);
});

Apply similar type annotations to other test cases as well.

tests/src/math/MathUtil.test.ts (2)

Line range hint 6-38: Consider using Vitest's native assertion style

The test structure and assertions are compatible with Vitest. However, for better consistency with Vitest's documentation and common practices, consider updating the assertions from .to.eq() to .toBe(). This change is not strictly necessary but might improve readability for developers more familiar with Jest-style assertions (which Vitest mimics).

Example:

expect(MathUtil.clamp(1, 10, 20)).toBe(10);

Line range hint 5-38: Enhance test descriptions for better clarity

While the tests cover various scenarios well, consider improving the test descriptions to be more specific about what each test is verifying. This can make it easier to understand test failures and maintain the test suite.

For example:

it("should clamp values within the specified range", () => {
  // ...
});

it("should consider values equal within the zero tolerance", () => {
  // ...
});

it("should correctly identify powers of 2", () => {
  // ...
});

it("should accurately convert radians to degrees", () => {
  // ...
});

it("should accurately convert degrees to radians", () => {
  // ...
});

These more descriptive titles can help developers quickly understand the purpose of each test.

tests/src/math/BoundingSphere.test.ts (2)

Line range hint 28-28: Update assertion syntax to match Vitest.

While the import statement has been updated to use Vitest, the assertion syntax still uses Chai-style expect().to.eq(). For consistency and to fully leverage Vitest, consider updating these assertions to Vitest's syntax.

Apply the following changes throughout the file:

-expect(Vector3.equals(center1, center2)).to.eq(true);
-expect(radius1).to.eq(radius2);
+expect(Vector3.equals(center1, center2)).toBe(true);
+expect(radius1).toBe(radius2);

This change should be applied to all assertions in the file (lines 28, 34, and 41).

Also applies to: 34-34, 41-41


Line range hint 1-43: Summary: Test refactoring is on the right track, minor adjustments needed.

The transition to Vitest has been initiated correctly with the import statement update. The overall structure and logic of the tests remain sound. To complete the refactoring:

  1. Update the assertion syntax as suggested in the previous comment.
  2. Double-check that all Chai-specific syntax has been replaced with Vitest equivalents.
  3. Run the tests to ensure they pass with the new framework.

These changes will ensure full compatibility with Vitest and maintain the integrity of your test suite.

tests/src/core/material/UnlitMaterial.test.ts (2)

8-10: LGTM: beforeAll function correctly implemented.

The change from before to beforeAll is correct for the Vitest framework. This ensures that the WebGLEngine is created once before all tests run, which is the intended behavior.

Consider removing the function keyword for consistency with modern JavaScript practices:

beforeAll(async () => {
  engine = await WebGLEngine.create({ canvas: document.createElement("canvas") });
});

Line range hint 1-46: Consider leveraging Vitest-specific features for enhanced testing.

The transition to Vitest has been implemented correctly, and the existing tests should work as expected. To further improve the test suite, consider the following Vitest-specific enhancements:

  1. Use test as an alias for it for better readability:

    test("参数测试", () => {
      // ...
    });
  2. Utilize test.each for parameterized tests if you have similar test cases with different inputs.

  3. Consider using vi.spyOn() for mocking or spying on methods if needed in future tests.

  4. If you need to run tests in parallel, you can use describe.concurrent() or test.concurrent().

These suggestions can help improve test organization and potentially speed up test execution.

tests/src/core/DeviceLost.test.ts (3)

1-4: LGTM! Consider verifying the need for "@galacean/engine-loader".

The import statements look good and align with the transition to Vitest. However, "@galacean/engine-loader" is imported without any named imports. If it's not used directly in the file, consider removing it to keep the imports clean.


Line range hint 35-46: Enhance test with assertions and rendering checks.

While the basic structure for testing device loss and restoration is in place, the test could be improved:

  1. Add assertions to verify the engine's state after restoration.
  2. Include a check to ensure the scene renders correctly after device restoration.
  3. Consider testing multiple loss-restore cycles to ensure consistent behavior.

Example improvements:

engine.update();

// Force lost device.
engine.forceLoseDevice();
expect(engine.isLost).toBe(true);

// Wait for 1 second to restore device.
await new Promise((resolve) => {
  setTimeout(() => {
    engine.forceRestoreDevice();
    expect(engine.isLost).toBe(false);
    engine.update();
    // Add a method to check if the scene is rendered correctly
    expect(isSceneRenderedCorrectly(engine)).toBe(true);
    resolve(null);
  }, 1000);
});

// Test multiple cycles
for (let i = 0; i < 3; i++) {
  engine.forceLoseDevice();
  expect(engine.isLost).toBe(true);
  engine.forceRestoreDevice();
  expect(engine.isLost).toBe(false);
  engine.update();
  expect(isSceneRenderedCorrectly(engine)).toBe(true);
}

These additions will make the test more robust and informative.


Line range hint 1-46: Enhance overall test structure and error handling.

While the test provides a good foundation, consider the following improvements to make it more robust and comprehensive:

  1. Add a teardown step to clean up the engine after the test:

    afterEach(() => {
      engine.destroy();
    });
  2. Implement error handling for potential failures during device loss or restoration:

    try {
      engine.forceLoseDevice();
      // ... restoration code ...
    } catch (error) {
      expect.fail(`Device loss/restoration failed: ${error.message}`);
    }
  3. Consider adding more test cases to cover different scenarios, such as:

    • Device loss during rendering
    • Multiple loss-restore cycles
    • Device loss with different scene complexities
  4. Add performance checks to ensure the engine performs adequately after restoration:

    const startTime = performance.now();
    engine.update();
    const endTime = performance.now();
    expect(endTime - startTime).toBeLessThan(someThreshold);

These enhancements will make the test suite more comprehensive and reliable.

tests/src/core/material/PBRSpecularMaterial.test.ts (1)

Line range hint 1-47: Consider leveraging Vitest-specific features for enhanced testing

The transition from Chai to Vitest has been implemented correctly, maintaining the existing test structure and logic. To further improve the test suite, consider exploring Vitest-specific features such as:

  1. Snapshot testing for complex objects
  2. Mocking capabilities for better isolation of units under test
  3. Concurrent test execution for improved performance

These enhancements could potentially make your tests more robust and efficient.

Would you like assistance in implementing any of these Vitest-specific features?

tests/src/core/Transform.test.ts (1)

13-13: LGTM: Lifecycle method updated to use beforeAll.

The change from before to beforeAll is correct for Vitest and maintains the original setup logic. This ensures the setup runs once before all tests, which is typically more efficient.

Consider removing the function keyword for consistency with modern arrow function syntax:

- beforeAll(async function () {
+ beforeAll(async () => {
tests/src/core/Utils.test.ts (1)

Line range hint 6-77: LGTM: Assertions are compatible with Vitest. Consider idiomatic Vitest assertions.

The existing assertions using expect(...).to.equal(...) and expect(...).to.true/false are compatible with Vitest, which is good. However, for better readability and to fully leverage Vitest's capabilities, consider using more idiomatic Vitest assertions:

  1. Replace expect(...).to.true with expect(...).toBe(true)
  2. Replace expect(...).to.false with expect(...).toBe(false)
  3. Replace expect(...).to.equal(...) with expect(...).toBe(...)

For example:

expect(Utils.isAbsoluteUrl("/test.png")).toBe(false);
expect(Utils.isAbsoluteUrl("https://www.galacean.com/test.png")).toBe(true);

expect(Utils.resolveAbsoluteUrl("https://www.galacean.com", "test.png")).toBe(
  "https://www.galacean.com/test.png"
);

These changes are optional but can improve consistency with Vitest's documentation and common practices.

tests/src/core/2d/text/Font.test.ts (1)

Line range hint 1-62: Overall changes look good, consider leveraging Vitest-specific features.

The transition from Chai to Vitest has been implemented correctly, maintaining the existing test coverage and behavior. All necessary changes have been made to adapt to the new testing framework without altering the core logic of the tests.

As a potential improvement, consider exploring Vitest-specific features that could enhance the test suite, such as:

  1. Using vi.spyOn() for more robust mocking and spying capabilities.
  2. Leveraging Vitest's built-in code coverage tools.
  3. Utilizing Vitest's snapshot testing for complex objects or UI components.

These suggestions could further improve the test suite's effectiveness and take full advantage of Vitest's capabilities.

tests/src/math/SphericalHarmonics3.test.ts (2)

9-10: Formatting change: Float32Array values on a single line.

The expected Float32Array values have been reformatted to a single line. While this change doesn't affect the test logic, it might slightly reduce readability. Consider if multi-line formatting would be more maintainable in the long run.


Line range hint 1-71: Consider updating assertion syntax to Vitest's native style.

While the file has been updated to use Vitest imports, the assertion syntax still uses Chai-like expect(...).to.eq(...). Although Vitest supports this syntax, it's recommended to use Vitest's native matchers (e.g., expect(...).toBe(...)) for improved error messages and better TypeScript support.

Example of updating an assertion:

// Current:
expect(a.coefficients[i]).to.eq(b[i]);

// Suggested:
expect(a.coefficients[i]).toBe(b[i]);

Consider updating all assertions in the file to follow Vitest's native style for consistency and to take full advantage of Vitest's features.

tests/src/core/resource/ResourceManager.test.ts (2)

75-75: LGTM! Assertion syntax updated correctly.

The transition from Chai's assertion syntax to Vitest's toHaveBeenCalled() is correct and maintains the same test logic.

Consider using toHaveBeenCalledTimes(1) for more precise assertion:

-expect(loaderSpy).toHaveBeenCalled();
+expect(loaderSpy).toHaveBeenCalledTimes(1);

This change would make the test more explicit about the expected number of calls.


Line range hint 1-77: LGTM! Test structure and logic maintained during framework transition.

The transition to Vitest has been implemented without altering the core logic or flow of the tests. The test cases still cover important aspects of ResourceManager functionality.

Consider adding more test cases to improve coverage, especially for edge cases or error scenarios. For example:

  1. Test resource loading with invalid URLs
  2. Test concurrent loading of multiple resources
  3. Test error handling when loading fails

These additional tests would enhance the robustness of the test suite.

tests/src/core/material/BaseMaterial.test.ts (1)

Line range hint 1-89: Suggestion: Consider future improvements for consistency

While not directly related to the Vitest transition, consider the following improvements for future PRs:

  1. Standardize the language used in test descriptions (currently mixing Chinese and English).
  2. Use consistent function syntax across tests (either all arrow functions or all regular functions).

These changes could enhance readability and maintainability of the test suite.

tests/src/math/Color.test.ts (1)

Line range hint 1-101: Consider updating assertion syntax to Vitest's native style

While the current assertions work with Vitest due to its compatibility with Chai syntax, it would be beneficial for long-term maintainability to update them to Vitest's native syntax. This change isn't strictly necessary but aligns better with Vitest conventions.

Consider updating the assertions as follows:

  • Replace expect(...).to.eq(...) with expect(...).toBe(...)
  • Replace expect(...).to.deep.eq(...) with expect(...).toEqual(...)

For example:

- expect(Color.equals(color1, color2)).to.eq(true);
+ expect(Color.equals(color1, color2)).toBe(true);

- expect(color2).to.deep.eq(new Color(0.5, 0.5, 0.5, 0.5));
+ expect(color2).toEqual(new Color(0.5, 0.5, 0.5, 0.5));

This change will make the tests more idiomatic to Vitest and potentially easier to maintain in the future.

tests/src/core/particle/ParticleGradient.test.ts (1)

Line range hint 1-78: Consider leveraging Vitest-specific features

The transition to Vitest has been successfully implemented, and the existing tests remain functional. To further improve the test suite, consider the following suggestions:

  1. Use Vitest's built-in snapshot testing for complex objects like color and alpha keys.
  2. Utilize Vitest's test.each for parameterized tests, which could reduce code duplication in similar test cases.
  3. Implement Vitest's beforeEach or beforeAll hooks to set up common test fixtures.
  4. Consider using Vitest's vi.spyOn for more advanced mocking and function call tracking if needed in future tests.

These suggestions are optional improvements and can be implemented gradually as the team becomes more familiar with Vitest's features.

tests/src/core/texture/Texture2D.test.ts (2)

Line range hint 27-117: Update remaining Chai assertions to Vitest syntax.

While the import statement and beforeAll hook have been updated to use Vitest, there are still Chai assertions present in the test cases. To complete the transition to Vitest, please update the following assertion patterns:

  1. Replace .to.throw with .toThrow()
  2. Replace .to.eq with .toBe()
  3. Replace .not.to.throw with .not.toThrow()

For example:

// Before (Chai)
expect(() => {
  // ...
}).to.throw;

// After (Vitest)
expect(() => {
  // ...
}).toThrow();

This will ensure consistency across the entire test suite and fully leverage Vitest's capabilities.


Line range hint 1-117: Complete the transition to Vitest for consistency.

The file has been partially updated to use Vitest, which is a positive change. The main structure and logic of the tests remain intact, ensuring that the test coverage is maintained. However, to fully benefit from the Vitest framework and maintain consistency, please address the following:

  1. Update all remaining Chai assertions to their Vitest equivalents.
  2. Double-check that all Vitest functions (describe, it, expect, etc.) are being used correctly throughout the file.

Once these changes are made, the transition to Vitest will be complete, and the test suite will be fully aligned with the new testing framework.

tests/src/core/material/PBRBaseMaterial.test.ts (3)

8-8: LGTM: Correct use of beforeAll, consider adding afterAll

The change from before to beforeAll is correct for the Vitest framework. This ensures that the setup runs once before all tests in the describe block, which is appropriate for creating the WebGLEngine instance.

Consider adding an afterAll hook to clean up the engine instance after all tests have run:

afterAll(() => {
  engine.destroy();
});

This ensures proper resource cleanup and is a good practice in test suites.


Line range hint 1-89: Overall: Successful migration to Vitest with room for minor enhancements

The transition from Chai to Vitest has been implemented correctly in this file. The core functionality of the tests has been preserved, which is crucial for maintaining the integrity of the test suite. The changes align well with the PR objectives of refactoring the tests and standardizing the testing approach.

To further improve the test suite, consider the following suggestions:

  1. Add an afterAll hook for cleanup, as mentioned earlier.
  2. Review the test cases for any opportunities to use Vitest-specific features that could enhance test readability or performance.
  3. Ensure consistent naming conventions across all test files in the project.

As you continue migrating other test files, consider creating a shared setup file for common operations like engine creation and destruction. This can help reduce duplication and improve maintainability across your test suite.


Chai-specific assertions still present in multiple test files

The following test files still contain Chai-specific assertions that need to be migrated to Vitest:

  • tests/src/core/material/PBRBaseMaterial.test.ts
  • tests/src/shader-lab/ShaderValidate.ts
  • tests/src/math/BoundingBox.test.ts
  • tests/src/loader/GLTFLoader.test.ts
  • tests/src/core/PhysicsManager.test.ts

Please update these assertions to Vitest-compatible syntax to ensure consistency and functionality within the test suite.

🔗 Analysis chain

Line range hint 12-89: LGTM: Test cases preserved correctly

The test cases and assertions have been maintained without changes. This is good as it preserves the original test logic and reduces the risk of introducing errors during the framework transition. The expect(...).to syntax is compatible with both Chai and Vitest, allowing for a smooth migration.

To ensure that all Chai-specific assertions have been properly migrated, let's run a verification script:

This script will help identify any Chai-specific assertions that might have been overlooked during the migration to Vitest.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any remaining Chai-specific assertions

# Test: Search for Chai-specific assertions that might need updating
rg --type typescript 'expect\(.+\)\.to\.(be\.a|be\.an|be\.null|be\.undefined|be\.true|be\.false|be\.empty|exist|equal|eql|throw|not|deep|nested|own|ordered|any|all|include|have|contain|increase|decrease)' tests/

Length of output: 248


Script:

#!/bin/bash
# Description: Check for any remaining Chai-specific assertions in .ts files

# Test: Search for Chai-specific assertions that might need updating
rg --glob '*.ts' 'expect\(.+\)\.to\.(be\.a|be\.an|be\.null|be\.undefined|be\.true|be\.false|be\.empty|exist|equal|eql|throw|not|deep|nested|own|ordered|any|all|include|have|contain|increase|decrease)' tests/

Length of output: 63144

tests/src/core/base/EventDispatcher.test.ts (1)

Line range hint 1-90: Overall review: Successful transition to Vitest with potential for further improvements

The entire file has been successfully updated to use Vitest instead of Chai:

  1. All mock functions now use vi.fn().
  2. All assertions have been updated to use Vitest's expect() syntax.
  3. The overall structure and logic of the tests remain unchanged, maintaining the original test coverage.

While the transition is complete and correct, there might be opportunities to leverage Vitest-specific features for more robust testing:

  1. Consider using beforeEach() to set up the EventDispatcher instance for each test, reducing code duplication.
  2. Explore Vitest's snapshot testing for complex event structures.
  3. Utilize Vitest's built-in code coverage tools to ensure comprehensive test coverage.

Would you like assistance in implementing any of these suggestions?

tests/src/core/physics/PhysicsMaterial.test.ts (1)

Line range hint 16-98: LGTM: Test cases remain consistent with new framework

The structure and content of the test cases remain unchanged and are compatible with Vitest. This maintains the integrity of the tests while transitioning to the new framework.

However, consider updating the assertion syntax to Vitest's native style for better consistency. For example, replace expect(x).to.eq(y) with expect(x).toBe(y) throughout the file.

Would you like me to provide a script to automate this change across the file?

tests/src/core/material/BlinnPhongMaterial.test.ts (1)

Line range hint 12-101: LGTM: Test cases maintained correctly with room for future improvement

The individual test cases have been correctly maintained during the transition to Vitest:

  1. The existing expect assertions remain unchanged, which is valid as Vitest supports Chai-like syntax.
  2. This approach minimizes the risk of introducing errors during the framework transition.

Consider updating the assertion style in the future to fully leverage Vitest's capabilities. For example, you could use Vitest's built-in matchers like toEqual instead of to.deep.eq. This isn't urgent but could improve test readability and potentially unlock additional features of Vitest.

Example of a potential future update:

expect(material.baseColor).toEqual(new Color(1, 1, 1, 1));

instead of

expect(material.baseColor).to.deep.eq(new Color(1, 1, 1, 1));
tests/src/core/material/Material.test.ts (2)

8-10: Consider adding a timeout to the beforeAll hook

The change from before to beforeAll is correct for Vitest and appropriate for this setup. However, the timeout configuration has been removed.

Consider adding a timeout to ensure the test doesn't hang if engine creation takes longer than expected:

beforeAll(async () => {
  engine = await WebGLEngine.create({ canvas: document.createElement("canvas") });
}, 10000); // 10 second timeout, adjust as needed

Line range hint 1-95: Summary: Successful transition to Vitest

The test file has been successfully updated to use Vitest instead of Chai. The changes are minimal and focused on the framework transition:

  1. Import statements have been updated to use Vitest.
  2. The test setup now uses beforeAll instead of before.
  3. The core test logic and assertions remain unchanged, ensuring consistent test coverage.

These changes align with the PR objectives and maintain the integrity of the tests. The transition appears smooth and well-executed.

As the project transitions to Vitest, consider creating a shared setup file for common test configurations, such as timeout settings and WebGLEngine creation. This could help maintain consistency across test files and simplify future updates.

tests/src/core/AssetPromise.test.ts (1)

Line range hint 8-156: Consider refactoring assertions to use Vitest's native syntax

While the current assertions using expect(...).to.be... syntax are supported by Vitest, consider refactoring to Vitest's more direct syntax for improved readability and maintainability. For example:

  • expect(assetPromise).not.to.be.undefined; could become expect(assetPromise).toBeDefined();
  • expect(value).to.be.equal(1); could become expect(value).toBe(1);
  • expect(e).to.eq(1); could become expect(e).toBe(1);

This refactoring is optional but aligns better with Vitest's idiomatic usage.

tests/src/core/texture/RenderTarget.test.ts (1)

Line range hint 36-38: LGTM: Assertions updated correctly with a minor suggestion.

The assertions have been successfully updated from Chai to Vitest syntax, maintaining the original logic. Most assertions now use expect().to.eq(), which is correct.

For consistency, consider updating the following assertions:

  • expect(renderTarget.depthTexture).to.be.null; to expect(renderTarget.depthTexture).to.eq(null);
  • expect(() => { ... }).to.throw; to expect(() => { ... }).toThrow();

These changes would align all assertions with Vitest's preferred syntax.

Also applies to: 65-68, 93-93, 99-99, 105-105, 113-113

tests/src/core/MeshRenderer.test.ts (2)

4-4: LGTM! Consider organizing imports.

The update from Chai to Vitest is correctly implemented. The necessary functions are now imported from 'vitest'.

Consider organizing imports alphabetically for better readability:

import { beforeAll, describe, expect, it } from "vitest";

Line range hint 7-129: LGTM! Well-structured test suite. Consider enhancing test descriptions.

The overall structure of the test suite is well-organized and follows best practices. The use of 'describe' and 'it' blocks provides a clear hierarchy and grouping of tests.

To further improve readability, consider adding more descriptive test names. For example:

it("should correctly assign and retrieve mesh", () => {
  // ... existing test code ...
});

it("should handle enableVertexColor property correctly", () => {
  // ... existing test code ...
});
tests/src/math/Vector2.test.ts (3)

2-2: LGTM! Consider grouping related imports.

The transition from Chai to Vitest is correctly implemented. The import statement now includes the necessary Vitest functions: describe, expect, and it.

For better organization, consider grouping related imports together. You could move this import statement next to the other import at the top of the file:

import { MathUtil, Vector2 } from "@galacean/engine-math";
import { describe, expect, it } from "vitest";

Line range hint 8-190: LGTM! Consider leveraging Vitest-specific features.

The existing test structure is compatible with Vitest, and all test cases have been preserved. The transition from Chai to Vitest has been smoothly handled without requiring changes to the test cases themselves.

Consider the following suggestions to further improve the tests:

  1. Use Vitest's built-in snapshot testing for complex objects or long strings.
  2. Utilize Vitest's test.each for parameterized tests to reduce repetition.
  3. Implement Vitest's beforeEach hook to set up common test data.
  4. Use ES6 arrow functions for more concise test definitions.

Example of using test.each:

const testCases = [
  { method: "add", a: new Vector2(2, 3), b: new Vector2(-3, 5), expected: "vec2(-1, 8)" },
  { method: "subtract", a: new Vector2(2, 3), b: new Vector2(-3, 5), expected: "vec2(5, -2)" },
  // ... add more test cases
];

test.each(testCases)("static $method", ({ method, a, b, expected }) => {
  const out = new Vector2();
  Vector2[method](a, b, out);
  expect(toString(out)).toBe(expected);
});

This approach can help reduce code duplication and make it easier to add new test cases in the future.

🧰 Tools
🪛 Biome

[error] 4-4: Do not shadow the global "toString" property.

Consider renaming this variable. It's easy to confuse the origin of variables when they're named after a known global.

(lint/suspicious/noShadowRestrictedNames)


Line range hint 1-190: Overall, great job on the transition to Vitest!

The migration from Chai to Vitest has been executed well. The import statement has been correctly updated, and the existing test structure is compatible with Vitest. All test cases have been preserved, maintaining the thorough coverage of the Vector2 class functionality.

While the current implementation works perfectly, there's potential to further leverage Vitest's features and modern JavaScript practices to enhance the test suite's readability and maintainability.

If you'd like assistance in implementing any of the suggested improvements or exploring other Vitest features, please let me know. I'd be happy to provide more detailed examples or open a GitHub issue to track these enhancements.

🧰 Tools
🪛 Biome

[error] 4-4: Do not shadow the global "toString" property.

Consider renaming this variable. It's easy to confuse the origin of variables when they're named after a known global.

(lint/suspicious/noShadowRestrictedNames)

tests/src/core/SkinnedMeshRenderer.test.ts (1)

Line range hint 1-156: Overall changes look good, but consider adding new Vitest features.

The transition from Chai to Vitest has been implemented correctly for imports and lifecycle hooks. The core logic of the tests remains unchanged, which maintains existing test coverage. However, consider leveraging Vitest-specific features to enhance your tests, such as:

  1. Using vi.spyOn() for mocking and spying on functions.
  2. Utilizing vi.mock() for module mocking.
  3. Implementing snapshot testing for complex objects.
  4. Using test.each() for parameterized tests.

These features could potentially make your tests more robust and easier to maintain.

Would you like assistance in implementing any of these Vitest-specific features in your tests?

tests/src/core/texture/TextureCubeMap.test.ts (2)

Line range hint 28-156: Consider updating assertion syntax to Vitest style.

While the import statements have been updated to use Vitest, the assertion syntax throughout the test file still appears to be using Chai-style assertions (e.g., expect().to.throw, expect().to.eq). For consistency and to fully leverage Vitest features, consider updating these to Vitest's assertion style.

For example:

  • Change expect().to.throw to expect().toThrow()
  • Change expect().to.eq to expect().toBe()

This will ensure that you're using Vitest's built-in matchers and taking full advantage of its features.

Here's a script to help identify assertions that may need updating:

#!/bin/bash
# Search for Chai-style assertions
rg --type typescript 'expect\(.*\)\.to\.' tests/src/core/texture/TextureCubeMap.test.ts

Line range hint 1-156: Summary: Incomplete transition to Vitest

The file has been partially updated to use Vitest instead of Chai. While the import statements and some lifecycle hooks have been changed, the assertion syntax still uses Chai-style expectations. To complete the transition:

  1. Update all assertions to use Vitest syntax.
  2. Review the use of beforeAll to ensure it doesn't break test isolation.
  3. Consider using Vitest's built-in mocking capabilities instead of manual mocks (e.g., rhi.canIUse.mockReturnValueOnce(false)).

These changes will ensure full compatibility with Vitest and allow you to leverage all of its features.

tests/src/math/Vector4.test.ts (1)

Line range hint 1-236: Overall assessment: Successful transition to Vitest

The file has been successfully updated to use Vitest instead of Chai. The change is minimal and doesn't affect the existing test cases, which is a positive sign. The test suite continues to provide comprehensive coverage for the Vector4 class, including various mathematical operations and transformations.

A few observations and suggestions:

  1. The test cases are well-organized and cover a wide range of Vector4 operations.
  2. The use of the toString helper function enhances readability of the test assertions.
  3. Consider adding a few edge cases or boundary value tests if not covered elsewhere.

To further improve the test suite, consider:

  • Adding tests for error cases, such as division by zero or invalid input.
  • Including performance benchmarks for critical Vector4 operations if deemed necessary.
🧰 Tools
🪛 Biome

[error] 4-4: Do not shadow the global "toString" property.

Consider renaming this variable. It's easy to confuse the origin of variables when they're named after a known global.

(lint/suspicious/noShadowRestrictedNames)

tests/src/math/CollisionUtil.test.ts (1)

Line range hint 1-185: LGTM: Test structure consistent with Vitest, minor suggestion for improvement.

The test structure correctly uses Vitest's describe and it functions, and the assertion syntax expect().to.eq() is compatible with Vitest. The original test logic and coverage have been preserved, which is excellent.

For improved consistency with Vitest's recommended syntax, consider updating the assertions to use .toBe() instead of .to.eq(). This change is optional but aligns better with Vitest's documentation and common usage.

Example:

expect(distance).toBe(5);

instead of

expect(distance).to.eq(5);

Would you like me to provide a script to update all assertions in this file to use .toBe()?

tests/src/core/Scene.test.ts (1)

Line range hint 1-236: Summary: Successful transition to Vitest with minimal changes.

The transition from Chai to Vitest has been implemented cleanly with minimal changes to the existing test structure and logic. This is a positive sign, indicating that the tests were well-structured to begin with. However, to ensure the continued robustness of the test suite, consider the following:

  1. Review the test coverage to ensure all scenarios and edge cases are still adequately tested.
  2. Consider adding new tests if any Vitest-specific features could enhance the test suite.
  3. Verify that the error messages and test output are as informative as they were with Chai.

To maintain and improve the quality of the test suite, consider implementing a coverage report as part of your CI/CD pipeline. This will help identify any areas that may need additional testing.

tests/src/math/Vector3.test.ts (1)

Line range hint 9-238: LGTM! Test structure and assertions are Vitest-compatible.

The existing test structure using describe and it is compatible with Vitest. The assertions using .to.eq() work with both Chai and Vitest, so no changes are needed in the test body.

Consider updating any relevant documentation or README files to reflect the switch from Chai to Vitest for the testing framework.

🧰 Tools
🪛 Biome

[error] 4-4: Do not shadow the global "toString" property.

Consider renaming this variable. It's easy to confuse the origin of variables when they're named after a known global.

(lint/suspicious/noShadowRestrictedNames)

tests/src/core/Sprite.test.ts (1)

Line range hint 1-185: Summary: Vitest migration partially complete, minor updates recommended.

The transition from Chai to Vitest has been initiated with the updated import statement. The test structure and coverage remain intact, which is commendable. To complete the migration:

  1. Update assertion syntax as suggested in the previous comment.
  2. Review and test the changes to ensure all tests pass with the updated syntax.
  3. Consider adding any Vitest-specific features that could enhance the test suite, such as snapshot testing or mock timers if applicable.

Overall, the changes are on the right track, and with these minor updates, the test file will be fully aligned with Vitest best practices.

Would you like assistance in generating a script to automate the assertion syntax updates?

tests/src/core/physics/ColliderShape.test.ts (1)

Line range hint 28-228: LGTM: Test logic preserved during framework transition.

The core logic of the tests has been successfully maintained during the transition from Chai to Vitest. All test cases for BoxColliderShape, CapsuleColliderShape, PlaneColliderShape, and SphereColliderShape are intact and continue to test the same properties and behaviors as before.

Consider updating the assertion syntax to use Vitest's built-in matchers for improved readability and maintainability. For example:

// Instead of:
expect(boxShape.size).to.deep.include({ x: 1, y: 2, z: 3 });

// Consider using:
expect(boxShape.size).toEqual({ x: 1, y: 2, z: 3 });

// Instead of:
expect(boxShape.isTrigger).to.eq(true);

// Consider using:
expect(boxShape.isTrigger).toBe(true);

These changes would leverage Vitest's native assertion style and potentially make the tests more idiomatic to the Vitest framework.

tests/src/loader/KTX2Loader.test.ts (2)

Line range hint 1-109: Overall: Successful transition to Vitest with preserved test logic

The file has been successfully updated to use Vitest instead of Mocha. The core testing logic remains intact, which is crucial for maintaining the validity of the tests. The changes are limited to the necessary updates for the new testing framework, which is the correct approach for this type of transition.

However, there are a few areas that could benefit from further attention:

  1. There are several // @ts-ignore comments throughout the file. It would be beneficial to address these type issues if possible.
  2. Consider adding more descriptive test names to improve test readability and maintenance.
  3. The test suite could benefit from additional error handling and edge case testing.

To improve the overall quality and maintainability of the test suite, consider the following:

  1. Resolve type issues to remove // @ts-ignore comments.
  2. Add more descriptive test names.
  3. Implement error handling and edge case testing.
  4. Consider grouping related tests using nested describe blocks for better organization.

Would you like assistance in implementing any of these improvements?


Multiple // @ts-ignore Comments Detected

The setup function has been correctly updated to use beforeAll for Vitest, maintaining the original functionality.

However, there are eight // @ts-ignore comments present in the code. While occasionally necessary, excessive use can obscure underlying type issues and reduce type safety.

🔗 Analysis chain

Line range hint 31-45: LGTM: Setup function updated for Vitest

The before hook has been correctly replaced with beforeAll, which is the appropriate lifecycle hook in Vitest. The function logic remains unchanged, maintaining the original setup process.

However, there are several // @ts-ignore comments in the code. While these are sometimes necessary, they can hide potential issues.

Could you review these type issues and see if they can be resolved without using // @ts-ignore? This might involve updating type definitions or refactoring the code slightly.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for @ts-ignore comments in the file
rg "@ts-ignore" "tests/src/loader/KTX2Loader.test.ts"

Length of output: 195


Script:

#!/bin/bash
# Retrieve each @ts-ignore comment with the following line for context
rg -A1 "@ts-ignore" "tests/src/loader/KTX2Loader.test.ts"

Length of output: 740

tests/src/core/SpriteMask.test.ts (2)

4-4: LGTM! Consider sorting imports alphabetically.

The change from Chai to Vitest is correctly implemented. The necessary functions are now imported from Vitest, which is consistent with the rest of the file.

Consider sorting the imported functions alphabetically for better readability:

import { beforeEach, describe, expect, it } from "vitest";

Line range hint 1-238: Overall assessment: Successful transition to Vitest

The change from Chai to Vitest has been implemented correctly. The test structure and assertions remain intact, ensuring that the SpriteMask component is still thoroughly tested. This transition allows for better integration with the project's testing ecosystem without compromising the quality or coverage of the tests.

Consider updating the project's documentation to reflect the transition to Vitest, including any changes to the test running process or configuration that may have resulted from this switch.

tests/src/shader-lab/ShaderLab.test.ts (4)

8-9: LGTM! Consider grouping imports.

The transition to Vitest is correctly implemented. However, for better organization, consider grouping related imports together.

You could group the Vitest imports like this:

import { describe, beforeAll, expect, assert, it } from "vitest";
import { server } from "@vitest/browser/context";

10-12: LGTM! Consider adding a type annotation.

The transition to asynchronous file reading is appropriate. For improved clarity, consider adding a type annotation to the readFile function.

You could add a type annotation like this:

const { readFile }: { readFile: (path: string) => Promise<string> } = server.commands;

const demoShader = await readFile("./shaders/demo.shader");

Line range hint 114-120: Make the beforeAll hook asynchronous.

The beforeAll hook is using the asynchronously read demoShader, but the hook itself is not asynchronous. This could lead to race conditions or unexpected behavior.

Update the hook to be asynchronous:

beforeAll(async () => {
  shader = shaderLabVerbose._parseShaderContent(await demoShader);
  subShader = shader.subShaders[0];
  passList = subShader.passes;
  expect(passList[0].isUsePass).to.be.true;
  expect(passList[0].name).eq("pbr/Default/Forward");
  pass1 = passList[1];
});

Line range hint 228-256: LGTM! Consider using expect consistently.

All test cases have been correctly updated to use asynchronous file reading. The shader content is properly awaited before validation in each case. The assertions in the "compilation-error" test case have been correctly updated to use Vitest syntax.

For consistency, consider using expect instead of assert in the "compilation-error" test case:

expect(shaderLabVerbose.errors[0]).to.be.instanceOf(GSError);
expect(shaderLabVerbose.errors[1]).to.be.instanceOf(GSError);
expect(shaderLabVerbose.errors[2]).to.be.instanceOf(GSError);
tests/src/core/input/InputManager.test.ts (3)

115-120: LGTM: Test spy creation updated correctly for Vitest.

The test spy creation has been properly updated to use Vitest's vi.fn() instead of Chai's spy. This change is consistent with the transition to the Vitest testing framework and is applied correctly to all TestScript prototype methods.

Consider refactoring this repetitive code to improve maintainability:

const methodsToMock = ['onPointerEnter', 'onPointerExit', 'onPointerDown', 'onPointerClick', 'onPointerDrag', 'onPointerUp'];
methodsToMock.forEach(method => {
  TestScript.prototype[method] = vi.fn(TestScript.prototype[method]);
});

This refactoring applies the DRY (Don't Repeat Yourself) principle, making the code more maintainable and less prone to errors if new methods need to be mocked in the future.


149-154: LGTM: Assertion syntax consistently updated for Vitest.

The assertion syntax has been correctly updated to use Vitest's toHaveBeenCalledTimes(n) method. This change is consistent with the previous blocks and maintains the same test behavior while aligning with the Vitest framework.

Consider refactoring these repeated assertion blocks to reduce duplication and improve maintainability:

const assertMethodCalls = (expectedCalls) => {
  const methods = ['onPointerEnter', 'onPointerExit', 'onPointerDown', 'onPointerClick', 'onPointerDrag', 'onPointerUp'];
  methods.forEach((method, index) => {
    expect(script[method]).toHaveBeenCalledTimes(expectedCalls[index]);
  });
};

// Usage:
assertMethodCalls([1, 1, 1, 1, 1, 1]);

This refactoring would make the tests more maintainable and easier to update if the number of methods or their order changes in the future.


Line range hint 1-265: Overall assessment: Successful transition to Vitest with room for refactoring.

The transition from Chai to Vitest has been implemented correctly and consistently throughout the file. The changes maintain the original test behavior while adopting the new framework's syntax. Here's a summary of the changes:

  1. Import statements have been updated to use Vitest functions.
  2. Test spy creation has been changed to use Vitest's vi.fn().
  3. Assertion syntax has been updated to use Vitest's toHaveBeenCalledTimes().

The core logic of the tests remains unchanged, ensuring that the original test coverage is maintained. However, there are opportunities for refactoring to improve code maintainability, as suggested in previous comments.

Consider implementing the suggested refactoring to reduce code duplication and improve maintainability. This will make the test suite more robust and easier to update in the future.

tests/src/core/Light.test.ts (1)

15-15: LGTM! Consider grouping related imports.

The addition of Vitest-specific imports and "@galacean/engine-loader" is appropriate for the transition to the Vitest testing framework.

Consider grouping related imports together for better readability. For example:

import "@galacean/engine-loader";
import { WebGLEngine } from "@galacean/engine-rhi-webgl";
import { Color, SphericalHarmonics3, Vector3 } from "@galacean/engine-math";
import { describe, beforeAll, it, expect, afterAll } from "vitest";

import { lightResource } from "./model/ambientLight";
import { ColorSpace, ShadowType } from "@galacean/engine-core";

Also applies to: 21-21

tests/src/core/mesh/BlendShapeManager.test.ts (3)

Line range hint 1-20: LGTM! Improved imports and test setup.

The changes to the import statements and test setup look good:

  • Removal of unused imports enhances code cleanliness.
  • Switching to vitest aligns with modern testing practices.
  • Using beforeAll instead of before may improve test efficiency.

Consider adding a comment explaining why beforeAll is preferred over before in this context, to help future maintainers understand the rationale behind this change.


Line range hint 21-385: LGTM! Successful transition to vitest assertions.

The update of assertion syntax from chai to vitest has been done correctly, maintaining the original test logic and coverage. This change aligns well with the new testing framework.

To further improve test readability and maintainability, consider using vitest's built-in snapshot testing for complex object comparisons. For example, the macro checks could be simplified using snapshots:

it("Test macros for BlendShapeFrame with normal and tangent", () => {
  // ... existing test setup ...
  
  expect(meshRendererWebgl2.shaderData.getMacros()).toMatchSnapshot();
});

This approach can make the tests more robust against small changes and easier to update when intentional changes occur.


Line range hint 1-385: Overall, excellent transition to vitest with preserved test integrity.

The changes in this file successfully migrate the test suite from chai to vitest while maintaining the original test coverage and logic. This transition aligns the project with modern testing practices and potentially improves test execution efficiency.

Key points:

  1. Unused imports have been removed, enhancing code cleanliness.
  2. Test setup has been optimized with beforeAll.
  3. Assertion syntax has been correctly updated to vitest.

These changes contribute to a more maintainable and standardized testing approach across the project.

As the project continues to evolve, consider the following to further enhance the testing strategy:

  1. Implement snapshot testing for complex comparisons.
  2. Explore vitest's built-in mocking capabilities for more robust unit tests.
  3. Utilize vitest's coverage reporting to ensure comprehensive test coverage is maintained during future development.
tests/src/core/physics/DynamicCollider.test.ts (1)

Line range hint 1-384: Overall test suite review

The transition to Vitest has been implemented smoothly, with the core functionality of the tests remaining intact. The test suite comprehensively covers various aspects of the DynamicCollider class, including:

  1. Shape management (addShape, removeShape)
  2. Physical properties (linearDamping, angularDamping, mass, etc.)
  3. Kinematic behavior
  4. Force and torque application
  5. Collision detection modes
  6. Constraints
  7. Sleep and wake-up functionality

Consider adding tests for edge cases or error handling scenarios if not already covered in other test files. This could include:

  1. Testing with invalid input values
  2. Checking behavior when reaching physical limits (e.g., maximum velocity)
  3. Verifying error handling for incompatible shape additions

Additionally, you might want to add comments explaining the purpose of each test group to improve readability and maintainability.

tests/src/core/Script.test.ts (5)

21-23: LGTM: Correct implementation of Vitest mocking

The TestScript prototype methods are now correctly using vi.fn() for mocking, which is consistent with the transition to Vitest.

Consider using the vi.spyOn() method instead of directly overwriting the prototype methods. This approach is generally considered more robust and easier to clean up after tests. For example:

vi.spyOn(TestScript.prototype, 'onAwake');
vi.spyOn(TestScript.prototype, 'onEnable');
vi.spyOn(TestScript.prototype, 'onDisable');

65-67: LGTM: Correct implementation of Vitest mocking for ParentScript and ChildScript

The ParentScript and ChildScript prototype methods are now correctly using vi.fn() for mocking, which is consistent with the transition to Vitest.

As suggested earlier, consider using vi.spyOn() instead of directly overwriting the prototype methods. For example:

vi.spyOn(ParentScript.prototype, 'onAwake');
vi.spyOn(ParentScript.prototype, 'onEnable');
vi.spyOn(ParentScript.prototype, 'onDisable');

vi.spyOn(ChildScript.prototype, 'onAwake');
vi.spyOn(ChildScript.prototype, 'onEnable');
vi.spyOn(ChildScript.prototype, 'onDisable');

Also applies to: 94-96


137-139: LGTM: Correct implementation of Vitest mocking for TestScript

The TestScript prototype methods are now correctly using vi.fn() for mocking in the "Entity isActive = true after script call enabled = false" test, which is consistent with the transition to Vitest.

As suggested earlier, consider using vi.spyOn() instead of directly overwriting the prototype methods. For example:

vi.spyOn(TestScript.prototype, 'onAwake');
vi.spyOn(TestScript.prototype, 'onEnable');
vi.spyOn(TestScript.prototype, 'onDisable');

185-187: LGTM: Correct implementation of Vitest mocking for Script1, Script2, and Script3

The Script1, Script2, and Script3 prototype methods are now correctly using vi.fn() for mocking in the "Script delete in the main loop" test, which is consistent with the transition to Vitest.

As suggested earlier, consider using vi.spyOn() instead of directly overwriting the prototype methods. For example:

vi.spyOn(Script1.prototype, 'onUpdate');
vi.spyOn(Script2.prototype, 'onUpdate');
vi.spyOn(Script3.prototype, 'onUpdate');

208-209: LGTM: Correct implementation of Vitest mocking for Script1 and Script2

The Script1 and Script2 prototype methods are now correctly using vi.fn() for mocking in the "Script add in script's onStart" test, which is consistent with the transition to Vitest.

As suggested earlier, consider using vi.spyOn() instead of directly overwriting the prototype methods. For example:

vi.spyOn(Script1.prototype, 'onStart');
vi.spyOn(Script2.prototype, 'onStart');
tests/src/core/Camera.test.ts (1)

Line range hint 1-359: Test logic preserved, minor improvement suggested

The core logic of the tests has been successfully maintained during the transition from Chai to Vitest. This ensures that the functionality being tested remains consistent. However, there's a potential area for improvement:

In some cases, to.eq is used for object comparisons (e.g., line 22). For complex objects, this might not always work as expected. Consider using to.deep.equal or Vitest's toEqual for more reliable object comparisons.

Example:

expect(camera.viewport).toEqual(new Vector4(0, 0, 1, 1).toJSON());

This change would make the tests more robust and less prone to false negatives.

tests/src/core/Shader.test.ts (2)

31-34: LGTM: Test case updated for Vitest

The test case for creating a shader with the same name has been successfully updated to use Vitest syntax. The changes include:

  1. Using vi.spyOn for creating a spy on console.error.
  2. Updating the assertion to use toHaveBeenCalledWith.
  3. Using vi.resetAllMocks() to reset all mocks after the test.

These changes are correct and align with Vitest best practices.

Consider using vi.spyOn(console, "error").mockImplementation() to prevent actual console errors during tests, which can clutter the test output.


Line range hint 1-524: Recommendations for the testing framework transition

The transition from Chai to Vitest in this file has been executed well. To ensure a smooth and consistent transition across the entire project, consider the following recommendations:

  1. Create a checklist of common Chai to Vitest syntax changes to guide the transition process for other test files.
  2. Consider using a codemod or automated script to perform bulk updates where possible, reducing the chance of manual errors.
  3. After updating all files, run the entire test suite to ensure no tests were broken during the transition.
  4. Update any CI/CD pipelines to use Vitest commands instead of Chai.
  5. Review and update any documentation or contribution guidelines related to testing to reflect the use of Vitest.

To maintain consistency and ease future transitions, consider creating a thin wrapper around Vitest that exposes a stable API for your project. This can help isolate any future testing framework changes to a single location.

tests/src/loader/GLTFLoader.test.ts (5)

31-31: LGTM! Consider using ES6 import syntax for consistency.

The transition from Chai to Vitest and the use of beforeAll and afterAll hooks are appropriate changes. However, for consistency with the rest of the file, consider using ES6 import syntax:

-import { describe, beforeAll, afterAll, expect, it } from "vitest";
+import { describe, beforeAll, afterAll, expect, it } from "vitest";

Also applies to: 34-34, 373-373


Line range hint 35-371: Consider moving custom parsers and extensions to a separate file.

The custom GLTF parsers and extensions (GLTFCustomJSONParser, EXT_lights_image_based, CustomMaterial, and CustomLight) are well-implemented. However, defining them within the test file may impact maintainability as the codebase grows.

Consider moving these custom parsers and extensions to a separate file (e.g., customGLTFParsers.ts) and importing them in the test file. This would improve code organization and make it easier to reuse these parsers in other tests or parts of the application if needed.


Line range hint 380-457: Consider breaking down the "Pipeline Parser" test into smaller, focused tests.

The "Pipeline Parser" test case is comprehensive and covers many aspects of GLTF loading. However, it's quite long and tests multiple concerns in a single test. This can make it harder to identify the cause of failures and maintain the test over time.

Consider breaking this test into smaller, more focused tests, each covering a specific aspect of the GLTF loading process. For example:

  1. Test material loading and properties
  2. Test entity hierarchy and transformations
  3. Test light components
  4. Test texture loading and properties
  5. Test mesh loading and properties

This approach would improve test readability, maintainability, and help isolate issues when they occur.


Line range hint 459-487: LGTM! Consider adding comments to clarify test stages.

The "GLTFResource GC" test case effectively covers the garbage collection behavior of GLTFResource under different scenarios. To improve readability and make the test's structure more apparent, consider adding comments to clearly delineate each stage of the test:

it("GLTFResource GC", async () => {
  // Setup: Load GLTFResource
  const glTFResource: GLTFResource = await engine.resourceManager.load({
    type: AssetType.GLTF,
    url: "mock/path/testB.gltf"
  });
  const { materials, textures, meshes } = glTFResource;

  // Stage 1: Verify initial state
  let glTFResourceCache = engine.resourceManager.getFromCache("mock/path/testB.gltf");
  expect(glTFResourceCache).to.not.be.null;

  // Stage 2: Test GC with instance
  // ...

  // Stage 3: Test GC with part instance exist
  // ...

  // Stage 4: Test GC with no instance exist
  // ...
});

This addition would make the test's structure and intent clearer at a glance.


Line range hint 489-516: LGTM! Consider improving the test description for clarity.

The "GLTFResource destroy directly" test case effectively covers the destruction behavior of GLTFResource and its sub-resources. However, the test description could be more specific to better reflect its contents.

Consider updating the test description to something like:

it("should handle direct destruction of GLTFResource and its sub-resources correctly", async () => {
  // ... (existing test code)
});

This description more accurately reflects the test's purpose and makes it easier for other developers to understand the test's intent at a glance.

Additionally, consider adding comments to clearly delineate each stage of the test, similar to the suggestion for the previous test case. This would further improve the test's readability and maintainability.

tests/src/core/physics/Collider.test.ts (10)

16-21: Simplify mocking of methods in CollisionScript class

While wrapping the methods with vi.fn() allows for tracking calls during tests, passing the prototype method as an argument is unnecessary since the original methods are empty. You can simplify the mocks by directly assigning vi.fn() to each method.

Apply this diff to simplify the mocks:

- onTriggerEnter = vi.fn(CollisionScript.prototype.onTriggerEnter);
+ onTriggerEnter = vi.fn();

- onTriggerStay = vi.fn(CollisionScript.prototype.onTriggerStay);
+ onTriggerStay = vi.fn();

- onTriggerExit = vi.fn(CollisionScript.prototype.onTriggerExit);
+ onTriggerExit = vi.fn();

- onCollisionEnter = vi.fn(CollisionScript.prototype.onCollisionEnter);
+ onCollisionEnter = vi.fn();

- onCollisionStay = vi.fn(CollisionScript.prototype.onCollisionStay);
+ onCollisionStay = vi.fn();

- onCollisionExit = vi.fn(CollisionScript.prototype.onCollisionExit);
+ onCollisionExit = vi.fn();

101-103: Inconsistent assertion syntax - Update Chai assertions to Vitest

While you've updated some assertions to use Vitest's syntax, the assertion expect(boxEntity.transform.position.x).not.to.be.equal(5); still uses Chai syntax. Please update it to Vitest's syntax for consistency.

Apply this diff to update the assertion:

- expect(boxEntity.transform.position.x).not.to.be.equal(5);
+ expect(boxEntity.transform.position.x).not.toBe(5);

121-123: Inconsistent assertion syntax - Update Chai assertions to Vitest

Similar to the previous test, the assertion expect(boxEntity.transform.position.x).to.be.equal(5); uses Chai syntax. Please update it to Vitest's syntax.

Apply this diff:

- expect(boxEntity.transform.position.x).to.be.equal(5);
+ expect(boxEntity.transform.position.x).toBe(5);

142-144: Inconsistent assertion syntax - Update Chai assertions to Vitest

The assertion expect(boxEntity.transform.position.x).to.be.equal(5); should be updated to use Vitest's syntax for consistency.

Apply this diff:

- expect(boxEntity.transform.position.x).to.be.equal(5);
+ expect(boxEntity.transform.position.x).toBe(5);

163-165: Inconsistent assertion syntax - Update Chai assertions to Vitest

Please update the assertion expect(boxEntity.transform.position.x).to.be.equal(5); to use Vitest's syntax.

Apply this diff:

- expect(boxEntity.transform.position.x).to.be.equal(5);
+ expect(boxEntity.transform.position.x).toBe(5);

185-187: Inconsistent assertion syntax - Update Chai assertions to Vitest

The assertion expect(boxEntity.transform.position.x).to.be.equal(5); uses Chai syntax and should be updated.

Apply this diff:

- expect(boxEntity.transform.position.x).to.be.equal(5);
+ expect(boxEntity.transform.position.x).toBe(5);

204-206: Inconsistent assertion syntax - Update Chai assertions to Vitest

Please update expect(boxEntity.transform.position.x).to.be.equal(5); to maintain consistency with Vitest.

Apply this diff:

- expect(boxEntity.transform.position.x).to.be.equal(5);
+ expect(boxEntity.transform.position.x).toBe(5);

225-227: Inconsistent assertion syntax - Update Chai assertions to Vitest

Update the assertion expect(boxEntity.transform.position.x).to.be.equal(5); to Vitest syntax.

Apply this diff:

- expect(boxEntity.transform.position.x).to.be.equal(5);
+ expect(boxEntity.transform.position.x).toBe(5);

247-249: Inconsistent assertion syntax - Update Chai assertions to Vitest

The assertion expect(boxEntity.transform.position.x).not.to.be.equal(5); should be updated to Vitest syntax.

Apply this diff:

- expect(boxEntity.transform.position.x).not.to.be.equal(5);
+ expect(boxEntity.transform.position.x).not.toBe(5);

271-273: Inconsistent assertion syntax - Update Chai assertions to Vitest

Please update expect(boxEntity.transform.position.x).not.to.be.equal(5); to use Vitest's assertion syntax.

Apply this diff:

- expect(boxEntity.transform.position.x).not.to.be.equal(5);
+ expect(boxEntity.transform.position.x).not.toBe(5);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between ab1ceb3 and 0bc262c.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (78)
  • .github/workflows/ci.yml (1 hunks)
  • package.json (2 hunks)
  • tests/.mocharc.json (0 hunks)
  • tests/package.json (1 hunks)
  • tests/src/core/2d/text/Font.test.ts (2 hunks)
  • tests/src/core/2d/text/TextRenderer.test.ts (2 hunks)
  • tests/src/core/2d/text/TextUtils.test.ts (3 hunks)
  • tests/src/core/Animator.test.ts (7 hunks)
  • tests/src/core/AssetPromise.test.ts (1 hunks)
  • tests/src/core/Camera.test.ts (2 hunks)
  • tests/src/core/CompomentDependencies.test.ts (2 hunks)
  • tests/src/core/DeviceLost.test.ts (1 hunks)
  • tests/src/core/Entity.test.ts (4 hunks)
  • tests/src/core/Light.test.ts (3 hunks)
  • tests/src/core/MeshRenderer.test.ts (1 hunks)
  • tests/src/core/ModelMesh.test.ts (2 hunks)
  • tests/src/core/Scene.test.ts (1 hunks)
  • tests/src/core/Script.test.ts (15 hunks)
  • tests/src/core/Shader.test.ts (2 hunks)
  • tests/src/core/SkinnedMeshRenderer.test.ts (1 hunks)
  • tests/src/core/Sprite.test.ts (1 hunks)
  • tests/src/core/SpriteMask.test.ts (1 hunks)
  • tests/src/core/SpriteRenderer.test.ts (1 hunks)
  • tests/src/core/TextRenderer.test.ts (1 hunks)
  • tests/src/core/Transform.test.ts (2 hunks)
  • tests/src/core/Utils.test.ts (1 hunks)
  • tests/src/core/base/EventDispatcher.test.ts (2 hunks)
  • tests/src/core/base/Time.test.ts (1 hunks)
  • tests/src/core/input/InputManager.test.ts (2 hunks)
  • tests/src/core/material/BaseMaterial.test.ts (1 hunks)
  • tests/src/core/material/BlinnPhongMaterial.test.ts (1 hunks)
  • tests/src/core/material/Material.test.ts (1 hunks)
  • tests/src/core/material/PBRBaseMaterial.test.ts (1 hunks)
  • tests/src/core/material/PBRMaterial.test.ts (1 hunks)
  • tests/src/core/material/PBRSpecularMaterial.test.ts (2 hunks)
  • tests/src/core/material/UnlitMaterial.test.ts (1 hunks)
  • tests/src/core/mesh/BlendShape.test.ts (1 hunks)
  • tests/src/core/mesh/BlendShapeManager.test.ts (1 hunks)
  • tests/src/core/mesh/BufferMesh.test.ts (1 hunks)
  • tests/src/core/mesh/PrimitiveMesh.test.ts (1 hunks)
  • tests/src/core/particle/ParticleBoundingBox.test.ts (2 hunks)
  • tests/src/core/particle/ParticleGradient.test.ts (1 hunks)
  • tests/src/core/physics/CharacterController.test.ts (1 hunks)
  • tests/src/core/physics/Collider.test.ts (12 hunks)
  • tests/src/core/physics/ColliderShape.test.ts (1 hunks)
  • tests/src/core/physics/DynamicCollider.test.ts (1 hunks)
  • tests/src/core/physics/Joint.test.ts (1 hunks)
  • tests/src/core/physics/PhysicsManager.test.ts (25 hunks)
  • tests/src/core/physics/PhysicsMaterial.test.ts (1 hunks)
  • tests/src/core/resource/ResourceManager.test.ts (2 hunks)
  • tests/src/core/texture/RenderTarget.test.ts (2 hunks)
  • tests/src/core/texture/Texture2D.test.ts (2 hunks)
  • tests/src/core/texture/TextureCubeMap.test.ts (2 hunks)
  • tests/src/loader/GLTFLoader.test.ts (2 hunks)
  • tests/src/loader/KTX2Loader.test.ts (3 hunks)
  • tests/src/math/BoundingBox.test.ts (1 hunks)
  • tests/src/math/BoundingFrustum.test.ts (1 hunks)
  • tests/src/math/BoundingSphere.test.ts (1 hunks)
  • tests/src/math/CollisionUtil.test.ts (1 hunks)
  • tests/src/math/Color.test.ts (1 hunks)
  • tests/src/math/MathUtil.test.ts (1 hunks)
  • tests/src/math/Matrix.test.ts (3 hunks)
  • tests/src/math/Matrix3x3.test.ts (1 hunks)
  • tests/src/math/Plane.test.ts (1 hunks)
  • tests/src/math/Quaternion.test.ts (1 hunks)
  • tests/src/math/Ray.test.ts (1 hunks)
  • tests/src/math/Rect.test.ts (1 hunks)
  • tests/src/math/SphericalHarmonics3.test.ts (3 hunks)
  • tests/src/math/Vector2.test.ts (1 hunks)
  • tests/src/math/Vector3.test.ts (1 hunks)
  • tests/src/math/Vector4.test.ts (1 hunks)
  • tests/src/rhi-webgl/WebGLEngine.test.ts (3 hunks)
  • tests/src/shader-lab/Preprocessor.test.ts (1 hunks)
  • tests/src/shader-lab/ShaderLab.test.ts (3 hunks)
  • tests/src/shader-lab/ShaderValidate.ts (1 hunks)
  • tests/src/shader-lab/test-case/index.ts (1 hunks)
  • tests/vitest.config.ts (1 hunks)
  • vitest.workspace.ts (1 hunks)
💤 Files with no reviewable changes (1)
  • tests/.mocharc.json
✅ Files skipped from review due to trivial changes (2)
  • tests/src/core/SpriteRenderer.test.ts
  • vitest.workspace.ts
🧰 Additional context used
🔇 Additional comments (200)
tests/vitest.config.ts (3)

1-3: LGTM: Correct import and export setup

The import of defineProject from "vitest/config" and its usage in the default export are correct. This setup properly initializes the Vitest configuration for the project.


13-20: Browser configuration looks good, but clarify environment matching

The browser configuration for testing looks appropriate, setting up Chromium as the test environment. This is good for ensuring consistent test results across different development environments.

However, there's a potential inconsistency in the environmentMatchGlobs configuration:

environmentMatchGlobs: [["tests/**/*.test.ts", "node"]]

This setting associates all .test.ts files in the tests directory with the "node" environment. Given that you've configured a browser environment, it's unexpected to see tests running in a Node.js environment. Could you clarify if this is intentional? If not, you might want to change "node" to "browser" or remove this configuration to use the default browser environment.

To help understand the impact of this configuration, you could run a script to check for browser-specific APIs used in your tests:

#!/bin/bash
# Description: Check for usage of browser-specific APIs in test files

echo "Checking usage of browser-specific APIs in test files:"
rg --type typescript -e "window\." -e "document\." -e "navigator\." -e "localStorage" -e "sessionStorage" tests/

This will help identify if your tests are indeed using browser APIs, which would confirm the need for a browser environment rather than Node.js.


4-12: Clarify the reason for excluding @galacean packages from optimization

The configuration excludes several @galacean packages from dependency optimization. While this might be necessary for certain scenarios, it's important to understand the reasoning behind this decision.

Could you please provide more context on why these packages are being excluded? Additionally, it would be beneficial to verify that this exclusion doesn't negatively impact the overall performance of the tests or the application.

To help assess the impact, you could run performance benchmarks with and without these exclusions. Here's a script to check for usage of these packages in your tests:

This will help understand the extent of usage of these packages in your tests and potentially inform the decision to exclude them from optimization.

✅ Verification successful

[/run_scripts]


Exclusion of @galacean packages from optimization is justified

The excluded @galacean packages are extensively used in your test files. Excluding them from dependency optimization helps prevent potential build issues and ensures that tests run reliably without unnecessary bundling overhead.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for usage of excluded @galacean packages in test files

echo "Checking usage of excluded @galacean packages in test files:"
for package in "@galacean/engine" "@galacean/engine-loader" "@galacean/engine-rhi-webgl" "@galacean/engine-math" "@galacean/engine-core"; do
    echo "Usage of $package:"
    rg --type typescript "$package" tests/
    echo ""
done

Length of output: 358


Script:

#!/bin/bash
# Description: Check for usage of excluded @galacean packages in test files

echo "Checking usage of excluded @galacean packages in test files:"
for package in "@galacean/engine" "@galacean/engine-loader" "@galacean/engine-rhi-webgl" "@galacean/engine-math" "@galacean/engine-core"; do
    echo "Usage of $package:"
    rg --glob '**/*.ts' --glob '**/*.tsx' "$package" tests/
    echo ""
done

Length of output: 36227

tests/src/shader-lab/Preprocessor.test.ts (2)

6-7: LGTM! Please clarify the testing environment.

The introduction of the Vitest server context and the readFile function from server.commands is a good modernization of the file reading process. This change suggests that the tests might be running in a browser environment.

Could you please confirm if these tests are intended to run in a browser environment? If so, are there any specific setup steps or configurations needed for other developers to run these tests locally?

To verify the testing environment, you can run:

#!/bin/bash
# Description: Check for browser-specific test configurations

# Test: Look for browser-specific test setup in package.json or vite.config.js
echo "Checking for browser-specific test configurations:"
rg --type json '"test":.+browser' package.json
rg --type javascript 'browser.+test' vite.config.js

9-9: Approve async change, but verify file path resolution.

The switch to an asynchronous readFile operation is good and consistent with the new Vitest setup. However, the simplified file path might cause issues if the current working directory during test execution is not what's expected.

Please confirm that the file path "test-case/included.txt" will always resolve correctly, regardless of where the tests are run from. You might want to consider using a path relative to __dirname or another reliable reference point.

To verify the file path resolution, you can run:

#!/bin/bash
# Description: Check the existence and location of the test case file

# Test 1: Find all occurrences of the test case file
echo "Locating test case file:"
fd 'included.txt'

# Test 2: Check if the file exists in the expected location
echo "Checking if file exists in the expected location:"
[ -f "test-case/included.txt" ] && echo "File exists" || echo "File not found"
tests/src/math/Rect.test.ts (1)

Line range hint 1-38: Overall assessment: Good transition to Vitest with minor adjustments needed.

The file has been successfully updated to use Vitest as the testing framework. The structure of the tests is good, and they cover the essential functionality of the Rect class. With the suggested changes to the import statement formatting and assertion syntax, this file will be fully aligned with Vitest conventions.

tests/package.json (1)

26-28: LGTM! Consider checking for the latest version of @vitest/browser.

The addition of @vitest/browser as a dev dependency is appropriate for transitioning to Vitest for browser-based testing. The JSON structure is now correct with the proper closing of the dependencies section.

Consider verifying if version 2.1.3 of @vitest/browser is the latest stable version. You may want to use the latest version to ensure you have the most up-to-date features and bug fixes.

To check for the latest version of @vitest/browser, you can run:

If a newer version is available, consider updating the version number in the package.json file.

tests/src/math/Plane.test.ts (2)

Line range hint 4-30: LGTM! No changes required in test cases.

The test cases and assertions are compatible with Vitest and don't require any changes. The expect().to.eq() syntax works well with both Chai and Vitest.


Line range hint 1-30: Summary: Successful migration from Chai to Vitest

The file has been successfully migrated from Chai to Vitest with minimal changes. This update aligns with the PR objectives of refactoring tests. The change is limited to the import statement, which is the correct approach as the existing test structure and assertions are compatible with Vitest.

This migration should not affect the functionality of the tests, but it standardizes the testing framework across the project. Good job on maintaining a clean and focused change!

tests/src/core/base/Time.test.ts (1)

Line range hint 1-30: Overall, good progress on transitioning to Vitest.

The changes made to this file successfully begin the transition from Chai to Vitest, which aligns with the PR objectives. The core logic and structure of the tests remain intact, ensuring that the original functionality is preserved.

To complete the transition and improve consistency:

  1. Update the import statement to use destructuring.
  2. Consider using an arrow function for the beforeAll hook.
  3. Update the assertion syntax throughout the file to use Vitest's native style.

These changes will enhance readability and fully leverage Vitest's features.

tests/src/math/Ray.test.ts (1)

Line range hint 1-38: Overall, excellent transition to Vitest!

The changes in this file successfully migrate the tests from Chai to Vitest while maintaining the integrity and functionality of the existing tests. The transition is smooth and aligns well with the PR objectives.

To further enhance the code:

  1. Consider importing test alongside other Vitest functions for consistency and flexibility.
  2. Add type annotations to test variables to improve type safety and code readability.

These minor improvements will contribute to a more robust and maintainable test suite.

tests/src/core/CompomentDependencies.test.ts (3)

3-3: LGTM: Correct import for Vitest

The import statement has been updated correctly to use Vitest instead of Chai. This change is consistent with the PR objective of transitioning the testing framework. The import includes all necessary functions for the test suite structure.


12-12: LGTM: Correct lifecycle hook for Vitest

The change from before to beforeAll is correct for the Vitest framework. This maintains the same functionality of running setup code once before all tests in the suite. The async nature of the function is preserved, which is crucial for the asynchronous setup process involving WebGLEngine creation.


Line range hint 1-38: Verify assertion styles for Vitest compatibility

The transition from Chai to Vitest has been implemented correctly for the imports and lifecycle hooks. The core logic and structure of the tests remain unchanged, which is good. However, it's important to verify that all assertions in the expect statements are compatible with Vitest's assertion style, as there might be subtle differences between Chai and Vitest assertions.

Please run the following script to check for any Chai-specific assertion styles that might need updating:

If the script returns any results, please review those assertions and update them to Vitest's equivalent assertions if necessary.

✅ Verification successful

Transition to Vitest implemented correctly, no changes needed

The search results confirm that the transition from Chai to Vitest has been implemented correctly in the test files. The assertion styles used in the codebase are compatible with both Chai and Vitest, which explains why the tests continue to work after the transition. Here are the key findings:

  1. The most common assertion styles used (expect(...).to.eq(...), expect(...).to.equal(...), expect(...).to.deep.equal(...)) are supported by both Chai and Vitest.
  2. Other assertion styles found, such as expect(...).to.be.true and expect(...).to.be.false, are also compatible with Vitest.
  3. No Chai-specific assertion styles that would be incompatible with Vitest were detected.

Based on these results, no further changes to the assertion styles in the test files are necessary. The transition to Vitest has been successful, and the existing tests should continue to function as expected.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for Chai-specific assertion styles in test files

# Test: Search for common Chai assertion patterns
rg --type typescript 'expect\(.+\)\.to\.' tests/
rg --type typescript 'expect\(.+\)\.be\.' tests/
rg --type typescript 'expect\(.+\)\.have\.' tests/

Length of output: 259


Script:

#!/bin/bash
# Description: Check for Chai-specific assertion styles in test files

# Test: Search for common Chai assertion patterns in .ts and .tsx files
rg --glob "*.ts" 'expect\(.+\)\.to\.' tests/
rg --glob "*.ts" 'expect\(.+\)\.be\.' tests/
rg --glob "*.ts" 'expect\(.+\)\.have\.' tests/
rg --glob "*.tsx" 'expect\(.+\)\.to\.' tests/
rg --glob "*.tsx" 'expect\(.+\)\.be\.' tests/
rg --glob "*.tsx" 'expect\(.+\)\.have\.' tests/

Length of output: 304172

tests/src/math/MathUtil.test.ts (2)

2-2: LGTM: Import statement updated correctly for Vitest

The import statement has been properly updated to use Vitest instead of Chai. The explicit import of describe and it is a good practice for clarity.


Line range hint 1-38: Overall assessment: Successfully migrated to Vitest

The test file has been successfully updated to use Vitest instead of Chai. The core functionality of the tests remains intact, which is crucial. The suggestions provided earlier about using Vitest's native assertion style and enhancing test descriptions are optional improvements that could be considered for better readability and maintainability.

Great job on smoothly transitioning this test file to the new testing framework!

tests/src/core/material/PBRMaterial.test.ts (4)

3-3: LGTM: Successfully transitioned to Vitest.

The import statement has been correctly updated to use Vitest instead of Chai. This change aligns with the overall goal of transitioning the testing framework.


5-5: LGTM: Describe block remains correct.

The describe block syntax is compatible with both Chai and Vitest, so no changes were needed here. This ensures the test structure remains consistent.


7-7: LGTM: Correctly updated to Vitest's beforeAll.

The "before" function has been appropriately replaced with "beforeAll", which is the correct syntax for Vitest. This change maintains the same functionality of running the setup once before all tests in the suite.


Line range hint 1-48: Overall: Successful transition to Vitest with no logic changes.

The file has been successfully updated to use Vitest instead of Chai. The changes are limited to the import statement and the beforeAll function, with no modifications to the test logic or assertions. This suggests a smooth transition between the testing frameworks.

To ensure complete compatibility, please run the following command to verify that all tests pass with the new Vitest framework:

This will help confirm that the transition to Vitest hasn't introduced any unexpected issues.

✅ Verification successful

Verification Successful: Vitest Transition Confirmed.

All necessary dependencies and imports for Vitest are correctly set up in the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Run Vitest tests and check for any failures

# Test: Run Vitest tests
npm test -- tests/src/core/material/PBRMaterial.test.ts

# Check the exit code
if [ $? -eq 0 ]; then
  echo "All tests passed successfully."
else
  echo "Some tests failed. Please review the output above for details."
fi

Length of output: 283


Script:

#!/bin/bash
# Description: Check if 'vitest' is listed in package.json dependencies or devDependencies

# Using jq to parse package.json and search for 'vitest' in dependencies and devDependencies
if jq '.dependencies.vitest // .devDependencies.vitest' package.json > /dev/null; then
  echo "'vitest' is present in package.json."
else
  echo "'vitest' is not found in package.json. Please add 'vitest' as a dev dependency."
fi

Length of output: 156


Script:

#!/bin/bash
# Description: Verify that Vitest is correctly imported in PBRMaterial.test.ts

# Using rg to search for Vitest-specific imports in the test file
if rg 'from\s+["\']vitest["\']' tests/src/core/material/PBRMaterial.test.ts > /dev/null; then
  echo "Vitest is correctly imported in PBRMaterial.test.ts."
else
  echo "Vitest import is missing or incorrect in PBRMaterial.test.ts."
fi

Length of output: 93


Script:

#!/bin/bash
# Description: Verify that Vitest is correctly imported in PBRMaterial.test.ts

# Using rg to search for Vitest-specific imports in the test file
if rg 'from\s+["\']vitest["\']' tests/src/core/material/PBRMaterial.test.ts > /dev/null; then
  echo "Vitest is correctly imported in PBRMaterial.test.ts."
else
  echo "Vitest import is missing or incorrect in PBRMaterial.test.ts."
fi

Length of output: 93


Script:

#!/bin/bash
# Description: Verify that Vitest is correctly imported in PBRMaterial.test.ts

# Using rg to search for Vitest-specific imports in the test file
if rg "from\s+['\"]vitest['\"]" tests/src/core/material/PBRMaterial.test.ts > /dev/null; then
  echo "Vitest is correctly imported in PBRMaterial.test.ts."
else
  echo "Vitest import is missing or incorrect in PBRMaterial.test.ts."
fi

Length of output: 193

tests/src/core/material/UnlitMaterial.test.ts (2)

4-4: LGTM: Import statement updated correctly for Vitest.

The import statement has been properly updated to use Vitest instead of Chai. This change is consistent with the transition to the Vitest testing framework and includes all necessary functions for the test structure.


Line range hint 1-46: Summary: Successful transition to Vitest with room for minor enhancements.

The UnlitMaterial test file has been successfully updated to use Vitest. The changes are minimal and correct, ensuring that the existing tests continue to function as expected. The transition maintains the integrity of the test suite while adopting the new testing framework.

A few minor enhancements have been suggested to further leverage Vitest features and improve code style. These suggestions, if implemented, would result in a more idiomatic use of Vitest and potentially more efficient test execution.

Overall, the changes in this file are approved and ready for merging, with the optional improvements left to the discretion of the development team.

tests/src/core/DeviceLost.test.ts (2)

Line range hint 6-12: LGTM! Test setup is well-structured.

The test setup is well-organized and follows best practices for Vitest. The canvas creation and sizing are appropriate for WebGL testing, and the use of describe and it provides a clear structure for the test suite.


Line range hint 13-33: LGTM! Comprehensive engine and scene setup.

The engine and scene setup is well-structured and comprehensive. It includes all necessary elements for a basic 3D scene, which is appropriate for testing device loss and restoration. The use of async/await for engine creation is a good practice.

tests/src/core/material/PBRSpecularMaterial.test.ts (3)

4-4: LGTM: Successfully transitioned to Vitest framework

The import statement has been correctly updated to use Vitest instead of Chai. The additional imports (describe, beforeAll, it) are necessary for the Vitest framework and are appropriately used in the test suite.


6-6: LGTM: Improved code formatting

The formatting of the describe function call has been adjusted, improving consistency with modern JavaScript/TypeScript practices. This change enhances code readability without affecting functionality.


8-8: LGTM: Correctly updated lifecycle hook for Vitest

The before hook has been appropriately replaced with beforeAll, which is the Vitest equivalent. This change maintains the same functionality of setting up the test environment once before all tests run, while adhering to the Vitest framework's syntax.

tests/src/core/Transform.test.ts (2)

4-4: LGTM: Import statement updated to use Vitest.

The change from Chai to Vitest is consistent with the project's transition to a new testing framework. All imported functions are utilized in the test file, which is good practice.


Line range hint 1-52: Overall, the changes look good, but let's verify test execution.

The transition from Chai to Vitest has been implemented correctly, with minimal changes to the actual test logic. This preserves the original test coverage while potentially improving performance and integration with the project's tooling.

To ensure the tests still run correctly with the new framework, please run the following command and verify that all tests pass:

tests/src/core/Utils.test.ts (3)

2-2: LGTM: Import statement updated correctly for Vitest.

The import statement has been properly updated to use Vitest instead of Chai. The imported functions (describe, expect, and it) are appropriate for the test structure in this file.


Line range hint 4-78: LGTM: Test structure remains compatible with Vitest.

The existing test structure using describe and it is compatible with Vitest. No changes were needed for the test organization, which is a good sign that the transition to Vitest was smooth.


Line range hint 1-78: Summary: Successful transition to Vitest with minor improvement opportunities.

The transition from Chai to Vitest in this test file has been implemented correctly. The import statement has been updated appropriately, and the existing test structure and assertions remain compatible with Vitest. This smooth transition indicates that the change was well-executed and maintains the integrity of the test suite.

To further improve the test file:

  1. Consider adopting more idiomatic Vitest assertion styles as suggested earlier.
  2. Review if any Vitest-specific features could enhance these tests (e.g., snapshot testing, mocking capabilities).

Overall, great job on the framework transition!

tests/src/core/2d/text/Font.test.ts (3)

4-4: LGTM: Import statement updated correctly for Vitest.

The import statement has been properly updated to use Vitest instead of Chai. All imported functions are utilized in the test suite, which is in line with the refactoring objective.


10-10: LGTM: Lifecycle hook updated correctly for Vitest.

The 'before' hook has been appropriately changed to 'beforeAll', which is the correct syntax for Vitest. The setup logic within the hook remains unchanged, ensuring that the test behavior is preserved while adapting to the new testing framework.


59-59: LGTM: Teardown hook updated correctly for Vitest.

The 'after' hook has been correctly changed to 'afterAll', which is the appropriate syntax for Vitest. The teardown logic within the hook remains intact, ensuring that the test cleanup process is maintained while adapting to the new testing framework.

tests/src/math/SphericalHarmonics3.test.ts (3)

2-2: LGTM: Import statement updated correctly for Vitest.

The import statement has been properly updated to use Vitest instead of Chai. This change is consistent with the transition to the new testing framework.


31-32: Consistent formatting change applied.

The Float32Array values have been reformatted to a single line, consistent with the change in the "addLight" test case. This maintains consistency throughout the file.


43-44: LGTM: Consistent formatting maintained.

The array values have been reformatted to a single line, maintaining consistency with the previous test cases. This change doesn't affect the test logic and keeps the file style uniform.

package.json (4)

Line range hint 1-78: Summary of changes and recommendations

The changes in this package.json file consistently reflect a transition from Chai/Mocha to Vitest for testing. This transition includes:

  1. Simplified test scripts using Vitest.
  2. Removal of Chai, Mocha, and related dependencies.
  3. Addition of Vitest as a dev dependency.

These changes should streamline your testing setup and reduce package bloat. However, to ensure a smooth transition:

  1. Verify that all test files have been updated to use Vitest syntax.
  2. Check that TypeScript files are correctly handled in the new Vitest setup.
  3. Confirm that the Vitest version is compatible with your project's Node.js version and other dependencies.
  4. Run a full test suite to catch any issues that may have been introduced during the transition.

The changes look good overall, but please ensure all verification steps mentioned in the previous comments are completed to guarantee a successful transition to Vitest.


60-61: Verify complete migration from Chai/Mocha to Vitest

The removal of Chai, Mocha, and related type definitions (@types/chai, @types/chai-spies, @types/mocha, chai, chai-spies, floss) from devDependencies is consistent with the transition to Vitest. This change should reduce package bloat and simplify the project's dependencies.

However, it's crucial to ensure that all test files have been updated to use Vitest instead of the removed testing libraries.

Please run the following script to check for any remaining references to the removed testing libraries:

#!/bin/bash
# Check for remaining references to removed testing libraries

echo "Checking for references to removed testing libraries..."

libraries=("chai" "mocha" "floss")

for lib in "${libraries[@]}"; do
  echo "Searching for references to $lib..."
  rg -i "$lib" --type ts --type js
done

echo "Search complete. If no results were shown, all references have been removed."

If any references are found, update those files to use Vitest instead. This will ensure a smooth transition and prevent any potential runtime errors during testing.


60-61: Verify Vitest compatibility and consider pinning the version

The addition of Vitest (version ^2.1.3) to devDependencies is consistent with the changes in the scripts section. However, there are a few points to consider:

  1. Version Compatibility: Ensure that this version of Vitest is compatible with your project's Node.js version and other dependencies.

  2. Version Pinning: The current version specification (^2.1.3) allows for compatible updates. Consider if you want to pin to a specific version for consistency across all environments.

To verify compatibility and check for any warnings, run the following:

#!/bin/bash
# Verify Vitest compatibility

echo "Checking Node.js version..."
node --version

echo "Installing dependencies..."
npm install

echo "Running Vitest version check..."
npx vitest --version

echo "Running a test to check for any compatibility issues..."
npm test

If you encounter any warnings or errors, consider updating the Vitest version or addressing any compatibility issues with other dependencies.


8-9: Verify the impact of simplified test script and new coverage script

The changes to the scripts section introduce a simpler test command and a new coverage script:

  1. The test script has been simplified to just "vitest". This removes specific configurations like TS_NODE_PROJECT and the test path. Ensure that:

    • Vitest is correctly configured to handle TypeScript files.
    • The default test discovery in Vitest matches your project structure.
    • Any environment-specific settings (like those previously set by cross-env) are properly handled.
  2. A new coverage script has been added, which is a positive addition for tracking test coverage.

To ensure these changes don't negatively impact your testing process, please run the following verification steps:

If any issues are encountered, you may need to adjust Vitest configuration or update test files to match the new setup.

tests/src/math/BoundingFrustum.test.ts (2)

Line range hint 4-95: LGTM! Run the test suite to verify functionality.

The existing test structure and assertions are compatible with Vitest, requiring no further changes. The test logic remains intact, which is good for maintaining consistency.

To ensure that the transition to Vitest hasn't introduced any issues, please run the following script to execute the test suite:

#!/bin/bash
# Description: Run the Vitest test suite for BoundingFrustum

# Test: Execute Vitest for the BoundingFrustum test file
npx vitest run tests/src/math/BoundingFrustum.test.ts

2-2: LGTM! Verify test structure compatibility.

The import statement has been successfully updated to use Vitest instead of Chai. This change aligns with the project's transition to the Vitest testing framework.

To ensure that the test structure is compatible with Vitest, please run the following script:

tests/src/core/resource/ResourceManager.test.ts (2)

70-70: LGTM! Spy functionality updated correctly.

The transition from Chai's spy to Vitest's vi.spyOn is implemented correctly, maintaining the same functionality of monitoring the glTFLoader.load method.


1-4: LGTM! Transition to Vitest implemented correctly.

The import statements and lifecycle hooks have been updated appropriately to transition from Chai to Vitest. The change from before to beforeAll is correct for Vitest syntax.

To ensure all imports are necessary, run the following script:

Also applies to: 8-8

✅ Verification successful

All imported entities are correctly utilized in the test file. No unnecessary imports detected.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify usage of imported entities

# Test: Check usage of imported entities
rg --type typescript -w 'ResourceManager|Texture2D|WebGLEngine|vi|describe|beforeAll|beforeEach|expect|it' tests/src/core/resource/ResourceManager.test.ts

Length of output: 191


Script:

#!/bin/bash
# Description: Verify usage of imported entities

# Test: Check usage of imported entities
rg --type ts --word-regexp 'ResourceManager|Texture2D|WebGLEngine|vi|describe|beforeAll|beforeEach|expect|it' tests/src/core/resource/ResourceManager.test.ts

Length of output: 1627

tests/src/core/material/BaseMaterial.test.ts (3)

3-3: LGTM: Import statement updated correctly for Vitest

The import statement has been properly updated to use Vitest instead of Chai. This change is consistent with the PR objective of transitioning the testing framework.


7-7: LGTM: Lifecycle hook updated correctly for Vitest

The 'before' hook has been correctly replaced with 'beforeAll', which is the appropriate Vitest equivalent. This change maintains the same functionality while adhering to Vitest's syntax.


Line range hint 1-89: Overall changes look good: Successful transition to Vitest

The changes in this file successfully transition the test suite from Chai to Vitest without altering the core logic or assertions of the tests. The modifications are minimal and focused, which reduces the risk of introducing errors. The test suite should function the same way as before, but now using Vitest's syntax and features.

Here's a summary of the changes:

  1. Updated import statement to use Vitest.
  2. Changed the 'before' hook to 'beforeAll'.

These changes align well with the PR objective of standardizing the testing approach across the project.

.github/workflows/ci.yml (2)

Line range hint 1-110: Overall, the CI workflow changes look good.

The modification to use npm run coverage instead of npm run test-cov is the only change in this file. It's consistent with the PR's objective of refactoring tests and standardizing the testing approach. The rest of the workflow remains unchanged, maintaining the existing CI/CD pipeline structure.

Remember to test the entire CI workflow to ensure that this change doesn't negatively impact the coverage reporting or any other parts of the pipeline.


71-71: LGTM. Verify the new 'coverage' script and update documentation if needed.

The change from npm run test-cov to npm run coverage aligns with the PR's objective of refactoring tests. This modification appears to be part of standardizing the testing approach.

To ensure this change doesn't introduce any issues:

  1. Verify that the 'coverage' script exists in the package.json file and produces the expected output for Codecov.
  2. Update any relevant documentation that might reference the old 'test-cov' command.

You can use the following script to check the package.json file:

This script will help ensure that the new 'coverage' script is properly set up and that there are no lingering references to the old 'test-cov' command in the project.

✅ Verification successful

Verified the 'coverage' script exists in package.json and there are no remaining references to 'test-cov'.

The change from npm run test-cov to npm run coverage has been successfully implemented without introducing any issues.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the existence of the 'coverage' script in package.json

# Test: Check if 'coverage' script exists in package.json
jq '.scripts.coverage' package.json

# If the output is null, the script doesn't exist
if [ "$(jq '.scripts.coverage' package.json)" == "null" ]; then
  echo "Warning: 'coverage' script not found in package.json"
fi

# Also check for any remaining references to 'test-cov'
grep -r "test-cov" .

Length of output: 163

tests/src/math/Color.test.ts (2)

2-2: LGTM: Import statement updated correctly for Vitest

The import statement has been properly updated to use Vitest instead of Chai. The inclusion of describe and it functions is correct and follows Vitest conventions.


Line range hint 1-101: LGTM: Smooth transition to Vitest

The transition from Chai to Vitest has been implemented correctly. The test suite structure and assertions remain unchanged, which is good for maintaining consistency. However, it's crucial to verify that all tests still pass with Vitest, as some subtle differences in assertion behavior might exist.

Please run the following command to ensure all tests pass with the new Vitest setup:

This will run the tests in the tests/src/math directory and display the results, helping to verify that the transition to Vitest hasn't introduced any unexpected issues.

tests/src/rhi-webgl/WebGLEngine.test.ts (3)

4-4: LGTM: Vitest import statement added correctly.

The import statement for Vitest functions has been added correctly, aligning with the transition from Chai to Vitest testing framework.


85-88: LGTM: Test case updated to use Vitest syntax.

The "engine device lost" test case has been successfully updated to use Vitest:

  1. Spy creation now uses vi.fn() instead of Chai's spy.
  2. Assertion syntax has been updated to use toHaveBeenCalledTimes().

These changes are consistent with the transition from Chai to Vitest.

Also applies to: 97-97


Line range hint 1-107: Overall changes look good: Successful transition to Vitest.

The file has been successfully updated to use Vitest instead of Chai:

  1. Import statements have been updated to import Vitest functions.
  2. Spy creation now uses Vitest's vi.fn().
  3. Assertion syntax has been updated to use Vitest's methods.

The overall structure and logic of the tests remain intact, ensuring that the functionality being tested hasn't changed. This transition should improve consistency with other test files using Vitest.

To ensure all Chai references have been removed, run the following command:

If this command returns no results, it confirms that all Chai references have been successfully removed.

tests/src/core/texture/Texture2D.test.ts (1)

14-14: LGTM: before hook correctly updated to beforeAll.

The before hook has been appropriately updated to beforeAll, which is the correct Vitest equivalent. This change maintains the original setup logic while aligning with the Vitest framework.

tests/src/core/material/PBRBaseMaterial.test.ts (2)

4-4: LGTM: Import statement updated correctly

The import statement has been properly updated to include the necessary Vitest testing utilities (describe, beforeAll, expect, and it). This change aligns with the transition from Chai to Vitest as the testing framework.


6-6: LGTM: Proper use of describe block

The introduction of the describe block to group the test cases is a good practice. It enhances the structure and readability of the test suite, which is in line with modern testing conventions used in Vitest.

tests/src/core/TextRenderer.test.ts (2)

3-3: LGTM: Import statement updated correctly for Vitest.

The import statement has been properly updated to use Vitest instead of Chai. All necessary functions (describe, it, expect, and beforeEach) are imported, which aligns with the test suite structure.


Line range hint 5-95: LGTM: Test suite structure preserved. Verify assertion compatibility.

The overall structure of the test suite has been maintained during the transition to Vitest, which is excellent. The individual tests continue to cover various aspects of the TextRenderer component, including constructor behavior, text setting, font size, line spacing, wrapping, emoji handling, and text wrapping scenarios.

While the transition appears seamless, it's crucial to ensure that all assertions are still valid and working as expected with Vitest, as some subtle differences might exist between Chai and Vitest assertion styles.

To verify the compatibility of assertions, please run the test suite and confirm that all tests pass as expected. Additionally, you may want to review the Vitest documentation to ensure that the assertion syntax used (e.g., expect(...).to.eq(...)) is the most idiomatic way to write assertions in Vitest.

tests/src/core/base/EventDispatcher.test.ts (6)

2-2: LGTM: Import statement updated for Vitest

The import statement has been correctly updated to include the necessary Vitest functions (vi, describe, expect, it). This change aligns with the transition from Chai to Vitest testing framework.


20-21: LGTM: Test case updated to use Vitest syntax

The "dispatch event" test case has been successfully updated to use Vitest:

  1. Mock functions are now created using vi.fn() instead of chai.spy.
  2. Assertions have been updated to use Vitest's expect().toHaveBeenCalledTimes() syntax.

These changes maintain the original test logic while adapting to the new testing framework.

Also applies to: 25-25, 28-29


33-34: LGTM: "once" test case updated to Vitest syntax

The "once" test case has been correctly updated to use Vitest:

  1. Mock functions are now created using vi.fn().
  2. Assertions have been updated to use Vitest's expect().toHaveBeenCalledTimes() syntax.

These changes maintain the original test logic while adapting to the new testing framework.

Also applies to: 38-38, 45-46


53-54: LGTM: "off event in listener" test case updated to Vitest syntax

The "off event in listener" test case has been successfully updated to use Vitest:

  1. Mock functions are now created using vi.fn().
  2. Assertions have been updated to use Vitest's expect().toHaveBeenCalledTimes() syntax.

These changes maintain the original test logic while adapting to the new testing framework.

Also applies to: 61-62


67-68: LGTM: "off event" test case updated to Vitest syntax

The "off event" test case has been correctly updated to use Vitest:

  1. Mock functions are now created using vi.fn().
  2. Assertions have been updated to use Vitest's expect().toHaveBeenCalledTimes() syntax.

These changes maintain the original test logic while adapting to the new testing framework.

Also applies to: 72-72


78-81: LGTM: "call event in a callback" test case updated to Vitest syntax

The "call event in a callback" test case has been successfully updated to use Vitest:

  1. Mock functions are now created using vi.fn().
  2. Assertions have been updated to use Vitest's expect().toHaveBeenCalledTimes() syntax.

These changes maintain the original test logic while adapting to the new testing framework.

Also applies to: 87-88

tests/src/core/physics/PhysicsMaterial.test.ts (2)

4-4: LGTM: Import statement updated to use Vitest

The import statement has been correctly updated to use Vitest instead of Chai. This change is consistent with the project's transition to Vitest and includes all necessary functions (describe, beforeAll, expect, and it) for the test suite.


9-9: LGTM: Lifecycle method updated to use beforeAll

The lifecycle method has been correctly updated from before to beforeAll, which is the appropriate syntax for Vitest. This change maintains the same functionality (running setup code once before all tests) while ensuring compatibility with the new testing framework.

tests/src/core/material/BlinnPhongMaterial.test.ts (2)

4-4: LGTM: Import statement updated correctly

The import statement has been successfully updated to use Vitest instead of Chai. This change aligns with the overall transition to the Vitest testing framework.


6-8: LGTM: Test suite structure updated correctly

The test suite structure has been properly updated to use Vitest:

  1. The describe function is now correctly used from the Vitest import.
  2. The before hook has been appropriately changed to beforeAll, which maintains the same functionality in Vitest.

These changes ensure that the test suite structure remains consistent while transitioning to the new testing framework.

tests/src/shader-lab/ShaderValidate.ts (2)

Line range hint 1-138: No further changes required in this file.

After scanning the entire file, I can confirm that no additional modifications are necessary. The existing expect assertions are compatible with Vitest, and the core functionality of shader validation and parsing remains intact.


4-4: LGTM: Import statement updated correctly.

The change from Chai to Vitest for the expect import is consistent with the PR objectives. This modification should maintain the existing test functionality while transitioning to the new testing framework.

To ensure a complete transition, please run the following script to check for any remaining Chai imports or configurations:

✅ Verification successful

Verified: No remaining Chai imports or configurations found.

All instances of Chai imports and configurations have been successfully removed from the codebase. The transition to Vitest has been correctly implemented, and no residual Chai-related code was detected.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for remaining Chai imports or configurations

# Test: Search for Chai imports
echo "Searching for Chai imports:"
rg --type typescript 'from ["\']chai["\']'

# Test: Search for Chai configurations in package.json or test setup files
echo "Searching for Chai configurations:"
rg --type json '"chai":'
rg --type typescript 'chai\.(use|config)'

Length of output: 159


Script:

#!/bin/bash
# Description: Check for remaining Chai imports or configurations

# Test: Search for Chai imports
echo "Searching for Chai imports:"
rg --type typescript 'from ["\']chai["\']'

# Test: Search for Chai configurations in package.json or test setup files
echo "Searching for Chai configurations:"
rg --type json '"chai":'
rg --type typescript 'chai\.(use|config)'

Length of output: 159


Script:

#!/bin/bash
# Description: Check for remaining Chai imports or configurations

# Test: Search for Chai imports
echo "Searching for Chai imports:"
rg --type typescript "from ['\"]chai['\"]"

# Test: Search for Chai configurations in package.json or test setup files
echo "Searching for Chai configurations:"
rg --type json '"chai":'
rg --type typescript 'chai\.(use|config)'

Length of output: 333


Script:

#!/bin/bash
# Description: Check for remaining Chai imports or configurations

# Test: Search for Chai imports in TypeScript files
echo "Searching for Chai imports:"
rg --glob "*.ts" --glob "*.tsx" "from ['\"]chai['\"]"

# Test: Search for Chai configurations in package.json or test setup files
echo "Searching for Chai configurations:"
rg --type json '"chai":'
rg --glob "*.ts" --glob "*.tsx" "chai\.(use|config)"

Length of output: 285

tests/src/core/material/Material.test.ts (2)

4-4: LGTM: Updated import statement for Vitest

The import statement has been correctly updated to use Vitest instead of Chai. This change is consistent with the transition to the Vitest testing framework and includes the necessary test utilities.


Line range hint 12-95: LGTM: Test logic preserved

The core logic of the test cases has been maintained, ensuring consistent test coverage. The use of expect for assertions remains compatible with the new Vitest framework.

tests/src/core/AssetPromise.test.ts (4)

2-2: LGTM: Import statement updated correctly for Vitest

The import statement has been properly updated to use Vitest instead of Chai. The necessary functions (describe, expect, and it) are correctly imported from Vitest.


Line range hint 4-156: LGTM: Test structure maintained during framework transition

The overall test structure using describe and it has been maintained during the transition to Vitest. The existing assertions using expect syntax remain compatible with Vitest, requiring no changes. This approach ensures that the original test logic and coverage are preserved.


Line range hint 11-156: LGTM: Async test cases properly maintained

The async test cases using async/await syntax have been correctly maintained during the transition to Vitest. This approach ensures that asynchronous behavior is properly tested without requiring changes to the test structure.


Line range hint 4-156: Comprehensive test coverage maintained

The test suite demonstrates thorough coverage of the AssetPromise functionality, including basic operations (constructor, resolve, reject), chaining (then, catch, finally), advanced features (cancel, progress), and static methods (AssetPromise.all). Edge cases, such as empty arrays in AssetPromise.all, are also addressed. This comprehensive coverage helps ensure the reliability of the AssetPromise implementation.

tests/src/core/texture/RenderTarget.test.ts (4)

3-3: LGTM: Import statement updated correctly.

The import statement has been successfully updated to use Vitest instead of Chai, importing all necessary functions (describe, beforeAll, beforeEach, expect, it). This change aligns with the transition to the Vitest testing framework.


18-18: LGTM: Lifecycle hook updated correctly.

The before hook has been correctly replaced with beforeAll, which is the appropriate lifecycle hook in Vitest. The logic inside the hook remains unchanged, ensuring that the test setup is preserved.


Line range hint 41-44: Please clarify the status of commented-out test cases.

Several test cases have been commented out in this file. While this might be temporary due to the framework transition, it's important to address these to maintain test coverage. Could you please:

  1. Clarify the reason for commenting out these test cases?
  2. If they are still relevant, consider updating them to work with Vitest.
  3. If they are no longer needed, consider removing them entirely.
  4. If they are pending updates, please add TODO comments explaining the required changes.

Ensuring all test cases are either active or have a clear reason for being disabled will help maintain the integrity of the test suite.

Also applies to: 47-50, 53-56, 71-78, 88-92


Line range hint 1-118: Overall, good transition to Vitest with minor improvements needed.

The test file has been successfully updated to use Vitest instead of Chai. The changes are mostly correct and maintain the original test logic. Here's a summary of the review:

  1. Import statements and lifecycle hooks have been correctly updated.
  2. Most assertions have been properly transitioned to Vitest syntax.
  3. Some minor consistency improvements can be made in assertion syntax.
  4. Clarification is needed regarding the commented-out test cases.

Please address the suggestions in the previous comments to further improve the test suite. Once these are resolved, the transition to Vitest will be complete and the test coverage will be maintained.

tests/src/core/MeshRenderer.test.ts (3)

12-12: LGTM! Correct usage of Vitest's beforeAll hook.

The change from 'before' to 'beforeAll' is appropriate for the Vitest framework. This ensures that the setup code runs once before all tests in the suite, which is consistent with the previous behavior.


Line range hint 1-129: LGTM! Comprehensive test coverage. Verify complete feature coverage.

The test suite provides good coverage of MeshRenderer functionality, including key areas such as mesh assignment, vertex color enabling, bounding box calculations, cloning, and destruction.

To ensure we have complete coverage, let's verify if all MeshRenderer features are tested:

#!/bin/bash
# Description: Check for complete MeshRenderer feature coverage

# Test: Extract MeshRenderer methods and properties
ast-grep --lang typescript --pattern $'class MeshRenderer {
  $$$
  $_($$_) {
    $$$
  }
  $$$
}' src/core/MeshRenderer.ts

# Test: Compare with tested features
rg --type typescript -e 'it\(' tests/src/core/MeshRenderer.test.ts

Please review the output to identify any untested features or methods.


Line range hint 29-129: LGTM! Assertions remain consistent. Consider leveraging Vitest-specific features.

The test assertions have been successfully transitioned to Vitest without requiring changes. This maintains the readability and consistency of the tests.

To ensure we're making the most of Vitest, let's verify if there are any Vitest-specific features that could enhance our tests:

tests/src/core/SkinnedMeshRenderer.test.ts (1)

4-4: LGTM: Import statement updated correctly for Vitest.

The import statement has been updated to include the necessary functions from Vitest, which aligns with the transition from Chai to Vitest as mentioned in the summary.

tests/src/core/texture/TextureCubeMap.test.ts (2)

3-3: LGTM: Import statement updated correctly for Vitest.

The import statement has been properly updated to include the necessary functions from Vitest (describe, beforeAll, beforeEach, expect, it). This change aligns with the transition from Chai to Vitest as mentioned in the summary.


15-15: Verify impact of lifecycle hook change.

The change from before to beforeAll alters when the setup code is executed. beforeAll runs once before all tests in the describe block, while before (in Chai) ran before each test. This could impact test isolation if tests were relying on a fresh setup for each test case.

Please verify that this change doesn't introduce any unintended side effects in your test suite. If test isolation is required, consider using beforeEach instead.

To help verify this change, you can run the following command to check for any usage of shared state that might be affected:

✅ Verification successful

Re-running verification with corrected file type.


Lifecycle hook change verified safely.

No variables defined in beforeAll are modified within individual tests, ensuring that switching from before to beforeAll does not introduce unintended side effects related to test isolation.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for variables defined in beforeAll that are modified in individual tests
rg --type typescript 'beforeAll\(' tests/src/core/texture/TextureCubeMap.test.ts -A 10 | rg '(let|var) \w+' | cut -d' ' -f2 | xargs -I {} rg --type typescript '\b{}\b.*=' tests/src/core/texture/TextureCubeMap.test.ts

Length of output: 255


Script:

#!/bin/bash
# Search for variables defined in beforeAll that are modified in individual tests
rg --type ts 'beforeAll\(' tests/src/core/texture/TextureCubeMap.test.ts -A 10 | rg '(let|var) (\w+)' | cut -d' ' -f3 | xargs -I {} rg --type ts '\b{}\b\s*=' tests/src/core/texture/TextureCubeMap.test.ts

Length of output: 207

tests/src/core/physics/CharacterController.test.ts (4)

13-13: LGTM: Import statement updated correctly.

The import statement has been properly updated to include the necessary functions from Vitest (describe, beforeAll, expect, it). This change aligns with the transition from Chai to Vitest testing framework.


19-19: LGTM: before hook correctly replaced with beforeAll.

The before hook has been appropriately replaced with beforeAll, which is the correct equivalent in Vitest. This change ensures that the setup runs once before all tests in the suite, maintaining the original behavior.


Line range hint 1-186: Overall: Successful transition to Vitest with maintained test integrity.

The changes in this file successfully transition the test suite from Chai to Vitest while maintaining the integrity of the existing tests. Key points:

  1. Import statements have been correctly updated to use Vitest functions.
  2. The before hook has been appropriately replaced with beforeAll.
  3. Core test logic and assertions remain unchanged, preserving the original test coverage.

These changes align with the PR objective of refactoring the testing framework. The transition appears smooth and doesn't introduce any apparent issues in the existing test cases.

However, please ensure that the timeout handling for potentially long-running tests has been addressed, as mentioned in the previous comment.


Line range hint 19-31: Verify timeout handling for long-running tests.

The timeout setting (this.timeout(10000);) has been removed. While Vitest handles timeouts differently from Mocha/Chai, it's important to ensure that long-running tests are still accommodated.

Please confirm that:

  1. The default Vitest timeout is sufficient for these tests.
  2. If needed, a new timeout mechanism has been implemented (e.g., using Vitest's test.timeout() or a global setting).

You can use the following script to check for any custom timeout settings in the test files:

✅ Verification successful

Verify that Vitest's default timeout settings are sufficient for your tests.

No custom timeout settings were found in the test files or global configuration. Ensure that your tests complete within Vitest's default timeout. If you encounter any timeout issues, consider implementing a new timeout mechanism using Vitest's test.timeout() or updating the global configuration.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for custom timeout settings in test files

# Search for Vitest timeout settings
echo "Searching for Vitest timeout settings:"
rg --type typescript 'test\.timeout\(' tests/
rg --type typescript 'it\.timeout\(' tests/

# Search for global Vitest config
echo "Searching for global Vitest config:"
rg --type typescript 'defineConfig.*timeout' -g 'vitest.config.*'

Length of output: 434


Script:

#!/bin/bash
# Description: Check for custom timeout settings in test files by targeting .ts and .tsx extensions

# Search for Vitest timeout settings in .ts files
echo "Searching for Vitest timeout settings in .ts files:"
rg 'test\.timeout\(' -g '*.ts' tests/
rg 'it\.timeout\(' -g '*.ts' tests/

# Search for Vitest timeout settings in .tsx files
echo "Searching for Vitest timeout settings in .tsx files:"
rg 'test\.timeout\(' -g '*.tsx' tests/
rg 'it\.timeout\(' -g '*.tsx' tests/

# Search for global Vitest config with common config filenames
echo "Searching for global Vitest config in common config files:"
rg 'defineConfig.*timeout' -g 'vitest.config.*' .

Length of output: 564

tests/src/core/Scene.test.ts (3)

3-3: LGTM: Import statement updated correctly.

The import statement has been successfully updated to use Vitest instead of Chai, including all necessary functions (describe, beforeAll, beforeEach, expect, it).


8-8: LGTM: Test setup updated correctly.

The before hook has been appropriately changed to beforeAll, which is the correct syntax for Vitest. The function is now correctly marked as async, which is a good practice for handling asynchronous setup operations.


Line range hint 1-236: Verify test assertions and overall functionality.

While the transition to Vitest appears smooth with minimal changes required, it's important to ensure that all assertions are still working as expected. Please run the entire test suite to confirm that all tests pass and behave as intended with the new testing framework.

To verify the test suite, run the following command:

If any issues are found, please address them and update the tests accordingly.

tests/src/math/Vector3.test.ts (1)

2-2: LGTM! Verify Vitest compatibility across the test suite.

The import statement has been correctly updated to use Vitest instead of Chai. This change is appropriate and aligns with the transition to the Vitest testing framework.

To ensure a smooth transition, please run the following script to verify that all test files in the project have been updated to use Vitest:

This script will help identify any remaining Chai imports, verify Vitest imports, and check for test files that might be missing Vitest imports.

✅ Verification successful

Vitest Compatibility Verified Across the Test Suite.

All test files have been successfully updated to use Vitest. No remaining Chai imports were found, ensuring a complete transition to the Vitest testing framework.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any remaining Chai imports in test files

# Search for Chai imports in test files
echo "Checking for remaining Chai imports in test files:"
rg --type typescript 'import.*from.*chai' -g '*.test.ts'

# Search for Vitest imports in test files
echo "Verifying Vitest imports in test files:"
rg --type typescript 'import.*from.*vitest' -g '*.test.ts'

# Check if any test files are missing Vitest imports
echo "Checking for test files missing Vitest imports:"
fd -e ts -e tsx '.*\.test\.(ts|tsx)$' | xargs rg --files-without-match 'import.*from.*vitest'

Length of output: 590


Script:

#!/bin/bash
# Description: Check for any remaining Chai imports in test files

# Search for Chai imports in test files
echo "Checking for remaining Chai imports in test files:"
rg 'import\s+\{[^}]*\}\s+from\s+["\']chai["\']' --glob '*.test.ts' --glob '*.test.tsx'

# Search for Vitest imports in test files
echo "Verifying Vitest imports in test files:"
rg 'import\s+\{[^}]*\}\s+from\s+["\']vitest["\']' --glob '*.test.ts' --glob '*.test.tsx'

# Check if any test files are missing Vitest imports
echo "Checking for test files missing Vitest imports:"
fd --extension ts --extension tsx -g '*.test.ts' -g '*.test.tsx' | xargs rg --files-without-match 'import\s+\{[^}]*\}\s+from\s+["\']vitest["\']'

Length of output: 205


Script:

#!/bin/bash
# Description: Check for any remaining Chai imports in test files

# Search for Chai imports in test files
echo "Checking for remaining Chai imports in test files:"
rg "import\s+\{[^}]*\}\s+from\s+['\"]chai['\"]" --glob '*.test.ts' --glob '*.test.tsx'

# Search for Vitest imports in test files
echo "Verifying Vitest imports in test files:"
rg "import\s+\{[^}]*\}\s+from\s+['\"]vitest['\"]" --glob '*.test.ts' --glob '*.test.tsx'

# Check if any test files are missing Vitest imports
echo "Checking for test files missing Vitest imports:"
fd --extension ts --extension tsx -g '*.test.ts' -g '*.test.tsx' | xargs rg --files-without-match "import\s+\{[^}]*\}\s+from\s+['\"]vitest['\"]"

Length of output: 68700


Script:

#!/bin/bash
# Description: Check for any remaining Chai imports in test files

# Search for Chai imports in test files
echo "Checking for remaining Chai imports in test files:"
rg "import\s+\{[^}]*\}\s+from\s+['\"]chai['\"]" --glob '*.test.ts' --glob '*.test.tsx'

# Search for Vitest imports in test files
echo "Verifying Vitest imports in test files:"
rg "import\s+\{[^}]*\}\s+from\s+['\"]vitest['\"]" --glob '*.test.ts' --glob '*.test.tsx'

# Check if any test files are missing Vitest imports
echo "Checking for test files missing Vitest imports:"
fd --extension ts --extension tsx -g '*.test.ts' -g '*.test.tsx' | xargs rg --files-without-match "import\s+\{[^}]*\}\s+from\s+['\"]vitest['\"]"

Length of output: 68700


Script:

#!/bin/bash
# Description: Check for any remaining Chai imports in test files

# Search for Chai imports in test files
echo "Checking for remaining Chai imports in test files:"
rg "import\s+\{[^}]*\}\s+from\s+['\"]chai['\"]" --glob '*.test.ts' --glob '*.test.tsx'

# Search for Vitest imports in test files
echo "Verifying Vitest imports in test files:"
rg "import\s+\{[^}]*\}\s+from\s+['\"]vitest['\"]" --glob '*.test.ts' --glob '*.test.tsx'

# Check if any test files are missing Vitest imports
echo "Checking for test files missing Vitest imports:"
fd --extension ts --extension tsx -g '{*.test.ts,*.test.tsx}' | xargs rg --files-without-match "import\s+\{[^}]*\}\s+from\s+['\"]vitest['\"]"

Length of output: 7342

tests/src/core/mesh/BufferMesh.test.ts (3)

15-15: LGTM: Import statement updated for Vitest

The import statement has been correctly updated to use Vitest instead of Chai. This change is consistent with the transition to the new testing framework.


21-21: LGTM: Lifecycle hook updated for Vitest

The 'before' hook has been correctly updated to 'beforeAll', which is the equivalent in Vitest. This change maintains the original setup logic while adapting to the new testing framework.


Line range hint 1-238: Verify test behavior after framework transition

The transition from Chai to Vitest has been implemented correctly, with appropriate updates to imports and lifecycle hooks. The core test logic and assertions remain unchanged, which is good for maintaining test coverage.

However, to ensure the transition hasn't introduced any subtle changes in test behavior:

  1. Run the test suite and compare the results with the previous version.
  2. Pay special attention to any asynchronous tests or complex assertions, as different testing frameworks may handle these slightly differently.
  3. Verify that all tests pass and that no new warnings or errors are introduced.

To assist in this verification, you can run the following script:

This script will run the tests, capture the output, and provide a quick check for any failures or errors. Please review the output carefully to ensure the test behavior matches expectations after the framework transition.

tests/src/core/Sprite.test.ts (2)

Line range hint 18-185: Suggestion: Update assertion syntax for Vitest compatibility.

While the overall test structure is compatible with Vitest, some assertions are still using Chai-specific syntax. To fully leverage Vitest and ensure consistency, consider updating the following assertion patterns throughout the file:

  1. Replace to.eq with .toBe() for primitive values or .toEqual() for objects.
  2. Replace to.deep.include and to.deep.eq with .toEqual().

For example:

// Before
expect(sprite.texture).to.eq(null);
expect(sprite.region).to.deep.include({ x: 0, y: 0, width: 1, height: 1 });

// After
expect(sprite.texture).toBe(null);
expect(sprite.region).toEqual({ x: 0, y: 0, width: 1, height: 1 });

These changes will make the tests more idiomatic to Vitest while maintaining the same functionality.

To assist in identifying all instances that need updating, you can run the following script:

#!/bin/bash
# Description: Identify Chai-specific assertions in the test file

# Test: Search for Chai-specific assertion patterns
rg --type typescript 'expect\(.+\)\.to\.(eq|deep\.include|deep\.eq)' tests/src/core/Sprite.test.ts

4-4: LGTM: Import statement updated correctly for Vitest.

The import statement has been successfully updated to use Vitest instead of Chai. The change includes importing additional necessary testing utilities (describe, beforeEach, it) which are used throughout the test suite. This modification aligns with the transition to Vitest as the new testing framework.

To ensure all Chai imports have been removed and replaced with Vitest, run the following script:

tests/src/math/Matrix3x3.test.ts (2)

2-2: LGTM: Import statement updated correctly for Vitest.

The change from Chai to Vitest is implemented correctly in the import statement. This is consistent with the project's transition to the Vitest testing framework.

To ensure the transition is complete, please verify that the project's test runner configuration (e.g., in package.json or a separate Vitest config file) has been updated to use Vitest. You can run the following command to check:

This will search for "vitest" in all files, helping to confirm that the configuration has been updated project-wide.


Line range hint 4-288: LGTM: Test structure and assertions remain consistent with Vitest.

The transition to Vitest has been implemented smoothly, with no changes required to the existing test structure or assertions. This indicates good compatibility between the previous testing setup and Vitest.

To ensure that all tests are functioning correctly with the new framework, please run the entire test suite. You can typically do this with a command like:

or

depending on your project setup. This will verify that all tests pass successfully with Vitest.

tests/src/core/physics/ColliderShape.test.ts (3)

14-14: LGTM: Import statement updated correctly for Vitest.

The import statement has been successfully updated to use Vitest instead of Chai. All necessary functions (describe, beforeAll, beforeEach, expect, and it) are now imported from Vitest, which is consistent with the framework transition.


19-19: LGTM: Lifecycle hook updated correctly for Vitest.

The before hook has been appropriately replaced with beforeAll, which is consistent with Vitest's API. This change ensures that the setup code runs once before all tests, maintaining the intended behavior of the test suite.


Line range hint 1-228: Overall: Successful transition to Vitest with preserved test functionality.

The changes made to this file effectively transition the test suite from Chai to Vitest while maintaining the integrity of the tests. The import statements and lifecycle hooks have been correctly updated, and the core test logic remains intact.

To ensure the transition is complete and the tests are functioning as expected, please run the following verification script:

This script will run the specific test file with Vitest and verify that it passes without any errors, confirming the successful transition to the new testing framework.

tests/src/loader/KTX2Loader.test.ts (2)

4-4: LGTM: Import statement updated for Vitest

The import statement has been correctly updated to include the necessary functions from Vitest, which is in line with the transition from Mocha to Vitest as the testing framework.


107-109: LGTM: Teardown function updated for Vitest

The after hook has been correctly replaced with afterAll, which is the appropriate lifecycle hook in Vitest. The function logic remains unchanged, ensuring proper cleanup after the tests.

tests/src/core/mesh/PrimitiveMesh.test.ts (4)

4-4: LGTM: Import statement updated correctly for Vitest.

The import statement has been properly updated to use Vitest instead of Chai. The additional imports (describe, beforeAll, it) are necessary for the Vitest testing structure.


9-9: LGTM: Lifecycle hook updated correctly for Vitest.

The before hook has been appropriately replaced with beforeAll, which is the correct syntax for Vitest. This change maintains the same functionality of running the setup once before all tests in the suite.


Line range hint 1-224: Summary of changes and recommendations

  1. The transition from Chai to Vitest has been implemented correctly, with appropriate updates to import statements and lifecycle hooks.
  2. The core logic and structure of the tests remain unchanged, which is good for maintaining test coverage and functionality.
  3. The potential removal of a timeout setting for the "test limit vertex count" test case needs verification. Please refer to the previous comment for a script to check this change and its potential impact.

Overall, the changes appear to be in line with the PR objectives of refactoring the tests. However, ensure that all tests still pass and perform as expected after these changes, particularly paying attention to any tests that might have had timeout settings previously.


Line range hint 1-224: Verify the removal of the timeout setting.

The AI summary mentions that the timeout setting for the "test limit vertex count" test case has been removed. However, this change is not visible in the provided annotated code. Please confirm if this change was actually made and consider the following:

  1. If the timeout was removed, ensure that the test doesn't require an extended runtime that could lead to unintended test failures.
  2. If the test previously timed out occasionally, investigate the root cause and consider optimizing the test or adjusting the timeout instead of removing it entirely.

To confirm the timeout removal and its potential impact, please run the following script:

This script will help verify the removal of the timeout setting and provide information about the current runtime of the specific test.

tests/src/shader-lab/ShaderLab.test.ts (7)

187-190: LGTM! Asynchronous test implementation is correct.

The test case has been correctly updated to use asynchronous file reading. The use of await ensures that the shader content is fully loaded before validation.


192-196: LGTM! Asynchronous test implementation is correct.

The test case has been properly updated to use asynchronous file reading. The shader content is correctly awaited before validation.


198-202: LGTM! Asynchronous test implementation is correct.

The test case has been correctly updated to use asynchronous file reading. The shader content is properly awaited before validation.


204-208: LGTM! Asynchronous test implementation is correct.

The test case has been properly updated to use asynchronous file reading. The shader content is correctly awaited before validation.


210-214: LGTM! Asynchronous test implementation is correct.

The test case has been correctly updated to use asynchronous file reading. The shader content is properly awaited before validation.


216-220: LGTM! Asynchronous test implementation is correct.

The test case has been properly updated to use asynchronous file reading. The shader content is correctly awaited before validation.


222-226: LGTM! Asynchronous test implementation is correct.

The test case has been properly updated to use asynchronous file reading. The shader content is correctly awaited before validation.

tests/src/math/Quaternion.test.ts (2)

2-2: LGTM: Import statement updated correctly for Vitest.

The import statement has been successfully updated to use Vitest instead of Chai. The necessary functions (describe, expect, and it) are now imported from Vitest, which is correct for the new testing framework.


Line range hint 1-265: LGTM: Successful transition to Vitest with no changes required to existing tests.

The transition from Chai to Vitest has been implemented correctly. The existing tests remain unchanged and appear to be fully compatible with the new testing framework. This suggests that Vitest's API is sufficiently similar to Chai's for these tests.

To ensure the transition is complete:

Please run the following command to verify that all tests pass with the new Vitest setup:

If all tests pass, it confirms that the transition to Vitest is successful and hasn't introduced any compatibility issues.

🧰 Tools
🪛 Biome

[error] 4-4: Do not shadow the global "toString" property.

Consider renaming this variable. It's easy to confuse the origin of variables when they're named after a known global.

(lint/suspicious/noShadowRestrictedNames)

tests/src/math/BoundingBox.test.ts (2)

2-2: LGTM: Import statement updated correctly for Vitest.

The import statement has been properly updated to use Vitest instead of Chai. The addition of describe and it imports is correct for Vitest's test structure.


Line range hint 1-324: LGTM: Smooth transition to Vitest with minimal changes.

The file has been successfully transitioned to use Vitest with only the import statement requiring modification. The existing test structure and assertions are compatible with Vitest, which has allowed for a seamless transition without the need for extensive changes. This approach minimizes the risk of introducing errors during the framework switch.

A few points to note:

  1. The test structure using describe and it was already in place, which aligns well with Vitest's expectations.
  2. All assertions use the expect syntax, which is compatible with both Chai and Vitest, ensuring that the test logic remains intact.
  3. No modifications to test cases or assertions were required, preserving the original test coverage and behavior.
tests/src/core/mesh/BlendShape.test.ts (3)

4-4: LGTM: Import statement updated for Vitest

The import statement has been correctly updated to use Vitest instead of Chai. This change is consistent with the transition to the Vitest testing framework. The additional imports (describe, beforeAll, it) are necessary for structuring tests in Vitest.


9-9: LGTM: Setup function updated for Vitest

The setup function has been correctly updated from before to beforeAll, which is the appropriate lifecycle hook in Vitest. This change maintains the same functionality of running the setup once before all tests in the suite.


Line range hint 1-238: Verify test behavior after framework change

The transition from Chai to Vitest has been implemented correctly. The core test logic and assertions remain unchanged, which should maintain the same level of test coverage and effectiveness. However, it's important to verify that all tests still pass and behave as expected with the new framework.

To ensure the transition is complete and all tests are functioning correctly, please run the following command:

This will execute the tests using Vitest and help identify any potential issues that may have arisen from the framework change.

tests/src/core/input/InputManager.test.ts (3)

14-14: LGTM: Import statement updated correctly for Vitest.

The import statement has been properly updated to use Vitest instead of Chai. This change is consistent with the transition to the Vitest testing framework.


127-132: LGTM: Assertion syntax updated correctly for Vitest.

The assertion syntax has been properly updated from Chai to Vitest. The toHaveBeenCalledTimes(n) method is the correct Vitest equivalent of Chai's to.have.been.called.exactly(n). This change maintains the same test behavior while aligning with the Vitest framework.


138-143: LGTM: Assertion syntax consistently updated for Vitest.

The assertion syntax has been correctly updated to use Vitest's toHaveBeenCalledTimes(n) method. This change is consistent with the previous block and maintains the same test behavior while aligning with the Vitest framework.

tests/src/core/physics/Joint.test.ts (3)

13-13: LGTM: Correct import for Vitest framework

The import statement has been updated to use Vitest instead of Chai, which aligns with the framework transition mentioned in the summary. All necessary testing functions are correctly imported.


18-18: LGTM: Correct usage of beforeAll in Vitest

The before hook has been correctly replaced with beforeAll, which is the equivalent in Vitest. This change maintains the original setup behavior while adhering to Vitest's conventions.


Line range hint 1-380: Overall: Smooth transition to Vitest with potential for further refinement

The changes successfully transition the test file from Chai to Vitest with minimal disruption. The core test structure and assertions remain intact, which is positive. However, I recommend a thorough review of all assertions in the file to ensure full compatibility with Vitest, as some Chai-specific assertion styles might need adjustment.

To ensure all assertions are Vitest-compatible, please run the following script:

If the script returns any results, those lines may need to be updated to fully align with Vitest's assertion style.

tests/src/core/particle/ParticleBoundingBox.test.ts (4)

20-20: LGTM: Import statement updated to use Vitest

The import statement has been correctly updated to use Vitest instead of Chai. All necessary functions (describe, beforeAll, beforeEach, expect, it) are now imported from Vitest, which aligns with the transition to the new testing framework.


64-64: LGTM: Lifecycle method updated to use Vitest's beforeAll

The before function has been correctly replaced with beforeAll. This change aligns with Vitest's lifecycle methods, where beforeAll is equivalent to Mocha's before, running once before all tests in the describe block.


Line range hint 1-461: Summary: Successful transition from Chai to Vitest

The changes in this file successfully transition the test suite from using Chai to Vitest. The modifications include:

  1. Updated import statements to use Vitest functions.
  2. Changed the lifecycle method from before to beforeAll.
  3. Removed the explicit timeout setting, relying on Vitest's default timeout.

These changes maintain the integrity of the tests while adapting to the new testing framework. The overall structure and logic of the tests remain intact, ensuring that the ParticleBoundingBox functionality is still thoroughly tested.

To ensure the smooth running of all tests, please verify that:

  1. All tests pass with the new Vitest setup.
  2. The VelocityOverLifetime test completes within the default timeout or adjust if necessary.
  3. Any global configurations or setup files have been updated to work with Vitest.

Line range hint 359-359: Verify if custom timeout is needed for VelocityOverLifetime test

The this.timeout(10000); line has been removed from the VelocityOverLifetime test case. This change is likely correct as Vitest handles timeouts differently from Mocha/Chai. Vitest has a default timeout of 5 seconds for tests.

However, please verify if this test case requires a longer timeout. If it does, you can set a custom timeout for this specific test using Vitest's test.timeout() method:

it("VelocityOverLifetime", () => {
  test.timeout(10000); // Set timeout to 10 seconds for this test
  // ... rest of the test
});
tests/src/core/Light.test.ts (4)

39-39: LGTM! Appropriate lifecycle hook change.

The transition from before to beforeAll is correct for the Vitest framework. This ensures that the setup code runs once before all tests in the describe block, which is suitable for initializing the engine and creating the test scene.


300-303: LGTM! Appropriate cleanup hook change.

The transition from after to afterAll is correct for the Vitest framework. This ensures that the cleanup code runs once after all tests in the describe block, which is suitable for releasing resources and destroying the engine.


Line range hint 1-300: LGTM! Consistent update of assertion syntax.

The transition from Chai to Vitest assertion syntax has been applied consistently throughout the file. The core logic and coverage of the tests appear to be maintained.

To ensure that the test coverage hasn't been inadvertently affected by the framework transition, please run the following command to check the test coverage:

This will help verify that the test coverage remains consistent after the framework change.


Line range hint 1-303: Overall LGTM! Successful transition to Vitest.

The transition from Chai to Vitest has been implemented consistently throughout the file. The core logic and coverage of the tests have been maintained, with only the necessary syntax changes applied.

To ensure the transition is complete and no remnants of the old framework remain, please run the following command:

This will help catch any overlooked Chai references and confirm that Vitest is properly configured and running all tests successfully.

tests/src/math/Matrix.test.ts (4)

2-2: LGTM: Import statement updated correctly

The import statement has been successfully updated to use Vitest instead of Chai, which aligns with the transition to the new testing framework.


398-398: LGTM: Expectation syntax updated correctly

The expectation syntax has been successfully updated to match Vitest's requirements while maintaining the same test logic.


475-475: LGTM: Expectation syntax updated correctly

The expectation syntax has been successfully updated to match Vitest's requirements while maintaining the same test logic.


Line range hint 1-479: Overall: Successful transition to Vitest

The changes in this file successfully transition the Matrix tests from Chai to Vitest. All modifications are consistent with Vitest's syntax and expectations. The core logic of the tests remains intact, ensuring that the functionality being tested is preserved. This update aligns well with the PR objective of refactoring the testing framework.

Some observations:

  1. Import statements have been correctly updated.
  2. Expectation syntax has been modified to match Vitest's requirements.
  3. No changes were made to the actual test cases or the Matrix class being tested.

These changes contribute to standardizing the testing approach across the project without altering the core functionality or coverage of the tests.

tests/src/core/physics/DynamicCollider.test.ts (1)

13-13: Transition to Vitest and test setup changes

The switch from Chai to Vitest aligns with the PR objectives. Good job on removing unused imports, which improves code cleanliness. However, changing before to beforeAll might affect test isolation.

Consider the implications of using beforeAll instead of before:

  1. Does this change affect the independence of individual tests?
  2. Are there any shared states that might cause test interference?

If you're confident about test isolation, you can ignore this. Otherwise, consider using beforeEach to ensure a clean state for each test.

Also applies to: 20-20

tests/src/core/2d/text/TextRenderer.test.ts (5)

15-15: LGTM: Import statement updated to use Vitest

The import statement has been correctly updated to use Vitest instead of Chai. This change is consistent with the transition to the Vitest testing framework and includes all necessary functions for the test suite.


23-23: LGTM: 'before' hook replaced with 'beforeAll'

The 'before' hook has been correctly replaced with 'beforeAll', which is the appropriate Vitest equivalent. This ensures that the setup code runs once before all tests in the suite.


378-380: LGTM: 'after' hook replaced with 'afterAll'

The 'after' hook has been correctly replaced with 'afterAll', which is the appropriate Vitest equivalent. This ensures that the cleanup code runs once after all tests in the suite have completed.


Line range hint 1-381: LGTM: Overall test structure consistent with Vitest

The test suite structure has been successfully transitioned to Vitest without altering the individual test cases. The use of 'describe' and 'it' functions, as well as 'expect' assertions, remains consistent with Vitest's API. This demonstrates a clean migration from Chai to Vitest while maintaining the integrity of the tests.


Line range hint 1-381: Summary: Successful migration to Vitest

The test file has been successfully migrated from Chai to Vitest. Key changes include:

  1. Updated import statement to use Vitest functions.
  2. Replaced 'before' and 'after' hooks with 'beforeAll' and 'afterAll' respectively.
  3. Maintained the overall structure and functionality of the test suite.

These changes improve the consistency of the testing framework across the project without altering the test coverage or functionality. The migration has been executed cleanly and efficiently.

tests/src/core/Entity.test.ts (5)

3-3: LGTM: Vitest imports added correctly.

The import statement has been updated to include the necessary functions from Vitest, which is in line with the transition from Chai to Vitest for this test file.


415-416: LGTM: Proper setup for method spying with Vitest.

The onDisable and onDestroy methods of DestroyScript are now wrapped with vi.fn(). This change enables proper spying and mocking of these methods in the Vitest framework, which is essential for verifying their behavior in the tests.


426-426: LGTM: Assertion syntax updated for Vitest.

The assertion has been correctly updated from Chai's syntax to Vitest's toHaveBeenCalledTimes(1). This change maintains the same test logic while properly adapting to the Vitest framework.


435-435: LGTM: Final assertion updated for Vitest.

The final assertion has been correctly updated to use Vitest's toHaveBeenCalledTimes(1) syntax. This change ensures consistency with the new testing framework while preserving the original test logic.


Line range hint 1-438: LGTM: Successful transition from Chai to Vitest.

The changes in this file successfully transition the test suite from Chai to Vitest. Key points:

  1. Imports have been updated to include Vitest functions.
  2. Assertion syntax has been correctly modified to use Vitest's expectations.
  3. Spy functions are now properly set up using Vitest's vi.fn().

These changes maintain the original test logic while adapting to the new testing framework. The transition appears to be complete and correct for this file.

tests/src/core/Script.test.ts (7)

3-3: LGTM: Vitest import added correctly

The import statement for Vitest testing utilities has been added correctly, which is necessary for the transition from Chai to Vitest.


34-36: LGTM: Assertions correctly updated to Vitest syntax

The expect statements have been properly updated to use Vitest syntax while maintaining the same logical assertions. This change is consistent with the transition from Chai to Vitest.


111-117: LGTM: Assertions correctly updated to Vitest syntax for ParentScript and ChildScript

The expect statements for ParentScript and ChildScript have been properly updated to use Vitest syntax while maintaining the same logical assertions. This change is consistent with the transition from Chai to Vitest.


155-157: LGTM: Assertions correctly updated to Vitest syntax

The expect statements in the "Entity isActive = true after script call enabled = false" test have been properly updated to use Vitest syntax while maintaining the same logical assertions. This change is consistent with the transition from Chai to Vitest.


191-193: LGTM: Assertions correctly updated to Vitest syntax

The expect statements in the "Script delete in the main loop" test have been properly updated to use Vitest syntax while maintaining the same logical assertions. This change is consistent with the transition from Chai to Vitest.


214-214: LGTM: Assertions correctly updated to Vitest syntax

The expect statements in the "Script add in script's onStart" test have been properly updated to use Vitest syntax while maintaining the same logical assertions. This change is consistent with the transition from Chai to Vitest.

Also applies to: 216-216, 218-219


Line range hint 1-409: Overall: Successful transition from Chai to Vitest

The changes in this file demonstrate a successful transition from Chai to Vitest for testing. All assertions and mocking have been correctly updated to use Vitest syntax while maintaining the original test logic. The consistency in these changes across different test cases is commendable.

A minor improvement suggestion has been made to use vi.spyOn() instead of directly overwriting prototype methods for more robust mocking. Consider implementing this change throughout the file for better test hygiene.

Great job on maintaining the integrity of the test suite while upgrading the testing framework!

tests/src/core/Camera.test.ts (2)

4-4: LGTM: Import statement updated correctly

The import statement has been successfully updated to include the necessary functions from Vitest (describe, beforeAll, expect, it). This change aligns with the transition from Chai to Vitest as the testing framework.


13-13: LGTM: Lifecycle hook updated correctly

The before function has been appropriately replaced with beforeAll, which is the correct lifecycle hook in Vitest. The function signature and its content remain unchanged, ensuring that the setup logic is preserved.

tests/src/core/2d/text/TextUtils.test.ts (4)

4-4: LGTM: Import statement updated correctly for Vitest

The import statement has been successfully updated to use Vitest instead of Chai. All necessary functions are imported and used in the test suite.


18-18: LGTM: beforeAll hook correctly implemented

The 'before' hook has been appropriately replaced with 'beforeAll', maintaining the same functionality while aligning with Vitest's syntax.


322-322: LGTM: afterAll hook correctly implemented

The 'after' hook has been appropriately replaced with 'afterAll', maintaining the same functionality while aligning with Vitest's syntax.


Line range hint 1-324: Overall: Successful transition from Chai to Vitest

The changes in this file successfully transition the test suite from using Chai to Vitest. The import statement and lifecycle hooks have been updated appropriately, while maintaining the original test logic and structure. This change enhances consistency with the project's new testing framework without introducing any functional changes to the tests themselves.

tests/src/core/Shader.test.ts (2)

18-18: LGTM: Import statement updated for Vitest

The import statement has been correctly updated to use Vitest instead of Chai. This change is consistent with the transition to the Vitest testing framework.


Line range hint 1-524: Overall assessment: Successful transition to Vitest

The changes in this file successfully transition the test suite from Chai to Vitest. The modifications are minimal and focused, affecting only the necessary parts:

  1. Updated import statements
  2. Changed spy creation and assertion syntax
  3. Updated mock reset method

The core logic and structure of the tests remain unchanged, which is appropriate for this type of migration. This approach minimizes the risk of introducing new bugs while updating the testing framework.

To ensure that all Chai-specific syntax has been removed, please run the following command:

This will help verify that no Chai-specific code remains in the test files.

tests/src/loader/GLTFLoader.test.ts (1)

Line range hint 1-516: Overall, well-structured and comprehensive tests with room for minor improvements.

The GLTFLoader tests provide thorough coverage of GLTF loading, resource management, and garbage collection behaviors. The transition to Vitest and the use of beforeAll and afterAll hooks are positive changes.

Key strengths:

  1. Comprehensive testing of GLTF resource loading and properties.
  2. Effective coverage of garbage collection scenarios.
  3. Thorough testing of resource destruction behaviors.

Suggestions for improvement:

  1. Move custom parsers and extensions to a separate file for better organization.
  2. Break down the large "Pipeline Parser" test into smaller, focused tests.
  3. Add clarifying comments to delineate stages in complex tests.
  4. Improve test descriptions to better reflect their contents.

Implementing these suggestions would further enhance the maintainability and readability of the test suite. Great job overall!

tests/src/core/ModelMesh.test.ts (3)

15-15: LGTM: Import statement updated correctly

The import statement has been successfully updated to use Vitest instead of Chai, importing all necessary functions (describe, beforeAll, expect, it).


41-41: LGTM: Lifecycle hook updated correctly

The before function has been correctly replaced with beforeAll, which is the equivalent in Vitest. This change ensures that the setup code runs once before all tests in the suite, maintaining the original behavior.


Line range hint 1-568: Summary: Successful migration to Vitest

The changes in this file are minimal and focused on updating the testing framework from Chai to Vitest. The import statement and lifecycle hook have been correctly updated, while preserving all existing test cases and their logic. This ensures that the ModelMesh class continues to be thoroughly tested with the new framework.

tests/src/core/physics/PhysicsManager.test.ts (23)

19-19: LGTM: Import statement updated correctly

The import statement has been successfully updated to use Vitest instead of Chai. This change is in line with the transition to the Vitest testing framework.


82-88: LGTM: Spy setup updated correctly

The spy setup in the resetSpy function has been successfully updated to use vi.fn() instead of chai.spy(). This change is consistent across all collision and trigger event handlers and aligns with the transition to Vitest.


518-523: LGTM: Test assertions updated correctly

The test assertions in the "Dynamic Trigger vs Dynamic Trigger" test have been successfully updated to use Vitest's syntax. The changes from .to.have.been.called to .toHaveBeenCalled() and .not.to.have.been.called to .not.toHaveBeenCalled() are correct and maintain the original test logic.


542-547: LGTM: Test assertions updated correctly

The test assertions in the "Dynamic vs Dynamic" test have been successfully updated to use Vitest's syntax. The changes from .to.have.been.called to .toHaveBeenCalled() and .not.to.have.been.called to .not.toHaveBeenCalled() are correct and maintain the original test logic.


566-571: LGTM: Test assertions updated correctly

The test assertions in the "Static Trigger vs Static Trigger" test have been successfully updated to use Vitest's syntax. The changes from .not.to.have.been.called to .not.toHaveBeenCalled() are correct and maintain the original test logic.


590-595: LGTM: Test assertions updated correctly

The test assertions in the "Static vs Static" test have been successfully updated to use Vitest's syntax. The changes from .not.to.have.been.called to .not.toHaveBeenCalled() are correct and maintain the original test logic.


614-619: LGTM: Test assertions updated correctly

The test assertions in the "Static vs Dynamic" test have been successfully updated to use Vitest's syntax. The changes from .to.have.been.called to .toHaveBeenCalled() and .not.to.have.been.called to .not.toHaveBeenCalled() are correct and maintain the original test logic.


638-643: LGTM: Test assertions updated correctly

The test assertions in the "Static Trigger vs Dynamic Trigger" test have been successfully updated to use Vitest's syntax. The changes from .not.to.have.been.called to .not.toHaveBeenCalled() are correct and maintain the original test logic.


662-667: LGTM: Test assertions updated correctly

The test assertions in the "Static Trigger vs Dynamic" test have been successfully updated to use Vitest's syntax. The changes from .not.to.have.been.called to .not.toHaveBeenCalled() and .to.have.been.called to .toHaveBeenCalled() are correct and maintain the original test logic.


686-691: LGTM: Test assertions updated correctly

The test assertions in the "Static vs Dynamic Trigger" test have been successfully updated to use Vitest's syntax. The changes from .not.to.have.been.called to .not.toHaveBeenCalled() and .to.have.been.called to .toHaveBeenCalled() are correct and maintain the original test logic.


710-715: LGTM: Test assertions updated correctly

The test assertions in the "Dynamic Trigger vs Dynamic" test have been successfully updated to use Vitest's syntax. The changes from .not.to.have.been.called to .not.toHaveBeenCalled() and .to.have.been.called to .toHaveBeenCalled() are correct and maintain the original test logic.


734-739: LGTM: Test assertions updated correctly

The test assertions in the "Static Trigger vs Static" test have been successfully updated to use Vitest's syntax. The changes from .not.to.have.been.called to .not.toHaveBeenCalled() are correct and maintain the original test logic.


758-763: LGTM: Test assertions updated correctly

The test assertions in the "Dynamic Kinematic vs Static" test have been successfully updated to use Vitest's syntax. The changes from .not.to.have.been.called to .not.toHaveBeenCalled() are correct and maintain the original test logic.


782-787: LGTM: Test assertions updated correctly

The test assertions in the "Dynamic Kinematic vs Dynamic" test have been successfully updated to use Vitest's syntax. The changes from .to.have.been.called to .toHaveBeenCalled() and .not.to.have.been.called to .not.toHaveBeenCalled() are correct and maintain the original test logic.


806-811: LGTM: Test assertions updated correctly

The test assertions in the "Dynamic Trigger Kinematic vs Dynamic" test have been successfully updated to use Vitest's syntax. The changes from .not.to.have.been.called to .not.toHaveBeenCalled() and .to.have.been.called to .toHaveBeenCalled() are correct and maintain the original test logic.


830-835: LGTM: Test assertions updated correctly

The test assertions in the "Dynamic Kinematic vs Dynamic Kinematic" test have been successfully updated to use Vitest's syntax. The changes from .not.to.have.been.called to .not.toHaveBeenCalled() are correct and maintain the original test logic.


854-859: LGTM: Test assertions updated correctly

The test assertions in the "Dynamic Trigger Kinematic vs Dynamic Trigger Kinematic" test have been successfully updated to use Vitest's syntax. The changes from .not.to.have.been.called to .not.toHaveBeenCalled() are correct and maintain the original test logic.


878-883: LGTM: Test assertions updated correctly

The test assertions in the "Static Trigger vs Dynamic Kinematic" test have been successfully updated to use Vitest's syntax. The changes from .not.to.have.been.called to .not.toHaveBeenCalled() and .to.have.been.called to .toHaveBeenCalled() are correct and maintain the original test logic.


902-907: LGTM: Test assertions updated correctly

The test assertions in the "Dynamic Trigger vs Dynamic Kinematic" test have been successfully updated to use Vitest's syntax. The changes from .not.to.have.been.called to .not.toHaveBeenCalled() and .to.have.been.called to .toHaveBeenCalled() are correct and maintain the original test logic.


926-931: LGTM: Test assertions updated correctly

The test assertions in the "Dynamic Trigger Kinematic vs Dynamic Kinematic" test have been successfully updated to use Vitest's syntax. The changes from .not.to.have.been.called to .not.toHaveBeenCalled() and .to.have.been.called to .toHaveBeenCalled() are correct and maintain the original test logic.


950-955: LGTM: Test assertions updated correctly

The test assertions in the "Dynamic Trigger Kinematic vs Static Trigger" test have been successfully updated to use Vitest's syntax. The changes from .not.to.have.been.called to .not.toHaveBeenCalled() are correct and maintain the original test logic.


974-979: LGTM: Test assertions updated correctly

The test assertions in the "Dynamic Trigger Kinematic vs Dynamic Trigger" test have been successfully updated to use Vitest's syntax. The changes from .not.to.have.been.called to .not.toHaveBeenCalled() are correct and maintain the original test logic.


Line range hint 1-982: LGTM: Successful transition from Chai to Vitest

The changes made in this file successfully transition the tests from using Chai to Vitest. All modifications, including import statements, spy setups, and test assertions, have been implemented correctly and consistently throughout the file. The original test logic has been maintained, ensuring that the tests continue to function as intended with the new testing framework.

Key changes include:

  1. Updated import statements to use Vitest functions.
  2. Modified spy setup to use vi.fn() instead of chai.spy().
  3. Updated all test assertions to use Vitest's syntax (e.g., .toHaveBeenCalled() instead of .to.have.been.called).

These changes have been applied uniformly across all test cases, maintaining the integrity of the tests while adapting to the new framework.

tests/src/core/physics/Collider.test.ts (2)

13-13: Imported Vitest testing functions - Approved

The import statement is correctly updated to import necessary testing functions from "vitest".


49-49: Updated test setup to use beforeAll - Approved

The setup function is correctly updated to use beforeAll, aligning with Vitest's test lifecycle hooks.

Comment on lines 4 to 6
import { Preprocessor } from "@galacean/engine-shader-lab";
import { describe, expect, it } from "vitest";
import { server } from "@vitest/browser/context";
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

Old Preprocessor imports still present in the codebase.

The following file contains imports from "@galacean/engine-shader-lab/verbose":

  • tests/src/shader-lab/ShaderLab.test.ts
🔗 Analysis chain

LGTM! Verify import changes across the codebase.

The update to the Preprocessor import and the switch to Vitest align with the refactoring objectives. These changes look good and should improve consistency across the project.

To ensure these changes are consistent across the codebase, run the following script:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify Preprocessor imports and Vitest usage across the codebase

# Test 1: Check for any remaining imports from "@galacean/engine-shader-lab/verbose"
echo "Checking for old Preprocessor imports:"
rg --type typescript '@galacean/engine-shader-lab/verbose'

# Test 2: Verify consistent use of Vitest in test files
echo "Checking for consistent Vitest usage in test files:"
rg --type typescript 'from "(chai|mocha)"' 'tests/'

Length of output: 460


Script:

#!/bin/bash
# Description: Verify Preprocessor imports and Vitest usage across the codebase

# Test 1: Check for any remaining imports from "@galacean/engine-shader-lab/verbose"
echo "Checking for old Preprocessor imports:"
rg --type typescript "@galacean/engine-shader-lab/verbose" || echo "No old Preprocessor imports found."

# Test 2: Verify consistent use of Vitest in test files
echo "Checking for inconsistent testing framework usage in test files:"
rg --type typescript 'from "(chai|mocha)"' tests/ || echo "All test files consistently use Vitest."

Length of output: 574


Script:

#!/bin/bash
# Description: Verify Preprocessor imports and Vitest usage across the codebase

# Test 1: Check for any remaining imports from "@galacean/engine-shader-lab/verbose"
echo "Checking for old Preprocessor imports:"
rg '@galacean/engine-shader-lab/verbose' -- '*.ts' '*.tsx' || echo "No old Preprocessor imports found."

# Test 2: Verify consistent use of Vitest in test files
echo "Checking for inconsistent testing framework usage in test files:"
rg 'from "(chai|mocha)"' tests/**/*.ts tests/**/*.tsx || echo "All test files consistently use Vitest."

Length of output: 671


Script:

#!/bin/bash
# Description: Verify Preprocessor imports and Vitest usage across the codebase

# Test 1: Check for any remaining imports from "@galacean/engine-shader-lab/verbose"
echo "Checking for old Preprocessor imports:"
fd --extension ts --extension tsx --type f | xargs rg '@galacean/engine-shader-lab/verbose' && echo "Old Preprocessor imports found." || echo "No old Preprocessor imports found."

# Test 2: Verify consistent use of Vitest in test files
echo "Checking for inconsistent testing framework usage in test files:"
fd --extension ts --extension tsx --type f tests | xargs rg 'from "(chai|mocha)"' && echo "Inconsistent testing framework usage found." || echo "All test files consistently use Vitest."

Length of output: 696

@@ -1,5 +1,5 @@
import { BoundingBox, BoundingSphere, Vector3 } from "@galacean/engine-math";
import { expect } from "chai";
import { describe, expect, it } from "vitest";
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

⚠️ Leftover Chai Assertions Detected

The test file still contains Chai-specific assertions (to.eq). Please update these assertions to use Vitest's assertion methods to ensure consistency with the new testing framework.

  • expect(Vector3.equals(center1, center2)).to.eq(true);
  • expect(radius1).to.eq(radius2);
  • expect(Vector3.equals(a.center, b.center)).to.eq(true);
  • expect(a.radius).to.eq(b.radius);
  • expect(Vector3.equals(a.center, out.center)).to.eq(true);
  • expect(a.radius).to.eq(out.radius);
🔗 Analysis chain

LGTM: Import statement updated correctly for Vitest.

The import statement has been properly updated to use Vitest instead of Chai, which aligns with the PR's objective of refactoring the tests. The additional imports (describe and it) are correctly included for Vitest's testing structure.

Let's verify that the newly imported functions are used consistently throughout the file:


Let's adjust the shell scripts to remove the unrecognized --type typescript flag and directly target the file.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify usage of Vitest functions in the file

# Test: Check for usage of 'describe' and 'it' functions
rg --type typescript 'describe\(' tests/src/math/BoundingSphere.test.ts
rg --type typescript 'it\(' tests/src/math/BoundingSphere.test.ts

# Test: Ensure no leftover Chai-specific assertions
rg --type typescript 'to\.eq' tests/src/math/BoundingSphere.test.ts

Length of output: 316


Script:

#!/bin/bash
# Description: Verify usage of Vitest functions in the file

# Test: Check for usage of 'describe' and 'it' functions
rg 'describe\(' tests/src/math/BoundingSphere.test.ts
rg 'it\(' tests/src/math/BoundingSphere.test.ts

# Test: Ensure no leftover Chai-specific assertions
rg 'to\.eq' tests/src/math/BoundingSphere.test.ts

Length of output: 561

import { ParticleGradient, GradientColorKey, GradientAlphaKey } from "@galacean/engine-core";
import { Color } from "@galacean/engine-math";
import { describe, expect, it } from "vitest";
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

Chai-specific assertions still present

The following Chai-specific assertion methods are still present in tests/src/core/particle/ParticleGradient.test.ts and need to be updated to their Vitest equivalents:

  • to.be.an
  • to.deep.equal
  • to.have.lengthOf
  • to.throw

Please update these assertions to use Vitest's assertion syntax to ensure consistency with the testing framework transition.

🔗 Analysis chain

LGTM: Successful transition to Vitest

The import statement has been correctly updated to use Vitest instead of Chai. This change aligns with the project's goal of transitioning the testing framework. The imported functions (describe, expect, and it) are appropriate for the test structure used in this file.

To ensure the transition is complete, let's verify that no Chai-specific assertions are still in use:


To address the error, let's adjust the shell script to target the specific file without using the unsupported --type option:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any remaining Chai-specific assertions

# Test: Search for Chai-specific assertion methods
rg --type typescript 'to\.(be|equal|have|throw|not|deep|include|match|property|lengthOf|exist|true|false|null|undefined|NaN|empty|above|below|least|most|within|instanceof|oneOf|satisfy|closeTo|members|ordered|string|number|boolean|symbol|function|object|keys|respondTo|itself|approximately|increase|decrease|extensible|sealed|frozen|finite|fail)\b' tests/src/core/particle/ParticleGradient.test.ts

# If no results are found, the transition is complete

Length of output: 434


Script:

#!/bin/bash
# Description: Check for any remaining Chai-specific assertions

# Test: Search for Chai-specific assertion methods
rg 'to\.(be|equal|have|throw|not|deep|include|match|property|lengthOf|exist|true|false|null|undefined|NaN|empty|above|below|least|most|within|instanceof|oneOf|satisfy|closeTo|members|ordered|string|number|boolean|symbol|function|object|keys|respondTo|itself|approximately|increase|decrease|extensible|sealed|frozen|finite|fail)\b' tests/src/core/particle/ParticleGradient.test.ts

# If no results are found, the transition is complete

Length of output: 1145

@@ -1,6 +1,6 @@
import { Engine, Texture2D, TextureFormat } from "@galacean/engine-core";
import { WebGLEngine } from "@galacean/engine-rhi-webgl";
import { expect } from "chai";
import { describe, beforeAll, beforeEach, expect, it } from "vitest";
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

Action Required: Remaining Chai Assertions Found

The import statement has been correctly updated to use Vitest, and all Vitest functions are properly utilized in the test suite. However, there are still Chai assertions present in the file:

  • .to.throw
  • expect(...).to.eq(...)

Please migrate these remaining Chai assertions to their Vitest equivalents to ensure consistency across the test suite.

🔗 Analysis chain

LGTM: Import statement updated correctly for Vitest.

The import statement has been correctly updated to use Vitest instead of Chai. This change aligns with the transition to the Vitest testing framework.

Let's verify that the newly imported Vitest functions are used correctly throughout the file:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify correct usage of Vitest functions

# Test: Check for correct usage of 'describe'
echo "Checking 'describe' usage:"
rg --type typescript "describe\(" tests/src/core/texture/Texture2D.test.ts

# Test: Check for correct usage of 'beforeAll'
echo "Checking 'beforeAll' usage:"
rg --type typescript "beforeAll\(" tests/src/core/texture/Texture2D.test.ts

# Test: Check for correct usage of 'beforeEach'
echo "Checking 'beforeEach' usage:"
rg --type typescript "beforeEach\(" tests/src/core/texture/Texture2D.test.ts

# Test: Check for correct usage of 'it'
echo "Checking 'it' usage:"
rg --type typescript "it\(" tests/src/core/texture/Texture2D.test.ts

# Test: Check for any remaining Chai assertions
echo "Checking for remaining Chai assertions:"
rg --type typescript "\.to\." tests/src/core/texture/Texture2D.test.ts

Length of output: 911


Script:

#!/bin/bash
# Revised shell script without '--type typescript'

# Test: Check for correct usage of 'describe'
echo "Checking 'describe' usage:"
rg "describe\(" tests/src/core/texture/Texture2D.test.ts

# Test: Check for correct usage of 'beforeAll'
echo "Checking 'beforeAll' usage:"
rg "beforeAll\(" tests/src/core/texture/Texture2D.test.ts

# Test: Check for correct usage of 'beforeEach'"
echo "Checking 'beforeEach' usage:"
rg "beforeEach\(" tests/src/core/texture/Texture2D.test.ts

# Test: Check for correct usage of 'it'"
echo "Checking 'it' usage:"
rg "it\(" tests/src/core/texture/Texture2D.test.ts

# Test: Check for any remaining Chai assertions
echo "Checking for remaining Chai assertions:"
rg "\.to\." tests/src/core/texture/Texture2D.test.ts

Length of output: 1640


describe("SkinnedMeshRenderer", async () => {
let engine: WebGLEngine;
let rootEntity: Entity;

before(async function () {
beforeAll(async function () {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

Potential Shared State Issues Detected

The verification found assignments to shared variables that may affect test isolation:

  • skin.skeleton = "RootBone"; in tests/src/core/SkinnedMeshRenderer.test.ts
  • engine = await WebGLEngine.create({ canvas: document.createElement("canvas") }); in tests/src/core/SkinnedMeshRenderer.test.ts
  • rootEntity = scene.createRootEntity(); in tests/src/core/SkinnedMeshRenderer.test.ts

Please ensure that these assignments do not introduce shared state between tests, which could compromise test isolation.

🔗 Analysis chain

LGTM: Lifecycle hook updated correctly, but verify test isolation.

The change from before to beforeAll is correct for Vitest. However, this means the setup code will run once before all tests, instead of before each test. Please verify that this doesn't affect test isolation, especially if the tests modify shared state.

To verify test isolation, you can run the following script:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for potential shared state issues in tests

# Look for mutable variables declared outside of test cases
rg --type typescript '(let|var).*=' tests/src/core/SkinnedMeshRenderer.test.ts

# Look for assignments to shared variables within test cases
rg --type typescript '(engine|rootEntity).*=' tests/src/core/SkinnedMeshRenderer.test.ts

Length of output: 241


Script:

#!/bin/bash
# Description: Check for potential shared state issues in tests

# Look for mutable variables declared outside of test cases
rg -g "*.ts" '(let|var).*=' tests/src/core/SkinnedMeshRenderer.test.ts

# Look for assignments to shared variables within test cases
rg -g "*.ts" '(engine|rootEntity).*=' tests/src/core/SkinnedMeshRenderer.test.ts

Length of output: 315

import { Quaternion } from "@galacean/engine-math";
import { WebGLEngine } from "@galacean/engine-rhi-webgl";
import chai, { expect } from "chai";
import spies from "chai-spies";
import { vi, describe, beforeAll, expect, it, afterAll, afterEach } from "vitest";
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Remove extra whitespace in import statement.

There's an unnecessary extra space between import and { on line 25.

Apply this diff:

-import  { vi, describe, beforeAll, expect, it, afterAll, afterEach } from "vitest";
+import { vi, describe, beforeAll, expect, it, afterAll, afterEach } from "vitest";
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
import { vi, describe, beforeAll, expect, it, afterAll, afterEach } from "vitest";
import { vi, describe, beforeAll, expect, it, afterAll, afterEach } from "vitest";

Comment on lines +21 to +22
import "@galacean/engine-loader"
import type { GLTFResource } from "@galacean/engine-loader";
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Remove unnecessary whitespace and add missing semicolon.

On line 22, there's an extra space before GLTFResource. Additionally, line 21 is missing a semicolon at the end of the import statement. Ensuring consistent formatting helps maintain code readability.

Apply this diff:

-import "@galacean/engine-loader"
+import "@galacean/engine-loader";
-import type {  GLTFResource } from "@galacean/engine-loader";
+import type { GLTFResource } from "@galacean/engine-loader";
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
import "@galacean/engine-loader"
import type { GLTFResource } from "@galacean/engine-loader";
import "@galacean/engine-loader";
import type { GLTFResource } from "@galacean/engine-loader";

Comment on lines +327 to +328
const testScript = animator.entity.addComponent(TestScript);
const testScriptSpy = vi.spyOn(testScript, "event0");
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Ensure type safety when spying on methods.

When creating a spy on event0, ensure that testScript correctly implements the method without TypeScript errors. If necessary, cast testScript to any to avoid type issues without suppressing errors globally.

Apply this change:

-const testScriptSpy = vi.spyOn(testScript, "event0");
+const testScriptSpy = vi.spyOn(testScript as any, "event0");
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const testScript = animator.entity.addComponent(TestScript);
const testScriptSpy = vi.spyOn(testScript, "event0");
const testScript = animator.entity.addComponent(TestScript);
const testScriptSpy = vi.spyOn(testScript as any, "event0");

Comment on lines +149 to +153
// @ts-ignore
const onDisableSpy = vi.spyOn(animator, "_onDisable");
// @ts-ignore
const onEnableSpy = vi.spyOn(animator, "_onEnable");
const onUpdateSpy = vi.spyOn(animator, "update");
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Avoid using @ts-ignore by casting to any when spying on private methods.

Using // @ts-ignore suppresses TypeScript errors, which may hide legitimate issues. Consider casting animator to any when spying on private methods to maintain type safety elsewhere.

Apply this change:

-// @ts-ignore
 const onDisableSpy = vi.spyOn(animator, "_onDisable");
+const onDisableSpy = vi.spyOn(animator as any, "_onDisable");

-// @ts-ignore
 const onEnableSpy = vi.spyOn(animator, "_onEnable");
+const onEnableSpy = vi.spyOn(animator as any, "_onEnable");
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// @ts-ignore
const onDisableSpy = vi.spyOn(animator, "_onDisable");
// @ts-ignore
const onEnableSpy = vi.spyOn(animator, "_onEnable");
const onUpdateSpy = vi.spyOn(animator, "update");
const onDisableSpy = vi.spyOn(animator as any, "_onDisable");
const onEnableSpy = vi.spyOn(animator as any, "_onEnable");
const onUpdateSpy = vi.spyOn(animator, "update");

Comment on lines +716 to +719
const onStateEnterSpy = vi.spyOn(testScript, "onStateEnter");
const onStateExitSpy = vi.spyOn(testScript, "onStateExit");
const onStateEnter2Spy = vi.spyOn(testScript2, "onStateEnter");
const onStateExit2Spy = vi.spyOn(testScript2, "onStateExit");
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Verify method accessibility when creating spies.

The methods onStateEnter and onStateExit may be protected or private, leading to TypeScript errors when spying on them. Consider casting to any to avoid using @ts-ignore.

Apply this change:

-const onStateEnterSpy = vi.spyOn(testScript, "onStateEnter");
+const onStateEnterSpy = vi.spyOn(testScript as any, "onStateEnter");

-const onStateExitSpy = vi.spyOn(testScript, "onStateExit");
+const onStateExitSpy = vi.spyOn(testScript as any, "onStateExit");

-const onStateEnter2Spy = vi.spyOn(testScript2, "onStateEnter");
+const onStateEnter2Spy = vi.spyOn(testScript2 as any, "onStateEnter");

-const onStateExit2Spy = vi.spyOn(testScript2, "onStateExit");
+const onStateExit2Spy = vi.spyOn(testScript2 as any, "onStateExit");
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const onStateEnterSpy = vi.spyOn(testScript, "onStateEnter");
const onStateExitSpy = vi.spyOn(testScript, "onStateExit");
const onStateEnter2Spy = vi.spyOn(testScript2, "onStateEnter");
const onStateExit2Spy = vi.spyOn(testScript2, "onStateExit");
const onStateEnterSpy = vi.spyOn(testScript as any, "onStateEnter");
const onStateExitSpy = vi.spyOn(testScript as any, "onStateExit");
const onStateEnter2Spy = vi.spyOn(testScript2 as any, "onStateEnter");
const onStateExit2Spy = vi.spyOn(testScript2 as any, "onStateExit");

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (3)
packages/core/src/animation/Keyframe.ts (1)

13-22: Improved readability of generic type parameter

The reformatting of the generic type parameter T enhances code readability without altering its functionality. The nested conditional types are now more clearly visible, making it easier for developers to understand the type relationships.

Consider adding a comment explaining the purpose of this complex type parameter, as it might not be immediately clear to all developers why such a detailed conditional type is necessary.

package.json (2)

8-10: LGTM! Consider combining the installPlaywright step.

The changes to the scripts section look good. The addition of the installPlaywright script and its integration into the test and coverage scripts ensures that Playwright is properly set up before running tests.

Consider combining the installPlaywright step directly into the test and coverage scripts to reduce redundancy:

"test": "pnpm exec playwright install && vitest",
"coverage": "pnpm exec playwright install && vitest --coverage --ui"

This would eliminate the need for a separate installPlaywright script and simplify the command execution.


40-41: LGTM! Consider using consistent version specifiers.

The addition of Vitest-related dependencies (@vitest/coverage-v8, @vitest/ui, vitest) and Playwright is appropriate for the transition to Vitest and the integration of browser testing.

For better consistency and to avoid potential issues with minor version updates, consider using the same version specifier for all Vitest-related packages:

"@vitest/coverage-v8": "^2.1.3",
"@vitest/ui": "^2.1.3",
"vitest": "^2.1.3"

This ensures that all Vitest packages can be updated together in the future.

Also applies to: 55-55, 65-65

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 0bc262c and 47bb76d.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (5)
  • .github/workflows/ci.yml (1 hunks)
  • package.json (3 hunks)
  • packages/core/src/animation/Keyframe.ts (1 hunks)
  • packages/core/src/animation/internal/animationCurveOwner/AnimationCurveOwner.ts (2 hunks)
  • tests/vitest.config.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • .github/workflows/ci.yml
  • tests/vitest.config.ts
🧰 Additional context used
🪛 Biome
packages/core/src/animation/internal/animationCurveOwner/AnimationCurveOwner.ts

[error] 99-99: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

🔇 Additional comments (3)
package.json (3)

40-41: Excellent cleanup of unused dependencies!

The removal of Chai and Mocha related dependencies (@types/chai, @types/chai-spies, @types/mocha, chai, chai-spies, and floss) is a good practice. This cleanup aligns with the transition to Vitest and helps maintain a cleaner, more focused dependency list.


Line range hint 1-74: Overall, excellent transition to Vitest and cleanup of dependencies.

The changes in this package.json file effectively implement the transition from Chai to Vitest for testing. The addition of Playwright for browser testing and the cleanup of unused dependencies contribute to a more streamlined and modern testing setup. The minor suggestions provided earlier will further enhance the consistency and maintainability of the project configuration.


64-64: Good update to TypeScript. Verify compatibility with the codebase.

Updating TypeScript to version ^5.1.6 is a good practice to leverage the latest features and bug fixes.

Please ensure that this update is compatible with the rest of the codebase and doesn't introduce any breaking changes. Run the following script to check for any TypeScript errors:

Copy link

codecov bot commented Oct 18, 2024

Codecov Report

Attention: Patch coverage is 81.25000% with 3 lines in your changes missing coverage. Please review.

Project coverage is 66.55%. Comparing base (ab1ceb3) to head (e44f652).
Report is 1 commits behind head on dev/1.4.

Files with missing lines Patch % Lines
...nternal/animationCurveOwner/AnimationCurveOwner.ts 50.00% 3 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           dev/1.4    #2396      +/-   ##
===========================================
- Coverage    69.69%   66.55%   -3.15%     
===========================================
  Files          523      893     +370     
  Lines        27514    91737   +64223     
  Branches      4135     7257    +3122     
===========================================
+ Hits         19176    61053   +41877     
- Misses        6829    30439   +23610     
+ Partials      1509      245    -1264     
Flag Coverage Δ
unittests 66.55% <81.25%> (-3.15%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (2)
package.json (2)

8-10: LGTM! Consider combining common commands.

The changes to the scripts section look good. They introduce Playwright installation and transition to Vitest for testing and coverage.

Consider extracting the common pnpm run installPlaywright && vitest part into a separate script to reduce duplication:

{
  "scripts": {
    "installPlaywright": "pnpm exec playwright install",
    "vitest": "pnpm run installPlaywright && vitest",
    "test": "pnpm run vitest",
    "coverage": "pnpm run vitest -- --coverage"
  }
}

This approach makes it easier to maintain and modify the common part in the future.


Line range hint 1-74: LGTM! Consider updating documentation.

The overall changes to the package.json file are well-structured and consistent with the goal of transitioning from Chai to Vitest. The file maintains its standard format, and the changes are focused on the testing framework and related dependencies.

Consider updating the project's documentation (e.g., README.md) to reflect the new testing setup. This could include:

  1. Instructions for running tests with Vitest
  2. How to generate coverage reports
  3. Any changes to the development workflow due to the introduction of Playwright

This will help maintain clear and up-to-date documentation for the project.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 47bb76d and 9431ab7.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (4)
  • package.json (3 hunks)
  • tests/src/shader-lab/Preprocessor.test.ts (1 hunks)
  • tests/src/shader-lab/test-case/index.ts (1 hunks)
  • tests/vitest.config.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • tests/src/shader-lab/Preprocessor.test.ts
  • tests/vitest.config.ts
🧰 Additional context used
🔇 Additional comments (1)
package.json (1)

40-40: LGTM! Verify complete removal of old testing dependencies.

The changes to the devDependencies section look good. They align with the transition to Vitest and the introduction of Playwright for browser testing.

To ensure a clean transition, let's verify that all old testing dependencies have been completely removed:

If these commands return any results, consider removing or updating those references to complete the transition to Vitest.

Also applies to: 54-54, 63-64

✅ Verification successful

LGTM! Old testing dependencies successfully removed.

The additional checks confirm that chai, mocha, and floss have been completely removed from the project. No references were found in:

  • Configuration files
  • Test files
  • package.json dependencies

This verifies the successful transition to the new testing framework.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any remaining references to old testing dependencies

# Test: Search for chai, mocha, or floss in the entire codebase
rg -i '(chai|mocha|floss)'

# Test: Check if any files still import these old dependencies
ast-grep --lang typescript --pattern 'import $_ from "$_"' | rg -i '(chai|mocha|floss)'

Length of output: 202311


Script:

#!/bin/bash
# Check for configuration files and test files related to old testing frameworks
echo "Searching for config files:"
fd -e json -e js -e yaml -e yml | rg -i '(chai|mocha|floss)'

echo "Searching for test files:"
fd -e test.js -e spec.js | rg -i '(chai|mocha|floss)'

echo "Checking package.json for old dependencies:"
cat package.json | jq '.dependencies, .devDependencies' | rg -i '(chai|mocha|floss)'

Length of output: 428

Comment on lines 9 to 17
for (const f of files) {
const cmpFilePath = join(cmpDir, f);
const sourceFilePath = join(sourceDir, f);
const cmpFilePath = `${cmpDir}${f}`;
const sourceFilePath = `${sourceDir}${f}`;
testCaseList.push({
source: readFileSync(sourceFilePath).toString(),
compare: readFileSync(cmpFilePath).toString(),
name: basename(f)
source: await readFile(sourceFilePath),
compare: await readFile(cmpFilePath),
name: f
});
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Optimize file reading with Promise.all for better performance

Using await inside a for...of loop reads the files sequentially, which can be inefficient. To improve performance, consider reading the files in parallel using Promise.all.

Apply this diff to refactor the code:

 const testCaseList: { source: string; compare: string; name: string }[] = [];
-for (const f of files) {
-  const cmpFilePath = `${cmpDir}${f}`;
-  const sourceFilePath = `${sourceDir}${f}`;
-  testCaseList.push({
-    source: await readFile(sourceFilePath),
-    compare: await readFile(cmpFilePath),
-    name: f
-  });
-}
+const testCaseList = await Promise.all(
+  files.map(async (f) => {
+    const cmpFilePath = `${cmpDir}${f}`;
+    const sourceFilePath = `${sourceDir}${f}`;
+    return {
+      source: await readFile(sourceFilePath),
+      compare: await readFile(cmpFilePath),
+      name: f,
+    };
+  })
+);

This refactored code reads all files concurrently, which can significantly improve the efficiency of the file loading process.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
for (const f of files) {
const cmpFilePath = join(cmpDir, f);
const sourceFilePath = join(sourceDir, f);
const cmpFilePath = `${cmpDir}${f}`;
const sourceFilePath = `${sourceDir}${f}`;
testCaseList.push({
source: readFileSync(sourceFilePath).toString(),
compare: readFileSync(cmpFilePath).toString(),
name: basename(f)
source: await readFile(sourceFilePath),
compare: await readFile(cmpFilePath),
name: f
});
}
const testCaseList = await Promise.all(
files.map(async (f) => {
const cmpFilePath = `${cmpDir}${f}`;
const sourceFilePath = `${sourceDir}${f}`;
return {
source: await readFile(sourceFilePath),
compare: await readFile(cmpFilePath),
name: f,
};
})
);

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between ee51fb8 and c25fa2a.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (1)
  • e2e/package.json (1 hunks)
🧰 Additional context used

@@ -20,7 +20,7 @@
"@galacean/engine-physics-lite": "workspace:*",
"@galacean/engine-physics-physx": "workspace:*",
"dat.gui": "^0.7.9",
"vite": "^3.1.6",
"vite": "3.1.6",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consider the implications of pinning the Vite version

The change from "^3.1.6" to "3.1.6" for the vite package pins it to an exact version. This ensures consistency across different environments but may prevent automatic updates for bug fixes or performance improvements.

Consider the following:

  1. Document the reason for pinning this specific version in a comment or commit message, if not already done.
  2. Evaluate if there are any known issues with newer patch versions of Vite 3.1.x that necessitate this pinning.
  3. Set up a process to periodically review and update this version to ensure you're not missing out on important updates.

If there's no specific reason to pin this exact version, you might want to keep the caret (^) to allow patch updates:

-    "vite": "3.1.6",
+    "vite": "^3.1.6",

This would allow automatic updates to patch versions (e.g., 3.1.7, 3.1.8) which typically include bug fixes and performance improvements without breaking changes.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
"vite": "3.1.6",
"vite": "^3.1.6",

@luzhuang luzhuang changed the title test: change floss to vitest test: replacce floss with vitest Oct 18, 2024
@GuoLei1990 GuoLei1990 merged commit 1b3c7fd into galacean:dev/1.4 Oct 22, 2024
8 of 9 checks passed
@GuoLei1990 GuoLei1990 changed the title test: replacce floss with vitest Replace unit test framework from floss to vitest Oct 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
test unit test
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants