From b37a9a9179219d4168cb3c0dab7328a454271ac2 Mon Sep 17 00:00:00 2001 From: Omar Kassem Date: Thu, 10 Apr 2025 16:32:54 +0200 Subject: [PATCH 1/9] chore: upgrade vitest to v2 --- packages/playground/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/playground/package.json b/packages/playground/package.json index 77a7ad5e1f..60a9e997c4 100644 --- a/packages/playground/package.json +++ b/packages/playground/package.json @@ -72,7 +72,7 @@ "utility-types": "^3.10.0", "vite": "^4.1.4", "vite-plugin-node-polyfills": "^0.7.0", - "vitest": "^0.29.1", + "vitest": "^2.0.0", "vue-tsc": "^1.2.0" } } From 5722f6974b00ddbf9a82e7b0ad45a98eebd03e83 Mon Sep 17 00:00:00 2001 From: Omar Kassem Date: Thu, 10 Apr 2025 16:40:23 +0200 Subject: [PATCH 2/9] tests: add unit tests for a function as example --- .../tests/utils/extractDomainIP.test.ts | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 packages/playground/tests/utils/extractDomainIP.test.ts diff --git a/packages/playground/tests/utils/extractDomainIP.test.ts b/packages/playground/tests/utils/extractDomainIP.test.ts new file mode 100644 index 0000000000..51a3915d13 --- /dev/null +++ b/packages/playground/tests/utils/extractDomainIP.test.ts @@ -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"); + }); +}); From 73c67a2c04181109e7a643175ef81604672df736 Mon Sep 17 00:00:00 2001 From: Omar Kassem Date: Thu, 10 Apr 2025 16:44:27 +0200 Subject: [PATCH 3/9] workflow: add unit test workflow --- .github/workflows/playground_unit_test.yaml | 41 +++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 .github/workflows/playground_unit_test.yaml diff --git a/.github/workflows/playground_unit_test.yaml b/.github/workflows/playground_unit_test.yaml new file mode 100644 index 0000000000..355c2d45b1 --- /dev/null +++ b/.github/workflows/playground_unit_test.yaml @@ -0,0 +1,41 @@ +# 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 + +on: + pull_request: + branches: + - development + - development_2.7 + paths: + - "packages/playground/**" + +jobs: + unit-tests: + runs-on: ubuntu-latest + env: + NODE_OPTIONS: "--max-old-space-size=8192" + + strategy: + matrix: + node-version: [20.x] + # 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 From 45774308e4db0bc45756762193d38fd9d1eb170c Mon Sep 17 00:00:00 2001 From: Omar Kassem Date: Thu, 10 Apr 2025 16:32:54 +0200 Subject: [PATCH 4/9] chore: upgrade vitest to v2 --- packages/playground/tests/setup.ts | 12 ++++++++++++ packages/playground/vitest.config.ts | 1 + 2 files changed, 13 insertions(+) create mode 100644 packages/playground/tests/setup.ts diff --git a/packages/playground/tests/setup.ts b/packages/playground/tests/setup.ts new file mode 100644 index 0000000000..d9657b080b --- /dev/null +++ b/packages/playground/tests/setup.ts @@ -0,0 +1,12 @@ +// 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'); diff --git a/packages/playground/vitest.config.ts b/packages/playground/vitest.config.ts index 089e6b8064..16751bcd76 100644 --- a/packages/playground/vitest.config.ts +++ b/packages/playground/vitest.config.ts @@ -10,6 +10,7 @@ export default mergeConfig( environment: "jsdom", exclude: [...configDefaults.exclude, "e2e/*"], root: fileURLToPath(new URL("./", import.meta.url)), + setupFiles: ["./tests/setup.ts"], }, }), ); From 59aa6e145c94d2f8c2a92465763d3a20458fc396 Mon Sep 17 00:00:00 2001 From: Omar Kassem Date: Mon, 26 May 2025 18:52:49 +0300 Subject: [PATCH 5/9] Potential fix for code scanning alert no. 31: Workflow does not contain permissions Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> --- .github/workflows/playground_unit_test.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/playground_unit_test.yaml b/.github/workflows/playground_unit_test.yaml index 355c2d45b1..f540712848 100644 --- a/.github/workflows/playground_unit_test.yaml +++ b/.github/workflows/playground_unit_test.yaml @@ -1,6 +1,8 @@ # 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: From c868e539e814b8610e97a5eb1332930a5a38d2b6 Mon Sep 17 00:00:00 2001 From: 0oM4R Date: Mon, 26 May 2025 18:55:38 +0300 Subject: [PATCH 6/9] ci: update CI node version to 22.16 --- .github/workflows/playground_unit_test.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/playground_unit_test.yaml b/.github/workflows/playground_unit_test.yaml index f540712848..4b0fd6f35c 100644 --- a/.github/workflows/playground_unit_test.yaml +++ b/.github/workflows/playground_unit_test.yaml @@ -8,7 +8,7 @@ on: pull_request: branches: - development - - development_2.7 + - development_vitest paths: - "packages/playground/**" @@ -20,7 +20,7 @@ jobs: strategy: matrix: - node-version: [20.x] + node-version: [22.16] # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ steps: From 86e68f2dd34819cc68b1867839fe4708cbba0937 Mon Sep 17 00:00:00 2001 From: 0oM4R Date: Mon, 26 May 2025 18:56:49 +0300 Subject: [PATCH 7/9] ci: trigger playground tests on development branch pushes --- .github/workflows/playground_unit_test.yaml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/playground_unit_test.yaml b/.github/workflows/playground_unit_test.yaml index 4b0fd6f35c..0faad76aaa 100644 --- a/.github/workflows/playground_unit_test.yaml +++ b/.github/workflows/playground_unit_test.yaml @@ -6,6 +6,12 @@ permissions: on: pull_request: + branches: + - development + paths: + - "packages/playground/**" + + push: branches: - development - development_vitest From 1c52adc4e274ae40f052cee3f9d0b6f872a2a510 Mon Sep 17 00:00:00 2001 From: 0oM4R Date: Mon, 26 May 2025 18:59:23 +0300 Subject: [PATCH 8/9] ci: remove push trigger for playground unit tests on development branches --- .github/workflows/playground_unit_test.yaml | 7 ------- 1 file changed, 7 deletions(-) diff --git a/.github/workflows/playground_unit_test.yaml b/.github/workflows/playground_unit_test.yaml index 0faad76aaa..ef6e4fb584 100644 --- a/.github/workflows/playground_unit_test.yaml +++ b/.github/workflows/playground_unit_test.yaml @@ -11,13 +11,6 @@ on: paths: - "packages/playground/**" - push: - branches: - - development - - development_vitest - paths: - - "packages/playground/**" - jobs: unit-tests: runs-on: ubuntu-latest From d7759d7139842709fc40a34907307623db1f55fe Mon Sep 17 00:00:00 2001 From: 0oM4R Date: Wed, 28 May 2025 11:10:13 +0300 Subject: [PATCH 9/9] eslint: format setup script --- packages/playground/tests/setup.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/playground/tests/setup.ts b/packages/playground/tests/setup.ts index d9657b080b..5757962e31 100644 --- a/packages/playground/tests/setup.ts +++ b/packages/playground/tests/setup.ts @@ -4,9 +4,7 @@ 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'); +console.log("Test environment initialized with mock window.env");