diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index d1ec79f..39214c7 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -35,5 +35,5 @@ jobs: uses: codecov/codecov-action@v4 with: token: ${{ secrets.CODECOV_TOKEN }} - files: coverage/coverage-final.json + files: coverage/coverage.json diff --git a/tests/Stopwatch/Stopwatch.test.ts b/tests/Stopwatch/Stopwatch.test.ts index 7c4ac76..36d009f 100644 --- a/tests/Stopwatch/Stopwatch.test.ts +++ b/tests/Stopwatch/Stopwatch.test.ts @@ -1,6 +1,5 @@ -/* eslint-disable @typescript-eslint/ban-ts-comment */ /* eslint-disable no-undef */ -import { expect, it, describe, beforeEach } from 'vitest'; +import { beforeEach, expect, it } from 'vitest'; import { usleep } from '../../src/lib/utils'; import Stopwatch from './../../src/Stopwatch/Stopwatch'; @@ -11,50 +10,48 @@ beforeEach(() => { stopwatch = new Stopwatch('one'); }); -describe('Stopwatch', () => { - it('can created an unnamed stopwatch', () => { - const sw = new Stopwatch(); - expect(sw.name).toBeUndefined(); - }); - - it('can be reset', () => { - stopwatch.startedAt = 100; - stopwatch.endedAt = 200; - - stopwatch.start('one'); - stopwatch.lap(); - stopwatch.stop(); - - stopwatch.reset(); - - expect(stopwatch.startedAt).toBe(0); - expect(stopwatch.endedAt).toBe(0); - expect(stopwatch.getLaps().length).toBe(0); - }); - - it('can get the total duration', async () => { - stopwatch.start('one'); - usleep(100); - stopwatch.stop(); - - expect(Math.floor(stopwatch.totalDuration() / 10)).toBe(10); - }); - - it('can get the previous duration', async () => { - stopwatch.start('one'); - usleep(100); - stopwatch.lap(); - usleep(100); - const ev2 = stopwatch.lap(); - expect(Math.floor(ev2.getPreviousDuration() / 10)).toBe(10); - stopwatch.stop(); - }); - - it('can get the laps', async () => { - stopwatch.start('one'); - usleep(5); - stopwatch.stop(); - - expect(stopwatch.getLaps().length).toBe(1); - }); +it('can created an unnamed stopwatch', () => { + const sw = new Stopwatch(); + expect(sw.name).toBeUndefined(); +}); + +it('can be reset', () => { + stopwatch.startedAt = 100; + stopwatch.endedAt = 200; + + stopwatch.start('one'); + stopwatch.lap(); + stopwatch.stop(); + + stopwatch.reset(); + + expect(stopwatch.startedAt).toBe(0); + expect(stopwatch.endedAt).toBe(0); + expect(stopwatch.getLaps().length).toBe(0); +}); + +it('can get the total duration', async () => { + stopwatch.start('one'); + usleep(100); + stopwatch.stop(); + + expect(Math.floor(stopwatch.totalDuration() / 10)).toBe(10); +}); + +it('can get the previous duration', async () => { + stopwatch.start('one'); + usleep(100); + stopwatch.lap(); + usleep(100); + const ev2 = stopwatch.lap(); + expect(Math.floor(ev2.getPreviousDuration() / 10)).toBe(10); + stopwatch.stop(); +}); + +it('can get the laps', async () => { + stopwatch.start('one'); + usleep(5); + stopwatch.stop(); + + expect(stopwatch.getLaps().length).toBe(1); }); diff --git a/vite.config.js b/vite.config.js index f4f614f..3d64f3f 100644 --- a/vite.config.js +++ b/vite.config.js @@ -2,15 +2,20 @@ import { defineConfig } from 'vitest/config'; export default defineConfig({ test: { - passWithNoTests: true, name: 'Ray', - coverage: { - exclude: ['**/node_modules/**', '**/dist/**', './coverage/**', '**/.git/**'], - }, + globals: true, + passWithNoTests: true, + watch: false, alias: { '@/': new URL('./src/', import.meta.url).pathname, }, - watch: false, + coverage: { + all: true, + include: ['src/**/*.ts'], + reporter: [['text'], ['json', { file: 'coverage.json' }]], + }, + include: ['tests/**/*.ts', 'tests/**/*.js'], + reporters: ['default', process.env.CI ? 'github-actions' : 'verbose'], }, build: { rollupOptions: {