|
| 1 | +/* eslint-disable @typescript-eslint/no-require-imports, unicorn/prefer-module */ |
| 2 | +const { describe, expect, it, vi } = await import('vitest'); |
| 3 | +const { allLocales, SimpleFaker } = require('../dist/index.cjs'); |
| 4 | + |
| 5 | +describe('require (cjs)', () => { |
| 6 | + describe.each( |
| 7 | + Object.keys( |
| 8 | + // eslint-disable-next-line @typescript-eslint/no-unsafe-argument |
| 9 | + allLocales |
| 10 | + ) |
| 11 | + )('locale imports', (locale) => { |
| 12 | + it(`should be possible to directly require('@faker-js/faker/locale/${locale}')`, () => { |
| 13 | + const { faker } = require(`../dist/locale/${locale}.cjs`); |
| 14 | + |
| 15 | + expect(faker).toBeDefined(); |
| 16 | + expect(faker.string.alpha()).toBeTypeOf('string'); |
| 17 | + expect(faker.definitions.metadata.title).toBe( |
| 18 | + allLocales[locale].metadata?.title |
| 19 | + ); |
| 20 | + }); |
| 21 | + }); |
| 22 | + |
| 23 | + describe('simpleFaker', () => { |
| 24 | + it('should not log anything on startup', () => { |
| 25 | + const spies = Object.keys(console) |
| 26 | + .filter( |
| 27 | + (key) => |
| 28 | + // @ts-expect-error: cts cant use `as keyof typeof console` |
| 29 | + typeof console[key] === 'function' |
| 30 | + ) |
| 31 | + .map((methodName) => |
| 32 | + vi.spyOn( |
| 33 | + console, |
| 34 | + // @ts-expect-error: cts cant use `as keyof typeof console` |
| 35 | + methodName |
| 36 | + ) |
| 37 | + ); |
| 38 | + |
| 39 | + expect(require('..').simpleFaker).toBeDefined(); |
| 40 | + |
| 41 | + expect(new SimpleFaker()).toBeDefined(); |
| 42 | + |
| 43 | + for (const spy of spies) { |
| 44 | + expect(spy).not.toHaveBeenCalled(); |
| 45 | + spy.mockRestore(); |
| 46 | + } |
| 47 | + }); |
| 48 | + }); |
| 49 | +}); |
0 commit comments