From 9a35dc92260585683132172f10bcdec701ed661a Mon Sep 17 00:00:00 2001 From: ST-DDT Date: Tue, 7 Mar 2023 10:09:29 +0100 Subject: refactor!: remove dynamic locale switching support (#1735) --- test/scripts/apidoc/examplesAndDeprecations.spec.ts | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) (limited to 'test/scripts') diff --git a/test/scripts/apidoc/examplesAndDeprecations.spec.ts b/test/scripts/apidoc/examplesAndDeprecations.spec.ts index d8fc7361..5ff635b2 100644 --- a/test/scripts/apidoc/examplesAndDeprecations.spec.ts +++ b/test/scripts/apidoc/examplesAndDeprecations.spec.ts @@ -21,7 +21,6 @@ import { extractSince, extractTagContent, } from '../../../scripts/apidoc/typedoc'; -import { faker } from '../../../src'; import { loadProjectModules } from './utils'; /* @@ -30,12 +29,6 @@ import { loadProjectModules } from './utils'; * - and running these do not log anything, unless the method is deprecated */ -const locales: Record = { - GH: 'en_GH', - US: 'en_US', - DE: 'de', -}; - beforeAll(initMarkdownRenderer); describe('examples and deprecations', () => { @@ -46,7 +39,6 @@ describe('examples and deprecations', () => { .map((methodName) => vi.spyOn(console, methodName as keyof typeof console)); afterAll(() => { - faker.locale = 'en'; for (const spy of consoleSpies) { spy.mockRestore(); } @@ -54,7 +46,6 @@ describe('examples and deprecations', () => { describe.each(Object.entries(modules))('%s', (moduleName, methodsByName) => { beforeEach(() => { - faker.locale = 'en'; for (const spy of consoleSpies) { spy.mockReset(); } @@ -65,11 +56,7 @@ describe('examples and deprecations', () => { '%s', async (methodName, signature) => { // Extract examples and make them runnable - let examples = extractRawExamples(signature).join('').trim(); - examples = examples.replace( - /faker([A-Z]{2})\./g, - (_, locale: string) => `faker.locale = '${locales[locale]}';\nfaker.` - ); + const examples = extractRawExamples(signature).join('').trim(); expect( examples, @@ -80,9 +67,12 @@ describe('examples and deprecations', () => { const dir = resolve(__dirname, 'temp', moduleName); mkdirSync(dir, { recursive: true }); const path = resolve(dir, `${methodName}.ts`); + const imports = [...new Set(examples.match(/faker[^\.]*(?=\.)/g))]; writeFileSync( path, - `import { faker } from '../../../../../src';\n${examples}` + `import { ${imports.join( + ', ' + )} } from '../../../../../src';\n\n${examples}` ); // Run the examples -- cgit v1.2.3