Simple tests for timedExecution
This commit is contained in:
parent
29e06fdf91
commit
b177a348b7
@ -1,4 +1,4 @@
|
|||||||
import safePath from '$lib';
|
import { safePath, timedExecution } from '$lib';
|
||||||
import { describe, it, expect } from 'vitest';
|
import { describe, it, expect } from 'vitest';
|
||||||
|
|
||||||
describe('safe path', () => {
|
describe('safe path', () => {
|
||||||
@ -30,3 +30,21 @@ describe('safe path', () => {
|
|||||||
expect(safePath('./uplodas', '..foobar..')).toBe(true);
|
expect(safePath('./uplodas', '..foobar..')).toBe(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('timedExecution', () => {
|
||||||
|
const asyncIdentity = async (v) => v;
|
||||||
|
const identity = (v) => v;
|
||||||
|
|
||||||
|
it('works with async', async () => {
|
||||||
|
const { executionTime, result } = await timedExecution(() => asyncIdentity(5));
|
||||||
|
expect(result).toBe(5);
|
||||||
|
// execution time is always positive
|
||||||
|
expect(executionTime).toBeGreaterThanOrEqual(0);
|
||||||
|
});
|
||||||
|
it('works with sync', async () => {
|
||||||
|
const { executionTime, result } = await timedExecution(() => identity(5));
|
||||||
|
expect(result).toBe(5);
|
||||||
|
// execution time is always positive
|
||||||
|
expect(executionTime).toBeGreaterThanOrEqual(0);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
Reference in New Issue
Block a user