diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index a8cbd454..a6ede618 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -9,46 +9,92 @@ on: - main jobs: - tests: - name: Tests build - runs-on: ubuntu-latest + tests-ubuntu: + name: Tests - Ubuntu + runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 + steps: + - uses: actions/checkout@v3 - - uses: pnpm/action-setup@v2 + - uses: pnpm/action-setup@v2 - - uses: actions/setup-node@v3 - with: - node-version: 18 - cache: pnpm + - uses: actions/setup-node@v3 + with: + node-version: 18 + cache: pnpm - - name: Versions - run: node -v && pnpm -v + - name: Versions + run: node -v && pnpm -v - - name: Install packages - run: pnpm repo:init + - name: Install packages + run: pnpm repo:init - - name: Build - run: pnpm build + - name: Build + run: pnpm build - - name: Eslint - run: pnpm eslint:check + - name: Eslint + run: pnpm eslint:check - - name: Jest tests - run: pnpm jest:test+coverage + - name: Jest tests + run: pnpm jest:test+coverage - - name: 'Upload Artifacts' - if: ${{ failure() }} - uses: actions/upload-artifact@v3 - with: - name: artifacts - path: | - packages - !node_modules - !packages/*/**/node_modules + - name: 'Upload Artifacts' + if: ${{ failure() }} + uses: actions/upload-artifact@v3 + with: + name: artifacts + path: | + packages + !node_modules + !packages/*/**/node_modules - - name: Upload coverage to Codecov - uses: codecov/codecov-action@v1 - with: - token: ${{ secrets.CODECOV_TOKEN }} + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v1 + with: + token: ${{ secrets.CODECOV_TOKEN }} + + tests-macos: + name: Tests - Mac OS + runs-on: macos-latest + + steps: + - uses: actions/checkout@v3 + + - uses: pnpm/action-setup@v2 + + - uses: actions/setup-node@v3 + with: + node-version: 18 + cache: pnpm + + - name: Install packages + run: pnpm repo:init + + - name: Build + run: pnpm build + + - name: Jest tests + run: pnpm jest:test + + tests-windows: + name: Tests - Windows + runs-on: windows-latest + + steps: + - uses: actions/checkout@v3 + + - uses: pnpm/action-setup@v2 + + - uses: actions/setup-node@v3 + with: + node-version: 18 + cache: pnpm + + - name: Install packages + run: pnpm repo:init + + - name: Build + run: pnpm build + + - name: Jest tests + run: pnpm jest:test diff --git a/tests/TestUtils.ts b/tests/TestUtils.ts index e7595630..972b645e 100644 --- a/tests/TestUtils.ts +++ b/tests/TestUtils.ts @@ -1,5 +1,6 @@ const fs = require('fs'); const path = require('path'); +const os = require('os') export default class TestUtils { @@ -7,6 +8,8 @@ export default class TestUtils { private testName: string|null = null; + private isWindowsEnv = os.platform() === 'win32' + constructor(packageName: string, testName: string) { this.packageName = packageName; this.testName = testName; @@ -89,13 +92,18 @@ export default class TestUtils { fs.writeFileSync(tmpFilePath, `${fileContentToSave.trim()}\n`); } - public testToBe(actual: any, expected: any, tmpFileName: string = null): void { - this.saveTmpFile(tmpFileName, actual); - expect(actual).toBe(expected); + public testToBe(actual: any, expected: any, tmpFileName: string|null = null): void { + if (tmpFileName) { + this.saveTmpFile(tmpFileName, actual); + } + expect(this.unitWhiteSpace(actual)).toBe(this.unitWhiteSpace(expected)); } - public testMatchObject(actual: Record, expected: Record, tmpFileName: string = null): void { - this.saveTmpFile(tmpFileName, actual); + public testMatchObject(actual: Record, expected: Record, tmpFileName: string|null = null): void { + if (tmpFileName) { + this.saveTmpFile(tmpFileName, actual); + } + expect(actual).toMatchObject(expected); } @@ -120,4 +128,12 @@ export default class TestUtils { this.testToBe(actualContent, this.getExpectedFile(expecedFile), expecedFile); } + private unitWhiteSpace(content: string) { + if (typeof content !== 'string' || !this.isWindowsEnv) { + return content; + }; + + return content.replace(/\s+/g, ' '); + } + }