",
"name": "methodWithMultipleSeeMarkers",
"parameters": [],
@@ -288,8 +289,8 @@ exports[`signature > analyzeSignature() > methodWithMultipleSeeMarkers 1`] = `
"test.apidoc.methodWithExample()",
"test.apidoc.methodWithDeprecated()",
],
- "since": "",
- "sourcePath": "test/scripts/apidoc/signature.example.ts#L335",
+ "since": "Missing",
+ "sourcePath": "test/scripts/apidoc/signature.example.ts#L345",
"throws": undefined,
}
`;
@@ -299,7 +300,7 @@ exports[`signature > analyzeSignature() > methodWithMultipleSeeMarkersAndBacktic
"deprecated": undefined,
"description": "
Test with multiple see markers and backticks.
tsmethodWithMultipleSeeMarkersAndBackticks(): number
+ "examples": "
tsmethodWithMultipleSeeMarkersAndBackticks(): number
",
"name": "methodWithMultipleSeeMarkersAndBackticks",
"parameters": [],
@@ -308,25 +309,43 @@ exports[`signature > analyzeSignature() > methodWithMultipleSeeMarkersAndBacktic
"test.apidoc.methodWithExample() with parameter
foo
.",
"test.apidoc.methodWithDeprecated() with parameter
bar
and
baz
.",
],
- "since": "",
- "sourcePath": "test/scripts/apidoc/signature.example.ts#L345",
+ "since": "Missing",
+ "sourcePath": "test/scripts/apidoc/signature.example.ts#L355",
"throws": undefined,
}
`;
+exports[`signature > analyzeSignature() > methodWithMultipleThrows 1`] = `
+{
+ "deprecated": undefined,
+ "description": "
Test with multiple throws.
+",
+ "examples": "
tsmethodWithMultipleThrows(): number
+
",
+ "name": "methodWithMultipleThrows",
+ "parameters": [],
+ "returns": "number",
+ "seeAlsos": [],
+ "since": "Missing",
+ "sourcePath": "test/scripts/apidoc/signature.example.ts#L306",
+ "throws": "First error case.
+Another error case.",
+}
+`;
+
exports[`signature > analyzeSignature() > methodWithSinceMarker 1`] = `
{
"deprecated": undefined,
"description": "
Test with since marker.
",
- "examples": "
tsmethodWithSinceMarker(): number
+ "examples": "
tsmethodWithSinceMarker(): number
",
"name": "methodWithSinceMarker",
"parameters": [],
"returns": "number",
"seeAlsos": [],
"since": "1.0.0",
- "sourcePath": "test/scripts/apidoc/signature.example.ts#L354",
+ "sourcePath": "test/scripts/apidoc/signature.example.ts#L364",
"throws": undefined,
}
`;
@@ -334,17 +353,17 @@ exports[`signature > analyzeSignature() > methodWithSinceMarker 1`] = `
exports[`signature > analyzeSignature() > methodWithThrows 1`] = `
{
"deprecated": undefined,
- "description": "
Test with throws
+ "description": "
Test with throws.
",
- "examples": "
tsmethodWithThrows(): number
+ "examples": "
tsmethodWithThrows(): number
",
"name": "methodWithThrows",
"parameters": [],
"returns": "number",
"seeAlsos": [],
- "since": "",
+ "since": "Missing",
"sourcePath": "test/scripts/apidoc/signature.example.ts#L296",
- "throws": "a Faker error",
+ "throws": "Everytime.",
}
`;
@@ -353,7 +372,7 @@ exports[`signature > analyzeSignature() > multiParamMethod 1`] = `
"deprecated": undefined,
"description": "
Test with multiple parameters.
",
- "examples": "
tsmultiParamMethod(a: number, b?: string, c: boolean = true): number
+ "examples": "
tsmultiParamMethod(a: number, b?: string, c: boolean = true): number
",
"name": "multiParamMethod",
"parameters": [
@@ -381,7 +400,7 @@ exports[`signature > analyzeSignature() > multiParamMethod 1`] = `
],
"returns": "number",
"seeAlsos": [],
- "since": "",
+ "since": "Missing",
"sourcePath": "test/scripts/apidoc/signature.example.ts#L116",
"throws": undefined,
}
@@ -392,13 +411,13 @@ exports[`signature > analyzeSignature() > noParamMethod 1`] = `
"deprecated": undefined,
"description": "
Test with no parameters.
",
- "examples": "
tsnoParamMethod(): number
+ "examples": "
tsnoParamMethod(): number
",
"name": "noParamMethod",
"parameters": [],
"returns": "number",
"seeAlsos": [],
- "since": "",
+ "since": "Missing",
"sourcePath": "test/scripts/apidoc/signature.example.ts#L78",
"throws": undefined,
}
@@ -409,7 +428,7 @@ exports[`signature > analyzeSignature() > optionalStringParamMethod 1`] = `
"deprecated": undefined,
"description": "
Test with an optional parameter.
",
- "examples": "
tsoptionalStringParamMethod(b?: string): number
+ "examples": "
tsoptionalStringParamMethod(b?: string): number
",
"name": "optionalStringParamMethod",
"parameters": [
@@ -423,7 +442,7 @@ exports[`signature > analyzeSignature() > optionalStringParamMethod 1`] = `
],
"returns": "number",
"seeAlsos": [],
- "since": "",
+ "since": "Missing",
"sourcePath": "test/scripts/apidoc/signature.example.ts#L96",
"throws": undefined,
}
@@ -434,13 +453,13 @@ exports[`signature > analyzeSignature() > optionsInlineParamMethodWithDefaults 1
"deprecated": undefined,
"description": "
Test with a function parameters (inline types) with defaults.
",
- "examples": "
tsoptionsInlineParamMethodWithDefaults(a: {
- value: number
-} = { value: 1 }, b: {
- value: number
-} = { value: 1 }, c: {
- value: number
-}): number
+ "examples": "
tsoptionsInlineParamMethodWithDefaults(a: {
+ value: number
+} = { value: 1 }, b: {
+ value: number
+} = { value: 1 }, c: {
+ value: number
+}): number
",
"name": "optionsInlineParamMethodWithDefaults",
"parameters": [
@@ -491,7 +510,7 @@ It also has a more complex description.
],
"returns": "number",
"seeAlsos": [],
- "since": "",
+ "since": "Missing",
"sourcePath": "test/scripts/apidoc/signature.example.ts#L226",
"throws": undefined,
}
@@ -502,7 +521,7 @@ exports[`signature > analyzeSignature() > optionsInterfaceParamMethodWithDefault
"deprecated": undefined,
"description": "
Test with a function parameters with defaults.
",
- "examples": "
tsoptionsInterfaceParamMethodWithDefaults(a: ParameterOptionsInterfaceA = { value: 1 }, b: ParameterOptionsInterfaceB = { value: 1 }, c: ParameterOptionsInterfaceC): number
+ "examples": "
tsoptionsInterfaceParamMethodWithDefaults(a: ParameterOptionsInterfaceA = { value: 1 }, b: ParameterOptionsInterfaceB = { value: 1 }, c: ParameterOptionsInterfaceC): number
",
"name": "optionsInterfaceParamMethodWithDefaults",
"parameters": [
@@ -530,7 +549,7 @@ exports[`signature > analyzeSignature() > optionsInterfaceParamMethodWithDefault
],
"returns": "number",
"seeAlsos": [],
- "since": "",
+ "since": "Missing",
"sourcePath": "test/scripts/apidoc/signature.example.ts#L262",
"throws": undefined,
}
@@ -541,13 +560,13 @@ exports[`signature > analyzeSignature() > optionsParamMethod 1`] = `
"deprecated": undefined,
"description": "
Test with an options parameter.
",
- "examples": "
tsoptionsParamMethod(options: {
- a: number,
- b: string,
- c: boolean,
- d: () => string,
- e: 'a' | 'b' | string
-}): number
+ "examples": "
tsoptionsParamMethod(options: {
+ a: number,
+ b: string,
+ c: boolean,
+ d: () => string,
+ e: 'a' | 'b' | string
+}): number
",
"name": "optionsParamMethod",
"parameters": [
@@ -596,7 +615,7 @@ exports[`signature > analyzeSignature() > optionsParamMethod 1`] = `
],
"returns": "number",
"seeAlsos": [],
- "since": "",
+ "since": "Missing",
"sourcePath": "test/scripts/apidoc/signature.example.ts#L196",
"throws": undefined,
}
@@ -607,7 +626,7 @@ exports[`signature > analyzeSignature() > optionsTypeParamMethodWithDefaults 1`]
"deprecated": undefined,
"description": "
Test with a function parameters with defaults.
",
- "examples": "
tsoptionsTypeParamMethodWithDefaults(a: ParameterOptionsTypeA = { value: 1 }, b: ParameterOptionsTypeB = { value: 1 }, c: ParameterOptionsTypeC): number
+ "examples": "
tsoptionsTypeParamMethodWithDefaults(a: ParameterOptionsTypeA = { value: 1 }, b: ParameterOptionsTypeB = { value: 1 }, c: ParameterOptionsTypeC): number
",
"name": "optionsTypeParamMethodWithDefaults",
"parameters": [
@@ -635,7 +654,7 @@ exports[`signature > analyzeSignature() > optionsTypeParamMethodWithDefaults 1`]
],
"returns": "number",
"seeAlsos": [],
- "since": "",
+ "since": "Missing",
"sourcePath": "test/scripts/apidoc/signature.example.ts#L244",
"throws": undefined,
}
@@ -646,7 +665,7 @@ exports[`signature > analyzeSignature() > recordParamMethod 1`] = `
"deprecated": undefined,
"description": "
Test with a Record parameter.
",
- "examples": "
tsrecordParamMethod(object: Record<string, number>): number
+ "examples": "
tsrecordParamMethod(object: Record<string, number>): number
",
"name": "recordParamMethod",
"parameters": [
@@ -660,7 +679,7 @@ exports[`signature > analyzeSignature() > recordParamMethod 1`] = `
],
"returns": "number",
"seeAlsos": [],
- "since": "",
+ "since": "Missing",
"sourcePath": "test/scripts/apidoc/signature.example.ts#L182",
"throws": undefined,
}
@@ -671,7 +690,7 @@ exports[`signature > analyzeSignature() > requiredNumberParamMethod 1`] = `
"deprecated": undefined,
"description": "
Test with a required parameter.
",
- "examples": "
tsrequiredNumberParamMethod(a: number): number
+ "examples": "
tsrequiredNumberParamMethod(a: number): number
",
"name": "requiredNumberParamMethod",
"parameters": [
@@ -685,7 +704,7 @@ exports[`signature > analyzeSignature() > requiredNumberParamMethod 1`] = `
],
"returns": "number",
"seeAlsos": [],
- "since": "",
+ "since": "Missing",
"sourcePath": "test/scripts/apidoc/signature.example.ts#L87",
"throws": undefined,
}
@@ -696,11 +715,11 @@ exports[`signature > analyzeSignature() > stringUnionParamMethod 1`] = `
"deprecated": undefined,
"description": "
Test with string union.
",
- "examples": "
tsstringUnionParamMethod(value: 'a' | 'b', options?: {
- casing: 'lower' | 'mixed' | 'upper',
- excludes: readonly AlphaNumericChar[],
- format: 'binary' | 'css' | 'decimal' | 'hex'
-}): string
+ "examples": "
tsstringUnionParamMethod(value: 'a' | 'b', options?: {
+ casing: 'lower' | 'mixed' | 'upper',
+ excludes: readonly AlphaNumericChar[],
+ format: 'binary' | 'css' | 'decimal' | 'hex'
+}): string
",
"name": "stringUnionParamMethod",
"parameters": [
@@ -742,7 +761,7 @@ exports[`signature > analyzeSignature() > stringUnionParamMethod 1`] = `
],
"returns": "string",
"seeAlsos": [],
- "since": "",
+ "since": "Missing",
"sourcePath": "test/scripts/apidoc/signature.example.ts#L138",
"throws": undefined,
}
diff --git a/test/scripts/apidoc/module.example.ts b/test/scripts/apidoc/module.example.ts
index b3f43a8602b..0e5d9d89613 100644
--- a/test/scripts/apidoc/module.example.ts
+++ b/test/scripts/apidoc/module.example.ts
@@ -1,3 +1,5 @@
+/* eslint-disable @typescript-eslint/no-extraneous-class -- required for tests */
+
/**
* A simple module without anything special.
*/
diff --git a/test/scripts/apidoc/module.spec.ts b/test/scripts/apidoc/module.spec.ts
index 508c9de36af..5e55afea850 100644
--- a/test/scripts/apidoc/module.spec.ts
+++ b/test/scripts/apidoc/module.spec.ts
@@ -4,12 +4,11 @@ import { analyzeModule } from '../../../scripts/apidoc/module-methods';
import * as ModuleTests from './module.example';
import { loadExampleModules } from './utils';
+beforeAll(initMarkdownRenderer);
+const modules = await loadExampleModules();
+
describe('module', () => {
describe('analyzeModule()', () => {
- const modules = loadExampleModules();
-
- beforeAll(initMarkdownRenderer);
-
it('dummy dependency to rerun the test if the example changes', () => {
expect(Object.keys(ModuleTests)).not.toEqual([]);
});
diff --git a/test/scripts/apidoc/signature.debug.ts b/test/scripts/apidoc/signature.debug.ts
index d72709b0754..9e99e8c6f93 100644
--- a/test/scripts/apidoc/signature.debug.ts
+++ b/test/scripts/apidoc/signature.debug.ts
@@ -8,10 +8,9 @@ import { loadExampleMethods } from './utils';
/* Run with `pnpm tsx test/scripts/apidoc/signature.debug.ts` */
-const methods = loadExampleMethods();
-
initMarkdownRenderer()
.then(async () => {
+ const methods = await loadExampleMethods();
for (const [name, method] of Object.entries(methods)) {
console.log('Analyzing:', name);
const result = await analyzeSignature(method, '', method.name);
diff --git a/test/scripts/apidoc/signature.example.ts b/test/scripts/apidoc/signature.example.ts
index 724f687d3a6..2f62057bc01 100644
--- a/test/scripts/apidoc/signature.example.ts
+++ b/test/scripts/apidoc/signature.example.ts
@@ -289,14 +289,24 @@ export class SignatureTest {
}
/**
- * Test with throws
+ * Test with throws.
*
- * @throws a Faker error
+ * @throws Everytime.
*/
methodWithThrows(): number {
throw new FakerError('Test error');
}
+ /**
+ * Test with multiple throws.
+ *
+ * @throws First error case.
+ * @throws Another error case.
+ */
+ methodWithMultipleThrows(): number {
+ throw new FakerError('Another test error');
+ }
+
/**
* Test with deprecated option.
*
diff --git a/test/scripts/apidoc/signature.spec.ts b/test/scripts/apidoc/signature.spec.ts
index 75abf23bd9a..51935fcf44b 100644
--- a/test/scripts/apidoc/signature.spec.ts
+++ b/test/scripts/apidoc/signature.spec.ts
@@ -4,12 +4,11 @@ import { analyzeSignature } from '../../../scripts/apidoc/signature';
import { SignatureTest } from './signature.example';
import { loadExampleMethods } from './utils';
+beforeAll(initMarkdownRenderer);
+const methods = await loadExampleMethods();
+
describe('signature', () => {
describe('analyzeSignature()', () => {
- const methods = loadExampleMethods();
-
- beforeAll(initMarkdownRenderer);
-
it('dummy dependency to rerun the test if the example changes', () => {
expect(new SignatureTest()).toBeTruthy();
});
diff --git a/test/scripts/apidoc/utils.ts b/test/scripts/apidoc/utils.ts
index ade31120ad8..2752f25b648 100644
--- a/test/scripts/apidoc/utils.ts
+++ b/test/scripts/apidoc/utils.ts
@@ -16,14 +16,13 @@ import { mapByName } from '../../../scripts/apidoc/utils';
* @param options The TypeDoc options.
* @param includeTestModules Whether to include the test modules.
*/
-export function loadProjectModules(
+export async function loadProjectModules(
options?: Partial
,
includeTestModules = false
-): Record<
- string,
- [DeclarationReflection, Record]
+): Promise<
+ Record]>
> {
- const [, project] = loadProject(options);
+ const [, project] = await loadProject(options);
const modules = selectApiModules(project, includeTestModules);
@@ -33,20 +32,25 @@ export function loadProjectModules(
/**
* Loads the example methods using TypeDoc.
*/
-export function loadExampleMethods(): Record {
- return loadProjectModules(
+export async function loadExampleMethods(): Promise<
+ Record
+> {
+ const modules = await loadProjectModules(
{
entryPoints: ['test/scripts/apidoc/signature.example.ts'],
},
true
- )['SignatureTest'][1];
+ );
+ return modules['SignatureTest'][1];
}
/**
* Loads the example modules using TypeDoc.
*/
-export function loadExampleModules(): Record {
- const modules = loadProjectModules(
+export async function loadExampleModules(): Promise<
+ Record
+> {
+ const modules = await loadProjectModules(
{
entryPoints: ['test/scripts/apidoc/module.example.ts'],
},
diff --git a/test/scripts/apidoc/verify-jsdoc-tags.spec.ts b/test/scripts/apidoc/verify-jsdoc-tags.spec.ts
index 64cbcdb4ee5..b14523e1653 100644
--- a/test/scripts/apidoc/verify-jsdoc-tags.spec.ts
+++ b/test/scripts/apidoc/verify-jsdoc-tags.spec.ts
@@ -1,5 +1,7 @@
import { existsSync, mkdirSync, rmSync, writeFileSync } from 'node:fs';
-import { resolve } from 'node:path';
+import { dirname, resolve } from 'node:path';
+import { fileURLToPath } from 'node:url';
+import type { ReflectionType, SomeType } from 'typedoc';
import validator from 'validator';
import { afterAll, beforeAll, describe, expect, it, vi } from 'vitest';
import { initMarkdownRenderer } from '../../../scripts/apidoc/markdown';
@@ -9,8 +11,10 @@ import {
extractDescription,
extractJoinedRawExamples,
extractModuleFieldName,
+ extractRawDefault,
extractSeeAlsos,
extractSince,
+ extractSummaryDefault,
extractTagContent,
MISSING_DESCRIPTION,
} from '../../../scripts/apidoc/typedoc';
@@ -22,7 +26,7 @@ import { loadProjectModules } from './utils';
beforeAll(initMarkdownRenderer);
-const tempDir = resolve(__dirname, 'temp');
+const tempDir = resolve(dirname(fileURLToPath(import.meta.url)), 'temp');
afterAll(() => {
// Remove temp folder
@@ -31,68 +35,111 @@ afterAll(() => {
}
});
-describe('verify JSDoc tags', () => {
- const modules = loadProjectModules();
+const modules = await loadProjectModules();
- function resolveDirToModule(moduleName: string): string {
- return resolve(tempDir, moduleName);
- }
+function resolveDirToModule(moduleName: string): string {
+ return resolve(tempDir, moduleName);
+}
+
+function resolvePathToMethodFile(
+ moduleName: string,
+ methodName: string
+): string {
+ const dir = resolveDirToModule(moduleName);
+ return resolve(dir, `${methodName}.ts`);
+}
+
+const allowedReferences = new Set(
+ Object.values(modules).flatMap(([module, methods]) => {
+ const moduleFieldName = extractModuleFieldName(module);
+ return Object.keys(methods).map(
+ (methodName) => `faker.${moduleFieldName}.${methodName}`
+ );
+ })
+);
+const allowedLinks = new Set(
+ Object.values(modules).flatMap(([module, methods]) => {
+ const moduleFieldName = extractModuleFieldName(module);
+ return [
+ `/api/${moduleFieldName}.html`,
+ ...Object.keys(methods).map(
+ (methodName) =>
+ `/api/${moduleFieldName}.html#${methodName.toLowerCase()}`
+ ),
+ ];
+ })
+);
+
+function assertDescription(description: string, isHtml: boolean): void {
+ const linkRegexp = isHtml ? /(href)="([^"]+)"/g : /\[([^\]]+)\]\(([^)]+)\)/g;
+ const links = [...description.matchAll(linkRegexp)].map((m) => m[2]);
+
+ for (const link of links) {
+ if (!isHtml) {
+ expect(link).toMatch(/^https?:\/\//);
+ expect(link).toSatisfy(validator.isURL);
+ }
- function resolvePathToMethodFile(
- moduleName: string,
- methodName: string
- ): string {
- const dir = resolveDirToModule(moduleName);
- return resolve(dir, `${methodName}.ts`);
+ if (isHtml ? link.startsWith('/api/') : link.includes('fakerjs.dev/api/')) {
+ expect(allowedLinks, `${link} to point to a valid target`).toContain(
+ link.replace(/.*fakerjs.dev\//, '/')
+ );
+ }
}
+}
- const allowedReferences = new Set(
- Object.values(modules).reduce((acc, [module, methods]) => {
- const moduleFieldName = extractModuleFieldName(module);
- return [
- ...acc,
- ...Object.keys(methods).map(
- (methodName) => `faker.${moduleFieldName}.${methodName}`
- ),
- ];
- }, [] as string[])
- );
- const allowedLinks = new Set(
- Object.values(modules).reduce((acc, [module, methods]) => {
- const moduleFieldName = extractModuleFieldName(module);
- return [
- ...acc,
- `/api/${moduleFieldName}.html`,
- ...Object.keys(methods).map(
- (methodName) =>
- `/api/${moduleFieldName}.html#${methodName.toLowerCase()}`
- ),
- ];
- }, [] as string[])
- );
+// keep in sync with analyzeParameterOptions
+function assertNestedParameterDefault(
+ name: string,
+ parameterType?: SomeType
+): void {
+ if (!parameterType) {
+ return;
+ }
- function assertDescription(description: string, isHtml: boolean): void {
- const linkRegexp = isHtml
- ? /(href)="([^"]+)"/g
- : /\[([^\]]+)\]\(([^)]+)\)/g;
- const links = [...description.matchAll(linkRegexp)].map((m) => m[2]);
+ switch (parameterType.type) {
+ case 'array':
+ return assertNestedParameterDefault(
+ `${name}[]`,
+ parameterType.elementType
+ );
- for (const link of links) {
- if (!isHtml) {
- expect(link).toMatch(/^https?:\/\//);
- expect(link).toSatisfy(validator.isURL);
+ case 'union':
+ for (const type of parameterType.types) {
+ assertNestedParameterDefault(name, type);
}
- if (
- isHtml ? link.startsWith('/api/') : link.includes('fakerjs.dev/api/')
- ) {
- expect(allowedLinks, `${link} to point to a valid target`).toContain(
- link.replace(/.*fakerjs.dev\//, '/')
- );
+ return;
+
+ case 'reflection': {
+ for (const property of parameterType.declaration.children ?? []) {
+ const reflection = property.comment
+ ? property
+ : (property.type as ReflectionType)?.declaration?.signatures?.[0];
+ const comment = reflection?.comment;
+ const tagDefault = extractRawDefault({ comment }) || undefined;
+ const summaryDefault = extractSummaryDefault(comment, false);
+
+ if (summaryDefault) {
+ expect(
+ tagDefault,
+ `Expect jsdoc summary default and @default for ${name}.${property.name} to be the same`
+ ).toBe(summaryDefault);
+ }
}
+
+ return;
}
+
+ case 'typeOperator':
+ return assertNestedParameterDefault(name, parameterType.target);
+
+ default:
+ return;
}
+}
+describe('verify JSDoc tags', () => {
describe.each(Object.entries(modules))(
'%s',
(moduleName, [module, methodsByName]) => {
@@ -110,7 +157,7 @@ describe('verify JSDoc tags', () => {
// Write temp files to disk
// Extract examples and make them runnable
- const examples = extractJoinedRawExamples(signature);
+ const examples = extractJoinedRawExamples(signature) ?? '';
// Save examples to a file to run them later in the specific tests
const dir = resolveDirToModule(moduleName);
@@ -176,6 +223,31 @@ describe('verify JSDoc tags', () => {
});
it('verify @param tags', async () => {
+ // This must run before analyzeSignature
+ for (const param of signature.parameters ?? []) {
+ const type = param.type;
+ const paramDefault = param.defaultValue;
+ const commentDefault = extractSummaryDefault(
+ param.comment,
+ false
+ );
+ if (paramDefault) {
+ if (
+ /^{.*}$/.test(paramDefault) ||
+ paramDefault.includes('\n')
+ ) {
+ expect(commentDefault).toBeUndefined();
+ } else {
+ expect(
+ commentDefault,
+ `Expect '${param.name}'s js implementation default to be the same as the jsdoc summary default.`
+ ).toBe(paramDefault);
+ }
+ }
+
+ assertNestedParameterDefault(param.name, type);
+ }
+
for (const param of (
await analyzeSignature(signature, '', methodName)
).parameters) {
@@ -201,6 +273,24 @@ describe('verify JSDoc tags', () => {
expect(link, 'Expect method reference to contain ()').toContain(
')'
);
+ expect(
+ link,
+ "Expect method reference to have a ': ' after the parenthesis"
+ ).toContain('): ');
+ expect(
+ link,
+ 'Expect method reference to have a description starting with a capital letter'
+ ).toMatch(/\): [A-Z]/);
+ expect(
+ link,
+ 'Expect method reference to start with a standard description phrase'
+ ).toMatch(
+ /\): (?:For generating |For more information about |For using |For the replacement method)/
+ );
+ expect(
+ link,
+ 'Expect method reference to have a description ending with a dot'
+ ).toMatch(/\.$/);
expect(allowedReferences).toContain(link.replace(/\(.*/, ''));
}
}
@@ -209,6 +299,7 @@ describe('verify JSDoc tags', () => {
it('verify @since tag', () => {
const since = extractSince(signature);
expect(since, '@since to be present').toBeTruthy();
+ expect(since).not.toBe(MISSING_DESCRIPTION);
expect(since, '@since to be a valid semver').toSatisfy(
validator.isSemVer
);
diff --git a/test/simple-faker.spec.ts b/test/simple-faker.spec.ts
index c416f4fed4c..ec1247cf474 100644
--- a/test/simple-faker.spec.ts
+++ b/test/simple-faker.spec.ts
@@ -1,16 +1,15 @@
import type { SpyInstance } from 'vitest';
import { describe, expect, it, vi } from 'vitest';
import { SimpleFaker, simpleFaker } from '../src';
+import { keys } from '../src/internal/keys';
describe('simpleFaker', () => {
it('should not log anything on startup', () => {
- const spies: SpyInstance[] = Object.keys(console)
+ const spies: SpyInstance[] = keys(console)
.filter((key) => typeof console[key] === 'function')
- .map((methodName) =>
- vi.spyOn(console, methodName as keyof typeof console)
- );
+ .map((methodName) => vi.spyOn(console, methodName));
- // eslint-disable-next-line @typescript-eslint/no-var-requires
+ // eslint-disable-next-line @typescript-eslint/no-var-requires, unicorn/prefer-module -- Using import() requires types being build but the CI / TS-Check runs without them.
require('..').simpleFaker;
new SimpleFaker();
diff --git a/test/support/seeded-runs.ts b/test/support/seeded-runs.ts
index 4b014cb6d03..e95a522f9f3 100644
--- a/test/support/seeded-runs.ts
+++ b/test/support/seeded-runs.ts
@@ -11,8 +11,8 @@ type FakerModule = {
[Key in keyof Faker]: Faker[Key] extends Callable | string | number | number[]
? never
: Key extends 'definitions' | 'locales'
- ? never
- : Key;
+ ? never
+ : Key;
}[keyof Faker];
/**
diff --git a/test/vitest-extensions.ts b/test/vitest-extensions.ts
index e23b9c09c81..0a441d87425 100644
--- a/test/vitest-extensions.ts
+++ b/test/vitest-extensions.ts
@@ -2,7 +2,7 @@ import { expect } from 'vitest';
expect.extend({
toContainDuplicates(received: T[]) {
- const { isNot } = this;
+ const { isNot = false } = this;
const uniques = new Set(received);
const duplications = received.filter((entry) => !uniques.delete(entry));
diff --git a/tsconfig.build.json b/tsconfig.build.json
index aa1bfb29830..ce2dcfba1a7 100644
--- a/tsconfig.build.json
+++ b/tsconfig.build.json
@@ -8,7 +8,6 @@
"outDir": "dist/types",
// This negates what is set in the extended tsconfig.json
- "noImplicitAny": true,
"skipLibCheck": false,
"allowSyntheticDefaultImports": false,
"resolveJsonModule": false
diff --git a/tsconfig.json b/tsconfig.json
index cda27929e8f..a290fc07b56 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -8,10 +8,6 @@
"declaration": true,
"stripInternal": true,
- // We need to disable these for now, and need to tackle them in another PR
- "strictNullChecks": false,
- "noImplicitAny": false,
-
// These are configs specifically for !build and have to be reverted in the tsconfig.build.json
"skipLibCheck": true,
"allowSyntheticDefaultImports": true,
diff --git a/vite.config.ts b/vite.config.ts
index 4cbe0c4fcc5..ca3339f2c7e 100644
--- a/vite.config.ts
+++ b/vite.config.ts
@@ -5,6 +5,17 @@ const VITEST_SEQUENCE_SEED = Date.now();
console.log('VITEST_SEQUENCE_SEED', VITEST_SEQUENCE_SEED);
+// TODO @Shinigami92 2023-12-28: remove when we drop support for Node 14
+const [nodeVersionMajor] = process.versions.node.split('.').map(Number);
+const excludedTests: string[] = [];
+if (nodeVersionMajor < 16) {
+ excludedTests.push(
+ 'test/scripts/apidoc/module.spec.ts',
+ 'test/scripts/apidoc/signature.spec.ts',
+ 'test/scripts/apidoc/verify-jsdoc-tags.spec.ts'
+ );
+}
+
// https://vitejs.dev/config/
export default defineConfig({
test: {
@@ -20,6 +31,16 @@ export default defineConfig({
seed: VITEST_SEQUENCE_SEED,
shuffle: true,
},
+ // TODO @Shinigami92 2023-12-28: remove the whole `exclude` when we drop support for Node 14
+ exclude: [
+ // should be originally `...configDefaults.exclude` from `'vitest/config'`, but esm...
+ 'node_modules',
+ 'dist',
+ '.idea',
+ '.git',
+ '.cache',
+ ...excludedTests,
+ ],
onConsoleLog(log, type) {
if (
type === 'stderr' &&