Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: setup test workflow #21

Merged
merged 3 commits into from
Nov 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
48 changes: 35 additions & 13 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 17 additions & 17 deletions tests/__snapshots__/logger.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,68 +3,68 @@
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",
],
]
`;

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",
],
]
`;

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 <ROOT>/tests/logger.test.ts:68:18
error this is an error message
at <ROOT>/tests/logger.test.ts:81:18
at file://<ROOT>/node_modules/.pnpm/@[email protected]/node_modules/@vitest/runner/dist/index.js:146:14
at file://<ROOT>/node_modules/.pnpm/@[email protected]/node_modules/@vitest/runner/dist/index.js:61:7
at runTest (file://<ROOT>/node_modules/.pnpm/@[email protected]/node_modules/@vitest/runner/dist/index.js:960:17)
at runSuite (file://<ROOT>/node_modules/.pnpm/@[email protected]/node_modules/@vitest/runner/dist/index.js:1116:15)
at runSuite (file://<ROOT>/node_modules/.pnpm/@[email protected]/node_modules/@vitest/runner/dist/index.js:1116:15)
at runFiles (file://<ROOT>/node_modules/.pnpm/@[email protected]/node_modules/@vitest/runner/dist/index.js:1173:5)
at startTests (file://<ROOT>/node_modules/.pnpm/@[email protected]/node_modules/@vitest/runner/dist/index.js:1182:3)
at file://<ROOT>/node_modules/.pnpm/[email protected]_@[email protected][email protected].0/node_modules/vitest/dist/chunks/runBaseTests.CyvqmuC9.js:130:11
at withEnv (file://<ROOT>/node_modules/.pnpm/[email protected]_@[email protected][email protected].0/node_modules/vitest/dist/chunks/runBaseTests.CyvqmuC9.js:94:5)
at file://<ROOT>/node_modules/.pnpm/[email protected]_@[email protected][email protected].[email protected]/node_modules/vitest/dist/chunks/runBaseTests.CyvqmuC9.js:130:11
at withEnv (file://<ROOT>/node_modules/.pnpm/[email protected]_@[email protected][email protected].[email protected]/node_modules/vitest/dist/chunks/runBaseTests.CyvqmuC9.js:94:5)
`;
21 changes: 17 additions & 4 deletions tests/logger.test.ts
Original file line number Diff line number Diff line change
@@ -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, '<ROOT>');
return stripAnsi((val as any).toString().replaceAll(root, '<ROOT>'));
},
});

Expand All @@ -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', () => {
Expand All @@ -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', () => {
Expand All @@ -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', () => {
Expand Down