aboutsummaryrefslogtreecommitdiff
path: root/test/scripts
diff options
context:
space:
mode:
authorST-DDT <[email protected]>2023-03-07 10:09:29 +0100
committerGitHub <[email protected]>2023-03-07 09:09:29 +0000
commit9a35dc92260585683132172f10bcdec701ed661a (patch)
tree35a5711ba5a5fbc18a8f62515d1ae8b25af77023 /test/scripts
parenta4d5203511e6ea7e26bc8c75baf91ee44387cac0 (diff)
downloadfaker-9a35dc92260585683132172f10bcdec701ed661a.tar.xz
faker-9a35dc92260585683132172f10bcdec701ed661a.zip
refactor!: remove dynamic locale switching support (#1735)
Diffstat (limited to 'test/scripts')
-rw-r--r--test/scripts/apidoc/examplesAndDeprecations.spec.ts20
1 files changed, 5 insertions, 15 deletions
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<string, string> = {
- 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