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 Apr 11, 2024
1 parent 1140bfc commit f6f861d
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 38 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:
- 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
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 f6f861d

Please sign in to comment.