From 9058f209dd932261256b944ad0117867452ff0fc Mon Sep 17 00:00:00 2001 From: Marco Pasqualetti <24919330+marcalexiei@users.noreply.github.com> Date: Tue, 26 Nov 2024 17:50:53 +0100 Subject: [PATCH] ci: add Windows and MacOS to test matrix for both `rust` and `typescript` (#158) --- .github/workflows/repo-root-ci.yml | 2 +- .github/workflows/rust.yml | 44 +++++++++++-------- .github/workflows/typescript.yml | 15 +++++-- package.json | 1 + .../tests/generator.spec.ts | 36 +++++---------- 5 files changed, 52 insertions(+), 46 deletions(-) diff --git a/.github/workflows/repo-root-ci.yml b/.github/workflows/repo-root-ci.yml index e056055c..026a9efc 100644 --- a/.github/workflows/repo-root-ci.yml +++ b/.github/workflows/repo-root-ci.yml @@ -28,4 +28,4 @@ jobs: uses: ./.github/actions/install-node-dependencies - name: Test project - run: pnpm repo:root:format + run: pnpm repo:root:format:check diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index ed5f9712..a7010ebd 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -14,6 +14,32 @@ env: CARGO_TERM_COLOR: always jobs: + build_and_test: + if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name + name: Build and test rust crates + + strategy: + fail-fast: true + matrix: + os: + - 'ubuntu-latest' + - 'macos-latest' + - 'windows-latest' + toolchain: + - stable + - beta + - nightly + + runs-on: ${{ matrix.os }} + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - run: rustup update ${{ matrix.toolchain }} && rustup default ${{ matrix.toolchain }} + - run: cargo build --verbose + - run: cargo test --verbose + lint_and_fmt: if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name name: Check format and lint rust crates @@ -25,21 +51,3 @@ jobs: - run: cargo fmt --all -- --check - run: cargo clippy -- -D warnings - - build_and_test: - if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name - name: Build and test rust crates - runs-on: ubuntu-latest - strategy: - matrix: - toolchain: - - stable - - beta - - nightly - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - run: rustup update ${{ matrix.toolchain }} && rustup default ${{ matrix.toolchain }} - - run: cargo build --verbose - - run: cargo test --verbose diff --git a/.github/workflows/typescript.yml b/.github/workflows/typescript.yml index 3d1ff1f9..25c3b9e4 100644 --- a/.github/workflows/typescript.yml +++ b/.github/workflows/typescript.yml @@ -11,11 +11,20 @@ on: - 'packages/**' jobs: - build-and-test: + build_and_test: if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name name: Check build and test timeout-minutes: 15 - runs-on: ubuntu-latest + + strategy: + fail-fast: true + matrix: + os: + - 'ubuntu-latest' + - 'macos-latest' + - 'windows-latest' + + runs-on: ${{ matrix.os }} steps: - name: Checkout code @@ -30,7 +39,7 @@ jobs: - name: Test project run: pnpm test - fmt-lint-and-types: + lint_and_fmt: if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name name: Check format and lint runs-on: ubuntu-latest diff --git a/package.json b/package.json index 29a10546..8861837b 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,7 @@ "docs:format": "turbo format --filter=documentation", "docs:format:check": "turbo format:check --filter=documentation", "docs:types": "turbo types --filter=documentation", + "repo:root:format:check": "prettier . !./apps/** !./assets/** !./benches/** !./crates !./examples !./packages/** --check", "repo:root:format": "prettier . !./apps/** !./assets/** !./benches/** !./crates !./examples !./packages/** --write", "check-all": "turbo build lint format:check types --filter=!./examples" }, diff --git a/packages/fs-router-vite-plugin/tests/generator.spec.ts b/packages/fs-router-vite-plugin/tests/generator.spec.ts index fefbeff6..a0883c25 100644 --- a/packages/fs-router-vite-plugin/tests/generator.spec.ts +++ b/packages/fs-router-vite-plugin/tests/generator.spec.ts @@ -2,40 +2,28 @@ import fs from 'fs/promises' import { describe, it, expect } from 'vitest' import { routeGenerator } from '../src/generator' -function makeFolderDir(folder: string) { - return process.cwd() + `/tests/generator/${folder}` -} - -async function getRouteTreeFileText(folder: string) { - const dir = makeFolderDir(folder) - return await fs.readFile(dir + '/routeTree.gen.ts', 'utf-8') -} - -async function getExpectedRouteTreeFileText(folder: string) { - const dir = makeFolderDir(folder) - const location = dir + '/routeTree.expected.ts' - return await fs.readFile(location, 'utf-8') -} - describe('generator works', async () => { const folderNames = await fs.readdir(process.cwd() + '/tests/generator') - it.each(folderNames.map((folder) => [folder]))( + it.each(folderNames)( 'should wire-up the routes for a "%s" tree', async (folderName) => { - const currentFolder = `${process.cwd()}/tests/generator/${folderName}` + const testDirPath = `${process.cwd()}/tests/generator/${folderName}` await routeGenerator({ - folderName: `${currentFolder}/routes`, - generatedRouteTree: `${currentFolder}/routeTree.gen.ts`, + folderName: `${testDirPath}/routes`, + generatedRouteTree: `${testDirPath}/routeTree.gen.ts`, }) - const [expectedRouteTree, generatedRouteTree] = await Promise.all([ - getExpectedRouteTreeFileText(folderName), - getRouteTreeFileText(folderName), - ]) + const generatedFilePath = `${testDirPath}/routeTree.gen.ts` + const expectedFilePath = `${testDirPath}/routeTree.expected.ts` - expect(generatedRouteTree).equal(expectedRouteTree) + const generatedFileContent = await fs.readFile(generatedFilePath, 'utf-8') + + await expect(generatedFileContent).toMatchFileSnapshot( + expectedFilePath, + `${generatedFilePath} content should be equal to ${expectedFilePath}`, + ) }, ) })