From 8edd73ac5a488f1cd8a5ca6466cc79093e3b9fd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr?= <8machy@seznam.cz> Date: Sat, 14 Jan 2023 10:05:11 +0000 Subject: [PATCH] Windows and macos unit tests --- .github/workflows/tests.yaml | 112 ++++++++++++++++++++++---------- packages/bundler/src/Bundler.ts | 4 +- tests/TestUtils.ts | 27 ++++++-- 3 files changed, 103 insertions(+), 40 deletions(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 6d81c70c..1206e133 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -9,46 +9,92 @@ on: - master 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: 16 - cache: pnpm + - uses: actions/setup-node@v3 + with: + node-version: 16 + 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: 16 + 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: 16 + cache: pnpm + + - name: Install packages + run: pnpm repo:init + + - name: Build + run: pnpm build + + - name: Jest tests + run: pnpm jest:test diff --git a/packages/bundler/src/Bundler.ts b/packages/bundler/src/Bundler.ts index 08d832cc..46416add 100644 --- a/packages/bundler/src/Bundler.ts +++ b/packages/bundler/src/Bundler.ts @@ -786,7 +786,7 @@ export class Bundler { 'bundler:beforeCssFileCreated', { content: generatedCss, bundleConfig } ); - let outputFileContent = hookData.content; + let outputFileContent: string = hookData.content; const isDev = bundleBuildCache.compiler.dev; const whiteSpace = isDev ? '\n' : ''; @@ -796,7 +796,7 @@ export class Bundler { typeof exportLayerName === 'undefined' || !exportLayerName.includes(bundleConfig.cssLayer) ? '' : `@layer ${this.cssLayersOrder.order};${whiteSpace.repeat(2)}`; - layerContent += `@layer ${bundleConfig.cssLayer} {${whiteSpace + outputFileContent + whiteSpace}}`; + layerContent += `@layer ${bundleConfig.cssLayer} {${whiteSpace}${outputFileContent}${whiteSpace}}`; outputFileContent = layerContent; } diff --git a/tests/TestUtils.ts b/tests/TestUtils.ts index e7595630..81721b46 100644 --- a/tests/TestUtils.ts +++ b/tests/TestUtils.ts @@ -89,13 +89,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 +125,16 @@ export default class TestUtils { this.testToBe(actualContent, this.getExpectedFile(expecedFile), expecedFile); } + private unitWhiteSpace(content: string) { + if (typeof content !== 'string') { + return content; + }; + + return content + .replace(/\r|\rn/g, '\n') + .replace(/\n/g, '___NEWLINE___') + .replace(/\s+/g, ' ') + .replace(/___NEWLINE___/g, '\n'); + } + }