diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..995484d --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,39 @@ +name: Test + +# Controls when the action will run. +on: + # Triggers the workflow on pull request events but only for the main branch + pull_request: + branches: [main] + push: + branches: [main] + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +# A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + test: + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest] + + # Steps represent a sequence of tasks that will be executed as part of the job + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Install Pnpm + run: corepack enable + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: 22 + cache: "pnpm" + + - name: Install Dependencies + run: pnpm install && npx playwright install + + - name: Run Test + run: pnpm run test diff --git a/package.json b/package.json index 8cbbce4..51872b9 100644 --- a/package.json +++ b/package.json @@ -37,6 +37,7 @@ "@types/node": "~16.11.7", "prettier": "~2.8.1", "rimraf": "~3.0.2", + "strip-ansi": "^7.1.0", "supports-color": "^9.4.0", "typescript": "~5.0.4", "vitest": "^2.0.5" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index b42ffd8..f35cbcb 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -23,6 +23,9 @@ importers: rimraf: specifier: ~3.0.2 version: 3.0.2 + strip-ansi: + specifier: ^7.1.0 + version: 7.1.0 supports-color: specifier: ^9.4.0 version: 9.4.0 @@ -31,7 +34,7 @@ importers: version: 5.0.4 vitest: specifier: ^2.0.5 - version: 2.0.5(@types/node@16.11.7)(supports-color@9.4.0) + version: 2.0.5(@types/node@16.11.7)(supports-color@9.4.0)(terser@5.19.2) packages: @@ -1028,6 +1031,10 @@ packages: resolution: {integrity: sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==} engines: {node: '>=8'} + ansi-regex@6.1.0: + resolution: {integrity: sha512-7HSX4QQb4CspciLpVFwyRe79O3xsIZDDLER21kERQ71oaPodF8jL725AgJMFAYbooIqolJoRLuM81SpeUkpkvA==} + engines: {node: '>=12'} + ansi-styles@3.2.1: resolution: {integrity: sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==} engines: {node: '>=4'} @@ -2438,6 +2445,10 @@ packages: resolution: {integrity: sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==} engines: {node: '>=8'} + strip-ansi@7.1.0: + resolution: {integrity: sha512-iq6eVVI64nQQTRYq2KtEg2d2uU7LElhTJwsH4YzIHZshxlgZms/wIc4VoDQTlG/IvVIrBKG06CrZnp0qv7hkcQ==} + engines: {node: '>=12'} + strip-bom@3.0.0: resolution: {integrity: sha512-vavAMRXOgBVNF6nyEEmL3DBK19iRpDcoIwW+swQ+CbGiu7lju6t+JklA1MHweoWtadgt4ISVUsXLyDq34ddcwA==} engines: {node: '>=4'} @@ -2829,7 +2840,7 @@ snapshots: '@babel/code-frame': 7.23.5 '@babel/generator': 7.23.6 '@babel/helper-compilation-targets': 7.23.6 - '@babel/helper-module-transforms': 7.23.3(@babel/core@7.23.9) + '@babel/helper-module-transforms': 7.23.3(@babel/core@7.23.9(supports-color@9.4.0)) '@babel/helpers': 7.23.9(supports-color@9.4.0) '@babel/parser': 7.23.9 '@babel/template': 7.23.9 @@ -2873,7 +2884,7 @@ snapshots: dependencies: '@babel/types': 7.23.9 - '@babel/helper-module-transforms@7.23.3(@babel/core@7.23.9)': + '@babel/helper-module-transforms@7.23.3(@babel/core@7.23.9(supports-color@9.4.0))': dependencies: '@babel/core': 7.23.9(supports-color@9.4.0) '@babel/helper-environment-visitor': 7.22.20 @@ -3309,7 +3320,7 @@ snapshots: '@esbuild/win32-x64@0.21.5': optional: true - '@eslint-community/eslint-utils@4.4.0(eslint@8.50.0)': + '@eslint-community/eslint-utils@4.4.0(eslint@8.50.0(supports-color@9.4.0))': dependencies: eslint: 8.50.0(supports-color@9.4.0) eslint-visitor-keys: 3.4.3 @@ -3505,6 +3516,7 @@ snapshots: tapable: 2.2.1 terser: 5.19.2 tsconfig-paths-webpack-plugin: 4.1.0 + optionalDependencies: typescript: 5.0.4 transitivePeerDependencies: - debug @@ -3762,6 +3774,8 @@ snapshots: ansi-regex@5.0.1: {} + ansi-regex@6.1.0: {} + ansi-styles@3.2.1: dependencies: color-convert: 1.9.3 @@ -3992,11 +4006,13 @@ snapshots: debug@4.3.4(supports-color@9.4.0): dependencies: ms: 2.1.2 + optionalDependencies: supports-color: 9.4.0 debug@4.3.6(supports-color@9.4.0): dependencies: ms: 2.1.2 + optionalDependencies: supports-color: 9.4.0 decamelize-keys@1.1.1: @@ -4210,7 +4226,7 @@ snapshots: eslint@8.50.0(supports-color@9.4.0): dependencies: - '@eslint-community/eslint-utils': 4.4.0(eslint@8.50.0) + '@eslint-community/eslint-utils': 4.4.0(eslint@8.50.0(supports-color@9.4.0)) '@eslint-community/regexpp': 4.9.0 '@eslint/eslintrc': 2.1.2(supports-color@9.4.0) '@eslint/js': 8.50.0 @@ -5295,6 +5311,10 @@ snapshots: dependencies: ansi-regex: 5.0.1 + strip-ansi@7.1.0: + dependencies: + ansi-regex: 6.1.0 + strip-bom@3.0.0: {} strip-final-newline@3.0.0: {} @@ -5479,13 +5499,13 @@ snapshots: spdx-correct: 3.2.0 spdx-expression-parse: 3.0.1 - vite-node@2.0.5(@types/node@16.11.7)(supports-color@9.4.0): + vite-node@2.0.5(@types/node@16.11.7)(supports-color@9.4.0)(terser@5.19.2): dependencies: cac: 6.7.14 debug: 4.3.6(supports-color@9.4.0) pathe: 1.1.2 tinyrainbow: 1.2.0 - vite: 5.4.3(@types/node@16.11.7) + vite: 5.4.3(@types/node@16.11.7)(terser@5.19.2) transitivePeerDependencies: - '@types/node' - less @@ -5497,19 +5517,19 @@ snapshots: - supports-color - terser - vite@5.4.3(@types/node@16.11.7): + vite@5.4.3(@types/node@16.11.7)(terser@5.19.2): dependencies: - '@types/node': 16.11.7 esbuild: 0.21.5 postcss: 8.4.45 rollup: 4.21.2 optionalDependencies: + '@types/node': 16.11.7 fsevents: 2.3.3 + terser: 5.19.2 - vitest@2.0.5(@types/node@16.11.7)(supports-color@9.4.0): + vitest@2.0.5(@types/node@16.11.7)(supports-color@9.4.0)(terser@5.19.2): dependencies: '@ampproject/remapping': 2.3.0 - '@types/node': 16.11.7 '@vitest/expect': 2.0.5 '@vitest/pretty-format': 2.0.5 '@vitest/runner': 2.0.5 @@ -5525,9 +5545,11 @@ snapshots: tinybench: 2.9.0 tinypool: 1.0.1 tinyrainbow: 1.2.0 - vite: 5.4.3(@types/node@16.11.7) - vite-node: 2.0.5(@types/node@16.11.7)(supports-color@9.4.0) + vite: 5.4.3(@types/node@16.11.7)(terser@5.19.2) + vite-node: 2.0.5(@types/node@16.11.7)(supports-color@9.4.0)(terser@5.19.2) why-is-node-running: 2.3.0 + optionalDependencies: + '@types/node': 16.11.7 transitivePeerDependencies: - less - lightningcss diff --git a/tests/__snapshots__/logger.test.ts.snap b/tests/__snapshots__/logger.test.ts.snap index a616063..8eead83 100644 --- a/tests/__snapshots__/logger.test.ts.snap +++ b/tests/__snapshots__/logger.test.ts.snap @@ -3,19 +3,19 @@ exports[`logger > should create new logger with info level correctly 1`] = ` [ [ - "error  this is a error message", + "error this is a error message", ], [ - "info  this is an info message", + "info this is an info message", ], [ - "warn  this is a warn message", + "warn this is a warn message", ], [ - "ready  this is a ready message", + "ready this is a ready message", ], [ - "success this is a success message", + "success this is a success message", ], ] `; @@ -23,10 +23,10 @@ exports[`logger > should create new logger with info level correctly 1`] = ` exports[`logger > should create new logger with warn level correctly 1`] = ` [ [ - "error  this is a error message", + "error this is a error message", ], [ - "warn  this is a warn message", + "warn this is a warn message", ], ] `; @@ -34,30 +34,30 @@ exports[`logger > should create new logger with warn level correctly 1`] = ` exports[`logger > should log as expected 1`] = ` [ [ - "😊 Rslog v1.0.0 -", + "😊 Rslog v1.0.0 +", ], [ "this is a log message", ], [ - "info  this is an info message", + "info this is an info message", ], [ - "warn  this is a warn message", + "warn this is a warn message", ], [ - "ready  this is a ready message", + "ready this is a ready message", ], [ - "success this is a success message", + "success this is a success message", ], ] `; exports[`logger > should log error with stack correctly 1`] = ` -error  this is an error message - at /tests/logger.test.ts:68:18 +error this is an error message + at /tests/logger.test.ts:81:18 at file:///node_modules/.pnpm/@vitest+runner@2.0.5/node_modules/@vitest/runner/dist/index.js:146:14 at file:///node_modules/.pnpm/@vitest+runner@2.0.5/node_modules/@vitest/runner/dist/index.js:61:7 at runTest (file:///node_modules/.pnpm/@vitest+runner@2.0.5/node_modules/@vitest/runner/dist/index.js:960:17) @@ -65,6 +65,6 @@ exports[`logger > should log error with stack correctly 1`] = ` at runSuite (file:///node_modules/.pnpm/@vitest+runner@2.0.5/node_modules/@vitest/runner/dist/index.js:1116:15) at runFiles (file:///node_modules/.pnpm/@vitest+runner@2.0.5/node_modules/@vitest/runner/dist/index.js:1173:5) at startTests (file:///node_modules/.pnpm/@vitest+runner@2.0.5/node_modules/@vitest/runner/dist/index.js:1182:3) - at file:///node_modules/.pnpm/vitest@2.0.5_@types+node@16.11.7_supports-color@9.4.0/node_modules/vitest/dist/chunks/runBaseTests.CyvqmuC9.js:130:11 - at withEnv (file:///node_modules/.pnpm/vitest@2.0.5_@types+node@16.11.7_supports-color@9.4.0/node_modules/vitest/dist/chunks/runBaseTests.CyvqmuC9.js:94:5) + at file:///node_modules/.pnpm/vitest@2.0.5_@types+node@16.11.7_supports-color@9.4.0_terser@5.19.2/node_modules/vitest/dist/chunks/runBaseTests.CyvqmuC9.js:130:11 + at withEnv (file:///node_modules/.pnpm/vitest@2.0.5_@types+node@16.11.7_supports-color@9.4.0_terser@5.19.2/node_modules/vitest/dist/chunks/runBaseTests.CyvqmuC9.js:94:5) `; diff --git a/tests/logger.test.ts b/tests/logger.test.ts index b5af577..67a3e0c 100644 --- a/tests/logger.test.ts +++ b/tests/logger.test.ts @@ -1,13 +1,14 @@ import { createLogger, logger } from '../src'; import { join } from 'path'; import { expect, test, describe, vi, Mock } from 'vitest'; +import stripAnsi from 'strip-ansi'; const root = join(__dirname, '..'); expect.addSnapshotSerializer({ test: val => typeof val === 'string' && val.includes(root), print: val => { - return (val as any).toString().replaceAll(root, ''); + return stripAnsi((val as any).toString().replaceAll(root, '')); }, }); @@ -23,7 +24,11 @@ describe('logger', () => { logger.debug('this is a debug message'); logger.success('this is a success message'); - expect((console.log as Mock).mock.calls).toMatchSnapshot(); + expect( + (console.log as Mock).mock.calls.map(items => + items.map(item => stripAnsi(item.toString())), + ), + ).toMatchSnapshot(); }); test('should create new logger with info level correctly', () => { @@ -41,7 +46,11 @@ describe('logger', () => { logger.debug('this is a debug message'); logger.success('this is a success message'); - expect((console.log as Mock).mock.calls).toMatchSnapshot(); + expect( + (console.log as Mock).mock.calls.map(items => + items.map(item => stripAnsi(item.toString())), + ), + ).toMatchSnapshot(); }); test('should create new logger with warn level correctly', () => { @@ -59,7 +68,11 @@ describe('logger', () => { logger.debug('this is a debug message'); logger.success('this is a success message'); - expect((console.log as Mock).mock.calls).toMatchSnapshot(); + expect( + (console.log as Mock).mock.calls.map(items => + items.map(item => stripAnsi(item.toString())), + ), + ).toMatchSnapshot(); }); test('should log error with stack correctly', () => {