Skip to content

Commit

Permalink
Windows and macos unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Machy8 committed Mar 26, 2023
1 parent 9215291 commit 6fff2c7
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 40 deletions.
112 changes: 79 additions & 33 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions packages/bundler/src/Bundler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' : '';

Expand All @@ -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;
}

Expand Down
26 changes: 21 additions & 5 deletions tests/TestUtils.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
const fs = require('fs');
const path = require('path');
const os = require('os')

export default class TestUtils {

private packageName: string|null = null;

private testName: string|null = null;

private isWindowsEnv = os.platform() === 'win32'

constructor(packageName: string, testName: string) {
this.packageName = packageName;
this.testName = testName;
Expand Down Expand Up @@ -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<any, any>, expected: Record<any, any>, tmpFileName: string = null): void {
this.saveTmpFile(tmpFileName, actual);
public testMatchObject(actual: Record<any, any>, expected: Record<any, any>, tmpFileName: string|null = null): void {
if (tmpFileName) {
this.saveTmpFile(tmpFileName, actual);
}

expect(actual).toMatchObject(expected);
}

Expand All @@ -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, ' ');
}

}

0 comments on commit 6fff2c7

Please sign in to comment.