Skip to content

feat: cxspa-13229#21687

Draft
SouhaibKhadraoui wants to merge 14 commits into
developfrom
feat/CXSPA-13229
Draft

feat: cxspa-13229#21687
SouhaibKhadraoui wants to merge 14 commits into
developfrom
feat/CXSPA-13229

Conversation

@SouhaibKhadraoui

@SouhaibKhadraoui SouhaibKhadraoui commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

The goal of this PR is to migrate the spartacus project testing from Jasmine/Karma to vitest

Reason for changes : It was brought to the dev team's attention that Karma was deprecated and no longer accepting new features or general bug fixes

Opportunity: Vitest runtimes are notoriously faster than other test runners, for these reasons among others [does not run on the browser, runs the tests in parallel worker threads]

Technical details on the change : For a project of this size, it is not only a tooling change that will run the existing karma unit tests 1-for-1 under vitest, but also a slight shift in the approach with which we test. There are of course simple syntax changes that can be run using schematics provided by angular for the wording of 1-to-1 equivalents such as spyOn methods, but the overwhelming majority of changes made have to do with strategies that used to work under Karma, but simply don't under vitest.

These changes include :

  • fakeAsync not working under vitest: fakeAsync is an Angular-specific testing utility that relies on Zone.js to synchronously manage macrotasks and microtasks. Under vitest, zone.js is still loaded in the test setup (setup-test.ts imports zone.js/testing) but the real problem is the previous usage of tick(), which has no direct Vitest equivalent. The replacement is vi.useFakeTimers() at the start of the test, await vi.advanceTimersByTimeAsync(ms) in place of tick(ms), and vi.useRealTimers() to restore with the test functions being async. For fakeAsync tests that only used it to enable async/await without tick, simply converting the test to a native async function is sufficient.
  • done() call deprecated: Subscribing to an observable and calling done() in the callback is no longer a strategy that works for test assertions. The approach documented is to replace this subscribe-assert-done pattern with awaitting firstValueFrom or lastValueFrom (imported from rxjs) and then asserting
  • returning multiple values at once: This is not supported under vitest which requires more explicit usage such as chaining multiple mockReturnValueOnce
  • spyOnProperty() not available in Vitest: Jasmine's spyOnProperty(obj, 'prop').and.returnValue(x) intercepts a property getter/setter. In Vitest use vi.spyOn(obj, 'prop', 'get').mockReturnValue(x) (pass 'get' or 'set' as the third argument). For the specific ngrx/store select case, spyOnProperty(ngrxStore, 'select') must be replaced entirely with vi.spyOn(store, 'pipe').mockReturnValueOnce(of(value)) — see the ngrx/store entry.
  • .and.stub() / .and.callFake() → mockImplementation(): Jasmine's .and.stub() makes a spy do nothing (no-op). In Vitest simply call vi.spyOn(obj, 'method') with no further chaining — an unimplemented spy returns undefined by default. - .and.callFake(fn) maps to .mockImplementation(fn).
  • Spy leaking between tests: Jasmine resets all spies between tests automatically. Vitest does not. Add afterEach(() => vi.restoreAllMocks()) at the describe block level to restore all spied methods to their original implementations between tests. Without this, a .mockReturnValue(false) set in one test will still be active in the next.
  • removal of mocked store in some cases : this might be subject to further discussions (since usually we want to isolate units of test into a controlled environment) but basically it was removed for the following reasons :
    • main reason : The store itself is not really a "dependency to mock" in the same sense as an HTTP client or a backend connector. It's a synchronous in-memory state container — there's no I/O, no network, no side effects to isolate from. The main reason to mock it in Jasmine was the ESM limitation on select, not a principled testing decision. Once that constraint is removed, using the real store is just less code with more accurate coverage.
    • (secondary reason) some mockSelect switch-case had to enumerate every selector the service might call and return controlled values for each. That's maintenance burden IMO — if the service adds a new selector call, the mock silently returns EMPTY and the test gives a false green. With real dispatch, you only set up the state the test actually needs and the store handles the rest correctly.

There are of course more changes that have not been detailed above, as they were either single-occurrence issue or were very simple fixes to adress.

Approach used:
You may have noticed the presence of the file vitest-failures.json. This file was created to be able to leverage Claude in writing unit tests, but also to limit his "creativity" in writing such unit tests. This file should not be present in the final commit before the merge, it is there only for information purposes :

  1. Find a unit test failure
  2. Fix it manually
  3. Document the fix in vitest-failures.json, referencing the initial issue encountered and identifying a candidate file for fixing the issue
  4. Find another test failure and repeat steps 1 to 3 a reasonable amount of times
  5. Ask Claude to find all issues similar to the ones identified in vitest-failures.json and to fix only the ones that match these issues

@SouhaibKhadraoui SouhaibKhadraoui requested a review from a team as a code owner July 3, 2026 16:31
@github-actions github-actions Bot marked this pull request as draft July 3, 2026 16:31
@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

🚨 PR Title Validation Failed 🚨

Your pull request title does not follow the required format. Please update it to match the expected pattern:

Expected format:
<type>: <subject>

Allowed Types

  • docs: Changes to documentation only
  • feat: New feature work
  • fix: Bug fixes
  • perf: Code improvements for performance
  • refactor: Code changes that are not bug fixes or features
  • style: Code style changes (e.g., whitespace, formatting)
  • test: Adding or updating tests
  • chore: Build, CI, scripts, configs, etc.

Example of a valid PR title

feat: Add user authentication
fix: Resolve checkout bug
docs: Update API documentation

Merge is blocked until the PR title is corrected.

@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

🚨 PR Title Validation Failed 🚨

Your pull request title does not follow the required format. Please update it to match the expected pattern:

Expected format:
<type>: <subject>

Allowed Types

  • docs: Changes to documentation only
  • feat: New feature work
  • fix: Bug fixes
  • perf: Code improvements for performance
  • refactor: Code changes that are not bug fixes or features
  • style: Code style changes (e.g., whitespace, formatting)
  • test: Adding or updating tests
  • chore: Build, CI, scripts, configs, etc.

Example of a valid PR title

feat: Add user authentication
fix: Resolve checkout bug
docs: Update API documentation

Merge is blocked until the PR title is corrected.

12 similar comments
@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

🚨 PR Title Validation Failed 🚨

Your pull request title does not follow the required format. Please update it to match the expected pattern:

Expected format:
<type>: <subject>

Allowed Types

  • docs: Changes to documentation only
  • feat: New feature work
  • fix: Bug fixes
  • perf: Code improvements for performance
  • refactor: Code changes that are not bug fixes or features
  • style: Code style changes (e.g., whitespace, formatting)
  • test: Adding or updating tests
  • chore: Build, CI, scripts, configs, etc.

Example of a valid PR title

feat: Add user authentication
fix: Resolve checkout bug
docs: Update API documentation

Merge is blocked until the PR title is corrected.

@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

🚨 PR Title Validation Failed 🚨

Your pull request title does not follow the required format. Please update it to match the expected pattern:

Expected format:
<type>: <subject>

Allowed Types

  • docs: Changes to documentation only
  • feat: New feature work
  • fix: Bug fixes
  • perf: Code improvements for performance
  • refactor: Code changes that are not bug fixes or features
  • style: Code style changes (e.g., whitespace, formatting)
  • test: Adding or updating tests
  • chore: Build, CI, scripts, configs, etc.

Example of a valid PR title

feat: Add user authentication
fix: Resolve checkout bug
docs: Update API documentation

Merge is blocked until the PR title is corrected.

@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

🚨 PR Title Validation Failed 🚨

Your pull request title does not follow the required format. Please update it to match the expected pattern:

Expected format:
<type>: <subject>

Allowed Types

  • docs: Changes to documentation only
  • feat: New feature work
  • fix: Bug fixes
  • perf: Code improvements for performance
  • refactor: Code changes that are not bug fixes or features
  • style: Code style changes (e.g., whitespace, formatting)
  • test: Adding or updating tests
  • chore: Build, CI, scripts, configs, etc.

Example of a valid PR title

feat: Add user authentication
fix: Resolve checkout bug
docs: Update API documentation

Merge is blocked until the PR title is corrected.

@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

🚨 PR Title Validation Failed 🚨

Your pull request title does not follow the required format. Please update it to match the expected pattern:

Expected format:
<type>: <subject>

Allowed Types

  • docs: Changes to documentation only
  • feat: New feature work
  • fix: Bug fixes
  • perf: Code improvements for performance
  • refactor: Code changes that are not bug fixes or features
  • style: Code style changes (e.g., whitespace, formatting)
  • test: Adding or updating tests
  • chore: Build, CI, scripts, configs, etc.

Example of a valid PR title

feat: Add user authentication
fix: Resolve checkout bug
docs: Update API documentation

Merge is blocked until the PR title is corrected.

@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

🚨 PR Title Validation Failed 🚨

Your pull request title does not follow the required format. Please update it to match the expected pattern:

Expected format:
<type>: <subject>

Allowed Types

  • docs: Changes to documentation only
  • feat: New feature work
  • fix: Bug fixes
  • perf: Code improvements for performance
  • refactor: Code changes that are not bug fixes or features
  • style: Code style changes (e.g., whitespace, formatting)
  • test: Adding or updating tests
  • chore: Build, CI, scripts, configs, etc.

Example of a valid PR title

feat: Add user authentication
fix: Resolve checkout bug
docs: Update API documentation

Merge is blocked until the PR title is corrected.

@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

🚨 PR Title Validation Failed 🚨

Your pull request title does not follow the required format. Please update it to match the expected pattern:

Expected format:
<type>: <subject>

Allowed Types

  • docs: Changes to documentation only
  • feat: New feature work
  • fix: Bug fixes
  • perf: Code improvements for performance
  • refactor: Code changes that are not bug fixes or features
  • style: Code style changes (e.g., whitespace, formatting)
  • test: Adding or updating tests
  • chore: Build, CI, scripts, configs, etc.

Example of a valid PR title

feat: Add user authentication
fix: Resolve checkout bug
docs: Update API documentation

Merge is blocked until the PR title is corrected.

@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

🚨 PR Title Validation Failed 🚨

Your pull request title does not follow the required format. Please update it to match the expected pattern:

Expected format:
<type>: <subject>

Allowed Types

  • docs: Changes to documentation only
  • feat: New feature work
  • fix: Bug fixes
  • perf: Code improvements for performance
  • refactor: Code changes that are not bug fixes or features
  • style: Code style changes (e.g., whitespace, formatting)
  • test: Adding or updating tests
  • chore: Build, CI, scripts, configs, etc.

Example of a valid PR title

feat: Add user authentication
fix: Resolve checkout bug
docs: Update API documentation

Merge is blocked until the PR title is corrected.

@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

🚨 PR Title Validation Failed 🚨

Your pull request title does not follow the required format. Please update it to match the expected pattern:

Expected format:
<type>: <subject>

Allowed Types

  • docs: Changes to documentation only
  • feat: New feature work
  • fix: Bug fixes
  • perf: Code improvements for performance
  • refactor: Code changes that are not bug fixes or features
  • style: Code style changes (e.g., whitespace, formatting)
  • test: Adding or updating tests
  • chore: Build, CI, scripts, configs, etc.

Example of a valid PR title

feat: Add user authentication
fix: Resolve checkout bug
docs: Update API documentation

Merge is blocked until the PR title is corrected.

@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

🚨 PR Title Validation Failed 🚨

Your pull request title does not follow the required format. Please update it to match the expected pattern:

Expected format:
<type>: <subject>

Allowed Types

  • docs: Changes to documentation only
  • feat: New feature work
  • fix: Bug fixes
  • perf: Code improvements for performance
  • refactor: Code changes that are not bug fixes or features
  • style: Code style changes (e.g., whitespace, formatting)
  • test: Adding or updating tests
  • chore: Build, CI, scripts, configs, etc.

Example of a valid PR title

feat: Add user authentication
fix: Resolve checkout bug
docs: Update API documentation

Merge is blocked until the PR title is corrected.

@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

🚨 PR Title Validation Failed 🚨

Your pull request title does not follow the required format. Please update it to match the expected pattern:

Expected format:
<type>: <subject>

Allowed Types

  • docs: Changes to documentation only
  • feat: New feature work
  • fix: Bug fixes
  • perf: Code improvements for performance
  • refactor: Code changes that are not bug fixes or features
  • style: Code style changes (e.g., whitespace, formatting)
  • test: Adding or updating tests
  • chore: Build, CI, scripts, configs, etc.

Example of a valid PR title

feat: Add user authentication
fix: Resolve checkout bug
docs: Update API documentation

Merge is blocked until the PR title is corrected.

@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

🚨 PR Title Validation Failed 🚨

Your pull request title does not follow the required format. Please update it to match the expected pattern:

Expected format:
<type>: <subject>

Allowed Types

  • docs: Changes to documentation only
  • feat: New feature work
  • fix: Bug fixes
  • perf: Code improvements for performance
  • refactor: Code changes that are not bug fixes or features
  • style: Code style changes (e.g., whitespace, formatting)
  • test: Adding or updating tests
  • chore: Build, CI, scripts, configs, etc.

Example of a valid PR title

feat: Add user authentication
fix: Resolve checkout bug
docs: Update API documentation

Merge is blocked until the PR title is corrected.

@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

🚨 PR Title Validation Failed 🚨

Your pull request title does not follow the required format. Please update it to match the expected pattern:

Expected format:
<type>: <subject>

Allowed Types

  • docs: Changes to documentation only
  • feat: New feature work
  • fix: Bug fixes
  • perf: Code improvements for performance
  • refactor: Code changes that are not bug fixes or features
  • style: Code style changes (e.g., whitespace, formatting)
  • test: Adding or updating tests
  • chore: Build, CI, scripts, configs, etc.

Example of a valid PR title

feat: Add user authentication
fix: Resolve checkout bug
docs: Update API documentation

Merge is blocked until the PR title is corrected.

@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

🚨 PR Title Validation Failed 🚨

Your pull request title does not follow the required format. Please update it to match the expected pattern:

Expected format:
<type>: <subject>

Allowed Types

  • docs: Changes to documentation only
  • feat: New feature work
  • fix: Bug fixes
  • perf: Code improvements for performance
  • refactor: Code changes that are not bug fixes or features
  • style: Code style changes (e.g., whitespace, formatting)
  • test: Adding or updating tests
  • chore: Build, CI, scripts, configs, etc.

Example of a valid PR title

feat: Add user authentication
fix: Resolve checkout bug
docs: Update API documentation

Merge is blocked until the PR title is corrected.

3 similar comments
@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

🚨 PR Title Validation Failed 🚨

Your pull request title does not follow the required format. Please update it to match the expected pattern:

Expected format:
<type>: <subject>

Allowed Types

  • docs: Changes to documentation only
  • feat: New feature work
  • fix: Bug fixes
  • perf: Code improvements for performance
  • refactor: Code changes that are not bug fixes or features
  • style: Code style changes (e.g., whitespace, formatting)
  • test: Adding or updating tests
  • chore: Build, CI, scripts, configs, etc.

Example of a valid PR title

feat: Add user authentication
fix: Resolve checkout bug
docs: Update API documentation

Merge is blocked until the PR title is corrected.

@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

🚨 PR Title Validation Failed 🚨

Your pull request title does not follow the required format. Please update it to match the expected pattern:

Expected format:
<type>: <subject>

Allowed Types

  • docs: Changes to documentation only
  • feat: New feature work
  • fix: Bug fixes
  • perf: Code improvements for performance
  • refactor: Code changes that are not bug fixes or features
  • style: Code style changes (e.g., whitespace, formatting)
  • test: Adding or updating tests
  • chore: Build, CI, scripts, configs, etc.

Example of a valid PR title

feat: Add user authentication
fix: Resolve checkout bug
docs: Update API documentation

Merge is blocked until the PR title is corrected.

@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

🚨 PR Title Validation Failed 🚨

Your pull request title does not follow the required format. Please update it to match the expected pattern:

Expected format:
<type>: <subject>

Allowed Types

  • docs: Changes to documentation only
  • feat: New feature work
  • fix: Bug fixes
  • perf: Code improvements for performance
  • refactor: Code changes that are not bug fixes or features
  • style: Code style changes (e.g., whitespace, formatting)
  • test: Adding or updating tests
  • chore: Build, CI, scripts, configs, etc.

Example of a valid PR title

feat: Add user authentication
fix: Resolve checkout bug
docs: Update API documentation

Merge is blocked until the PR title is corrected.

@SouhaibKhadraoui SouhaibKhadraoui changed the title Feat/cxspa 13229 feat: cxspa-13229 Jul 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant