Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion eslint.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ const config: ReturnType<typeof tseslint.config> = tseslint.config(
},
{
name: 'test/**/*.ts overrides',
files: ['test/**/*.spec.ts', 'test/**/*.spec.d.ts'],
files: ['test/**/*.spec.ts', 'test/**/*.spec.cts', 'test/**/*.spec.d.ts'],
plugins: {
vitest: eslintPluginVitest,
},
Expand Down Expand Up @@ -285,6 +285,13 @@ const config: ReturnType<typeof tseslint.config> = tseslint.config(
typecheck: true,
},
},
},
{
files: ['test/**/*.spec.cts'],
rules: {
'@typescript-eslint/no-require-imports': 'off',
'unicorn/prefer-module': 'off',
},
}
//#endregion
);
Expand Down
13 changes: 0 additions & 13 deletions test/locale-imports.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,6 @@ import { allLocales } from '../src';
import { keys } from '../src/internal/keys';

describe.each(keys(allLocales))('locale imports', (locale) => {
it(`should be possible to directly require('@faker-js/faker/locale/${locale}')`, () => {
// eslint-disable-next-line @typescript-eslint/no-require-imports, unicorn/prefer-module
const { faker } = require(`../dist/locale/${locale}.cjs`) as {
faker: Faker;
};

expect(faker).toBeDefined();
expect(faker.string.alpha()).toBeTypeOf('string');
expect(faker.definitions.metadata.title).toBe(
allLocales[locale].metadata?.title
);
});

it(`should be possible to directly import('@faker-js/faker/locale/${locale}')`, async () => {
const { faker } = (await import(`../dist/locale/${locale}.js`)) as {
faker: Faker;
Expand Down
48 changes: 48 additions & 0 deletions test/require.spec.cts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
const { describe, expect, it, vi } = await import('vitest');
const { allLocales, SimpleFaker } = require('../dist/index.cjs');

describe('require (cjs)', () => {
describe.each(
Object.keys(
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
allLocales
)
)('locale imports', (locale) => {
it(`should be possible to directly require('@faker-js/faker/locale/${locale}')`, () => {
const { faker } = require(`../dist/locale/${locale}.cjs`);

expect(faker).toBeDefined();
expect(faker.string.alpha()).toBeTypeOf('string');
expect(faker.definitions.metadata.title).toBe(
allLocales[locale].metadata?.title
);
});
});

describe('simpleFaker', () => {
it('should not log anything on startup', () => {
const spies = Object.keys(console)
.filter(
(key) =>
// @ts-expect-error: cts cant use `as keyof typeof console`
typeof console[key] === 'function'
)
.map((methodName) =>
vi.spyOn(
console,
// @ts-expect-error: cts cant use `as keyof typeof console`
methodName
)
);

expect(require('..').simpleFaker).toBeDefined();

expect(new SimpleFaker()).toBeDefined();

for (const spy of spies) {
expect(spy).not.toHaveBeenCalled();
spy.mockRestore();
}
});
});
});
7 changes: 4 additions & 3 deletions test/simple-faker.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import { generateMersenne32Randomizer, SimpleFaker, simpleFaker } from '../src';
import { keys } from '../src/internal/keys';

describe('simpleFaker', () => {
it('should not log anything on startup', () => {
it('should not log anything on startup', async () => {
const spies: MockInstance[] = keys(console)
.filter((key) => typeof console[key] === 'function')
.map((methodName) => vi.spyOn(console, methodName));

// eslint-disable-next-line @typescript-eslint/no-require-imports, unicorn/prefer-module -- Using import() requires types being build but the CI / TS-Check runs without them.
expect(require('..').simpleFaker).toBeDefined();
// Using import() requires types being build but the CI / TS-Check runs without them.
const { simpleFaker: importedSimpleFaker } = await import('..');
expect(importedSimpleFaker).toBeDefined();

expect(new SimpleFaker()).toBeDefined();

Expand Down
2 changes: 1 addition & 1 deletion vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ console.log('VITEST_SEQUENCE_SEED', VITEST_SEQUENCE_SEED);
export default defineConfig({
test: {
setupFiles: ['test/setup.ts'],
include: ['test/**/*.spec.ts'],
include: ['test/**/*.spec.ts', 'test/**/*.spec.cts'],
exclude: ['test/integration/**/*.spec.ts'],
coverage: {
all: true,
Expand Down