|
1 | 1 | import { describe, expect, it } from 'vitest';
|
2 | 2 | import { faker } from '../dist/cjs';
|
3 | 3 |
|
4 |
| -faker.seed(1234); |
| 4 | +const seededRuns = [ |
| 5 | + { |
| 6 | + seed: 42, |
| 7 | + expectations: { |
| 8 | + recent: { |
| 9 | + noArgs: 'number', |
| 10 | + }, |
| 11 | + }, |
| 12 | + }, |
| 13 | + { |
| 14 | + seed: 1337, |
| 15 | + expectations: { |
| 16 | + recent: { |
| 17 | + noArgs: 'number', |
| 18 | + }, |
| 19 | + }, |
| 20 | + }, |
| 21 | + { |
| 22 | + seed: 1211, |
| 23 | + expectations: { |
| 24 | + recent: { |
| 25 | + noArgs: 'number', |
| 26 | + }, |
| 27 | + }, |
| 28 | + }, |
| 29 | +]; |
| 30 | + |
| 31 | +const NON_SEEDED_BASED_RUN = 5; |
| 32 | + |
| 33 | +const functionNames = ['recent']; |
5 | 34 |
|
6 | 35 | describe('time', () => {
|
7 |
| - describe('recent()', () => { |
8 |
| - it('returns the recent timestamp in Unix time format', () => { |
9 |
| - const date = faker.time.recent(); |
10 |
| - expect(typeof date).toBe('number'); |
11 |
| - }); |
| 36 | + // TODO @Shinigami92 2022-02-04: Results are not seeded yet |
| 37 | + for (const { seed, expectations } of seededRuns) { |
| 38 | + describe(`seed: ${seed}`, () => { |
| 39 | + for (const functionName of functionNames) { |
| 40 | + it(`${functionName}()`, () => { |
| 41 | + faker.seed(seed); |
12 | 42 |
|
13 |
| - it('returns the recent timestamp in full time string format', () => { |
14 |
| - const date = faker.time.recent('wide'); |
15 |
| - expect(typeof date).toBe('string'); |
| 43 | + const actual = faker.time[functionName](); |
| 44 | + expect(typeof actual).toEqual(expectations[functionName].noArgs); |
| 45 | + }); |
| 46 | + } |
16 | 47 | });
|
| 48 | + } |
17 | 49 |
|
18 |
| - it('returns the recent timestamp in abbreviated string format', () => { |
19 |
| - const date = faker.time.recent('abbr'); |
20 |
| - expect(typeof date).toBe('string'); |
21 |
| - }); |
| 50 | + // Create and log-back the seed for debug purposes |
| 51 | + faker.seed(Math.ceil(Math.random() * 1_000_000_000)); |
| 52 | + |
| 53 | + describe(`random seeded tests for seed ${faker.seedValue}`, () => { |
| 54 | + for (let i = 1; i <= NON_SEEDED_BASED_RUN; i++) { |
| 55 | + describe('recent()', () => { |
| 56 | + it('should return the recent timestamp in unix time format by default', () => { |
| 57 | + const date = faker.time.recent(); |
| 58 | + expect(typeof date).toBe('number'); |
| 59 | + }); |
| 60 | + |
| 61 | + it('should return the recent timestamp in full time string format', () => { |
| 62 | + const date = faker.time.recent('wide'); |
| 63 | + expect(typeof date).toBe('string'); |
| 64 | + }); |
| 65 | + |
| 66 | + it('should return the recent timestamp in abbreviated string format', () => { |
| 67 | + const date = faker.time.recent('abbr'); |
| 68 | + expect(typeof date).toBe('string'); |
| 69 | + }); |
| 70 | + |
| 71 | + it('should return the recent timestamp in unix time format', () => { |
| 72 | + const date = faker.time.recent('unix'); |
| 73 | + expect(typeof date).toBe('number'); |
| 74 | + }); |
| 75 | + }); |
| 76 | + } |
22 | 77 | });
|
23 | 78 | });
|
0 commit comments