Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

test(hooks): add unit tests for @asgardeo/react hooks to cover edge c... #220

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Kavidu23 wants to merge 3 commits into asgardeo:main
base: main
Choose a base branch
Loading
from Kavidu23:add-hook-tests

Conversation

@Kavidu23
Copy link

@Kavidu23 Kavidu23 commented Oct 26, 2025

Purpose

This PR adds unit tests for @asgardeo/react hooks to cover edge cases and improve test coverage.
Hooks tested: useBranding, useBrowserUrl, useForm, useTranslation.

The tests cover:

Normal input, boundary, and invalid cases

Error handling and default behaviors

Context absence scenarios

Screenshots generated by Vitest are included but some may appear blank (no visual output for non-UI hooks).

Related Issues

#167 — Add unit test coverage for untested code paths in @asgardeo/react SDK

Related PRs

N/A

Checklist

Followed the CONTRIBUTING
guidelines

Unit tests provided for hooks

Security checks

Followed secure coding standards in WSO2 Secure Engineering Guidelines

Confirmed that this PR doesn’t commit any keys, passwords, tokens, usernames, or other secrets

Copy link
Author

⚠️ Note:
Running pnpm nx run @asgardeo/react:lint locally gives
TypeError: services.getTypeAtLocation is not a function from @typescript-eslint/no-implied-eval.
This seems unrelated to the new tests and is likely an ESLint + TypeScript plugin issue.

✅ Tests run locally with 27 passed and 2 existing failures (not from new tests):

  • useBrowserUrl: handles relative afterSignInUrl → Invalid URL
  • useForm: setValue and validate on change → expected 'Invalid email' to be undefined

Copy link
Member

brionmario commented Oct 31, 2025
edited
Loading

Hey @Kavidu23,

Thanks for the PR.

Couple of things:

  • There's an error in the test run. Have you run the tests locally?
  • ⚠️ IMPORTNANT - lets not delete the PR template.
 > @asgardeo/react@0.5.31 test /home/runner/work/javascript/javascript/packages/react
 > vitest
 
 
 RUN v3.1.3 /home/runner/work/javascript/javascript/packages/react
 
 ⎯⎯⎯⎯⎯⎯ Unhandled Errors ⎯⎯⎯⎯⎯⎯
 
 Vitest caught 1 unhandled error during the test run.
 This might cause false positive tests. Resolve unhandled errors to make sure your tests are not affected.
 
 ⎯⎯⎯⎯⎯⎯ Unhandled Error ⎯⎯⎯⎯⎯⎯⎯
 Error: browserType.launch: Executable doesn't exist at /home/runner/.cache/ms-playwright/chromium_headless_shell-1169/chrome-linux/headless_shell
 ╔═════════════════════════════════════════════════════════════════════════╗
 ║ Looks like Playwright Test or Playwright was just installed or updated. ║
 ║ Please run the following command to download new browsers: ║
 ║ ║
 ║ pnpm exec playwright install ║
 ║ ║
 ║ <3 Playwright Team ║
 ╚═════════════════════════════════════════════════════════════════════════╝
 ❯ ../../node_modules/.pnpm/@vitest+browser@3.1.3_playwright@1.52.0_vite@6.3.5_@types+node@22.15.30_jiti@2.6.0_ligh_b8bcb4faefafff31ab1b9ccbb49ee8ae/node_modules/@vitest/browser/dist/webdriver-BH7t2pDp.js:66:54
 
 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
 
 
 Test Files (4)
 Tests no tests
 Errors 1 error
 Start at 05:33:59
 Duration 792ms (transform 0ms, setup 0ms, collect 0ms, tests 0ms, environment 0ms, prepare 0ms)
 
 error during close browserType.launch: Executable doesn't exist at /home/runner/.cache/ms-playwright/chromium_headless_shell-1169/chrome-linux/headless_shell
 ╔═════════════════════════════════════════════════════════════════════════╗
 ║ Looks like Playwright Test or Playwright was just installed or updated. ║
 ║ Please run the following command to download new browsers: ║
 ║ ║
 ║ pnpm exec playwright install ║
 ║ ║
 ║ <3 Playwright Team ║
 ╚═════════════════════════════════════════════════════════════════════════╝
 at /home/runner/work/javascript/javascript/node_modules/.pnpm/@vitest+browser@3.1.3_playwright@1.52.0_vite@6.3.5_@types+node@22.15.30_jiti@2.6.0_ligh_b8bcb4faefafff31ab1b9ccbb49ee8ae/node_modules/@vitest/browser/dist/webdriver-BH7t2pDp.js:66:54 {
 name: 'Error',
 type: 'Unhandled Error',
 stacks: [
 {
 method: '',
 file: '/home/runner/work/javascript/javascript/node_modules/.pnpm/@vitest+browser@3.1.3_playwright@1.52.0_vite@6.3.5_@types+node@22.15.30_jiti@2.6.0_ligh_b8bcb4faefafff31ab1b9ccbb49ee8ae/node_modules/@vitest/browser/dist/webdriver-BH7t2pDp.js',
 line: 66,
 column: 54
 }
 ]
 }
 ELIFECYCLE Test failed. See above for more details.
 ```

Copy link
Author

Kavidu23 commented Nov 1, 2025
edited
Loading

Local Test Verification

All new hook tests worked locally.
(Attached screenshot shows successful Vitest results.)
test

Copy link
Member

brionmario commented Nov 6, 2025
edited
Loading

@Kavidu23,

I can still see that there's a failure in the CI. Check here: https://github.com/asgardeo/javascript/actions/runs/18818343585/job/53722190236?pr=220

 
 
 > @asgardeo/react@0.5.31 test /home/runner/work/javascript/javascript/packages/react
 > vitest
 
 
 RUN v3.1.3 /home/runner/work/javascript/javascript/packages/react
 
 ⎯⎯⎯⎯⎯⎯ Unhandled Errors ⎯⎯⎯⎯⎯⎯
 
 Vitest caught 1 unhandled error during the test run.
 This might cause false positive tests. Resolve unhandled errors to make sure your tests are not affected.
 
 ⎯⎯⎯⎯⎯⎯ Unhandled Error ⎯⎯⎯⎯⎯⎯⎯
 Error: browserType.launch: Executable doesn't exist at /home/runner/.cache/ms-playwright/chromium_headless_shell-1169/chrome-linux/headless_shell
 ╔═════════════════════════════════════════════════════════════════════════╗
 ║ Looks like Playwright Test or Playwright was just installed or updated. ║
 ║ Please run the following command to download new browsers: ║
 ║ ║
 ║ pnpm exec playwright install ║
 ║ ║
 ║ <3 Playwright Team ║
 ╚═════════════════════════════════════════════════════════════════════════╝
 ❯ ../../node_modules/.pnpm/@vitest+browser@3.1.3_playwright@1.52.0_vite@6.3.5_@types+node@22.15.30_jiti@2.6.0_ligh_b8bcb4faefafff31ab1b9ccbb49ee8ae/node_modules/@vitest/browser/dist/webdriver-BH7t2pDp.js:66:54
 
 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
 
 
 Test Files (4)
 Tests no tests
 Errors 1 error
 Start at 05:33:59
 Duration 792ms (transform 0ms, setup 0ms, collect 0ms, tests 0ms, environment 0ms, prepare 0ms)
 
 error during close browserType.launch: Executable doesn't exist at /home/runner/.cache/ms-playwright/chromium_headless_shell-1169/chrome-linux/headless_shell
 ╔═════════════════════════════════════════════════════════════════════════╗
 ║ Looks like Playwright Test or Playwright was just installed or updated. ║
 ║ Please run the following command to download new browsers: ║
 ║ ║
 ║ pnpm exec playwright install ║
 ║ ║
 ║ <3 Playwright Team ║
 ╚═════════════════════════════════════════════════════════════════════════╝
 at /home/runner/work/javascript/javascript/node_modules/.pnpm/@vitest+browser@3.1.3_playwright@1.52.0_vite@6.3.5_@types+node@22.15.30_jiti@2.6.0_ligh_b8bcb4faefafff31ab1b9ccbb49ee8ae/node_modules/@vitest/browser/dist/webdriver-BH7t2pDp.js:66:54 {
 name: 'Error',
 type: 'Unhandled Error',
 stacks: [
 {
 method: '',
 file: '/home/runner/work/javascript/javascript/node_modules/.pnpm/@vitest+browser@3.1.3_playwright@1.52.0_vite@6.3.5_@types+node@22.15.30_jiti@2.6.0_ligh_b8bcb4faefafff31ab1b9ccbb49ee8ae/node_modules/@vitest/browser/dist/webdriver-BH7t2pDp.js',
 line: 66,
 column: 54
 }
 ]
 }
 ELIFECYCLE Test failed. See above for more details.
 ```
 
 Can you check this.
 
 Run the tests only for `packages/react` and you should be able to reproduce this locally as well.

Copy link
Member

@brionmario brionmario Nov 6, 2025

Choose a reason for hiding this comment

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

Why do we need these files?

- Replaced Playwright browser testing config with Vitest jsdom environment
- Removed unnecessary screenshots and Playwright setup
- Simplified test configuration to match other packages and ensure CI compatibility
- replaced Playwright browser config with Vitest jsdom
- removed unused screenshots and Playwright dependencies
- aligned React package test setup with other modules for CI stability
Copy link

⚠️ No Changeset found

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go.

If these changes should result in a version bump, you need to add a changeset.

Refer Release Documentation to learn how to add a changeset.


export default defineConfig({
test: {
browser: {
Copy link
Member

@brionmario brionmario Nov 6, 2025

Choose a reason for hiding this comment

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

 ║ Looks like Playwright Test or Playwright was just installed or updated. ║
 ║ Please run the following command to download new browsers: ║
 ║ ║
 ║ pnpm exec playwright install ║
 ║ ║
 ║ <3 Playwright Team 

IMO, the previous issue was due to not having the playright dependency. Can't you try adding that and keep playright as the provider. Coz jsdom will go obsolete in the future and we need to stick with playwrite.

Copy link
Member

@brionmario brionmario Nov 6, 2025

Choose a reason for hiding this comment

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

Please check the indentation of these files.
We use 2 spaces.

I hope you have read the CONTRIBUTING guideline and installed the necessary plugins: https://github.com/brionmario/javascript/blob/next/CONTRIBUTING.md#development-tools

Kavidu23 reacted with thumbs up emoji
Copy link
Author

Kavidu23 commented Nov 6, 2025

Thanks @brionmario 🙏

I ran all the tests locally for the packages/react directory after executing pnpm exec playwright install, and everything passed successfully.

The error message in the CI log seems to occur because the Playwright browsers aren’t installed in the CI environment — locally, the Playwright command downloaded the required Chromium binaries, and tests ran without any issue.

The screenshots you saw were auto-generated by Playwright during the test execution.

I’m still quite new to Playwright and browser-based testing setups, so I double-checked the configuration using my code editor’s AI agent. It confirmed that the root cause is missing Playwright browser binaries in the CI runner and explained two approaches:

Option A: Keep Playwright and add pnpm exec playwright install in the CI pipeline before running tests.

Option B: Use jsdom for unit tests .

Since some other packages here already use jsdom, I initially decided to switch to it.

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

Reviewers

@brionmario brionmario brionmario left review comments

At least 1 approving review is required to merge this pull request.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /