Skip to content

Commit

Permalink
update testing config
Browse files Browse the repository at this point in the history
  • Loading branch information
patinthehat committed Mar 9, 2024
1 parent 6c73d0e commit f29f291
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 54 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ jobs:
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: coverage/coverage-final.json
files: coverage/coverage.json

93 changes: 45 additions & 48 deletions tests/Stopwatch/Stopwatch.test.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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);
});
15 changes: 10 additions & 5 deletions vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down

0 comments on commit f29f291

Please sign in to comment.