-
Notifications
You must be signed in to change notification settings - Fork 9
Vitest updates #4039
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
Merged
Merged
Vitest updates #4039
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
b37a9a9
chore: upgrade vitest to v2
0oM4R 5722f69
tests:
0oM4R 73c67a2
workflow: add unit test workflow
0oM4R 462f090
Merge remote-tracking branch 'origin/development' into development_vi…
0oM4R 4577430
chore: upgrade vitest to v2
0oM4R 59aa6e1
Potential fix for code scanning alert no. 31: Workflow does not conta…
0oM4R c868e53
ci: update CI node version to 22.16
0oM4R 86e68f2
ci: trigger playground tests on development branch pushes
0oM4R 1c52adc
ci: remove push trigger for playground unit tests on development bran…
0oM4R d7759d7
eslint: format setup script
0oM4R File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| # This workflow will do a clean install of node dependencies, cache/restore them, build the source code using yarn build:app run unit tests using yarn test:unit. | ||
|
|
||
| name: Playground Unit tests | ||
| permissions: | ||
| contents: read | ||
|
|
||
| on: | ||
| pull_request: | ||
| branches: | ||
| - development | ||
| paths: | ||
| - "packages/playground/**" | ||
|
|
||
| jobs: | ||
| unit-tests: | ||
| runs-on: ubuntu-latest | ||
| env: | ||
| NODE_OPTIONS: "--max-old-space-size=8192" | ||
|
|
||
| strategy: | ||
| matrix: | ||
| node-version: [22.16] | ||
| # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - name: Setup Node.js ${{ matrix.node-version }} | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: ${{ matrix.node-version }} | ||
| cache: "yarn" | ||
| cache-dependency-path: "**/yarn.lock" | ||
|
|
||
| - name: Install dependencies | ||
| run: | | ||
| yarn install | ||
| - name: Build | ||
| run: | | ||
| lerna run build --no-private | ||
| - name: Run unit tests | ||
| run: yarn workspace @threefold/playground test:unit |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| // Vitest setup file - runs before all tests | ||
| // Set up mock window.env that matches the development environment | ||
| // @ts-ignore - Add window object for test environment | ||
| global.window = global.window || {}; | ||
| // @ts-ignore - Add env object to window | ||
| global.window.env = { | ||
| // set the needed env variables for the tests | ||
| }; | ||
|
|
||
| console.log("Test environment initialized with mock window.env"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
|
|
||
| import { extractDomainIP } from "../../src/utils/gateway"; | ||
|
|
||
| describe("extractDomainIP", () => { | ||
| it("should extract the domain from a URL with a protocol", () => { | ||
| const domain = extractDomainIP("https://example.com:8080"); | ||
| expect(domain).toBe("example.com"); | ||
| }); | ||
|
|
||
| it("should extract the IPv6 address from a URL", () => { | ||
| const ipv6 = extractDomainIP("https://[::1]:8080"); | ||
| expect(ipv6).toBe("::1"); | ||
| }); | ||
|
|
||
| it("should throw an error when there is no domain or IP address", () => { | ||
| expect(() => extractDomainIP("http://:8080")).toThrow( | ||
| 'Invalid input "http://:8080": No domain or IP address found.', | ||
| ); | ||
| }); | ||
|
|
||
| it("should throw an error for invalid IPv6 format", () => { | ||
| expect(() => extractDomainIP("https://[]:8080")).toThrow( | ||
| 'Invalid input "https://[]:8080": Invalid IPv6 address format.', | ||
| ); | ||
| }); | ||
|
|
||
| it("should extract the domain from a URL without a port", () => { | ||
| const domain = extractDomainIP("https://example.com"); | ||
| expect(domain).toBe("example.com"); | ||
| }); | ||
|
|
||
| it("should extract the IPv4 address from a URL", () => { | ||
| const ipv4 = extractDomainIP("http://192.168.0.1:3000"); | ||
| expect(ipv4).toBe("192.168.0.1"); | ||
| }); | ||
|
|
||
| it("should handle plain domain strings without protocols", () => { | ||
| const domain = extractDomainIP("example.com"); | ||
| expect(domain).toBe("example.com"); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need to add test cases for urls with query params?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not supported by the extractDomainIP function, Please open a separate issue for that if needed, as these tests were added only to verify the functionality of Vitest configuration