From f99a944265422a6051d43983e1e9123c2b9cd0ee Mon Sep 17 00:00:00 2001 From: Amir Alami Date: Wed, 15 Jan 2025 11:47:23 +0100 Subject: [PATCH] chore: Removes the getComponentsMetadata public API --- src/converter/generate-component-finders.ts | 12 ----- src/converter/interfaces.ts | 14 ------ ...test-utils-generator-snapshot.test.ts.snap | 22 --------- .../test/generate-component-finders.test.tsx | 4 -- src/converter/test/utils.test.ts | 46 ------------------- src/converter/utils.ts | 14 ------ 6 files changed, 112 deletions(-) delete mode 100644 src/converter/test/utils.test.ts diff --git a/src/converter/generate-component-finders.ts b/src/converter/generate-component-finders.ts index 691ed35..648d39d 100644 --- a/src/converter/generate-component-finders.ts +++ b/src/converter/generate-component-finders.ts @@ -1,7 +1,6 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 import { ComponentWrapperMetadata, TestUtilType } from './interfaces'; -import { buildComponentsMetadataMap } from './utils'; const componentWrapperImport = ({ wrapperName, wrapperImportPath }: ComponentWrapperMetadata) => ` import ${wrapperName} from '${wrapperImportPath}';`; @@ -102,16 +101,5 @@ declare module '@cloudscape-design/test-utils-core/dist/${testUtilType}' { ${components.map(componentFinders).join('')} - -/** - * Returns the component metadata including its plural and wrapper name. - * - * @param {string} componentName Component name in pascal case. - * @returns {ComponentMetadata} - */ -export function getComponentMetadata(componentName: string) { - return ${buildComponentsMetadataMap(components)}[componentName]; -} - ${defaultExport[testUtilType]} `; diff --git a/src/converter/interfaces.ts b/src/converter/interfaces.ts index 6e1ce8f..fc34c90 100644 --- a/src/converter/interfaces.ts +++ b/src/converter/interfaces.ts @@ -53,17 +53,3 @@ export interface ComponentWrapperMetadata extends ComponentMetadata { */ wrapperImportPath: string; } - -export interface ComponentPublicMetadata { - /** - * Plural name of the component in pascal case. - * Examples: Buttons, Alerts, ButtonDropdowns - */ - pluralName: string; - - /* - * Name of the component wrapper in pascal case - * Examples: ButtonWrapper, AlertWrapper, ButtonDropdownWrapper - */ - wrapperName: string; -} diff --git a/src/converter/test/__snapshots__/test-utils-generator-snapshot.test.ts.snap b/src/converter/test/__snapshots__/test-utils-generator-snapshot.test.ts.snap index 56fd473..610608c 100644 --- a/src/converter/test/__snapshots__/test-utils-generator-snapshot.test.ts.snap +++ b/src/converter/test/__snapshots__/test-utils-generator-snapshot.test.ts.snap @@ -83,17 +83,6 @@ ElementWrapper.prototype.findAllTestComponentBs = function(selector) { }; -/** - * Returns the component metadata including its plural and wrapper name. - * - * @param {string} componentName Component name in pascal case. - * @returns {ComponentMetadata} - */ -export function getComponentMetadata(componentName: string) { - return {"TestComponentA":{"pluralName":"TestComponentAs","wrapperName":"TestComponentAWrapper"},"TestComponentB":{"pluralName":"TestComponentBs","wrapperName":"TestComponentBWrapper"}}[componentName]; -} - - export default function wrapper(root: Element = document.body) { if (document && document.body && !document.body.contains(root)) { console.warn('[AwsUi] [test-utils] provided element is not part of the document body, interactions may work incorrectly') @@ -182,17 +171,6 @@ ElementWrapper.prototype.findAllTestComponentBs = function(selector) { }; -/** - * Returns the component metadata including its plural and wrapper name. - * - * @param {string} componentName Component name in pascal case. - * @returns {ComponentMetadata} - */ -export function getComponentMetadata(componentName: string) { - return {"TestComponentA":{"pluralName":"TestComponentAs","wrapperName":"TestComponentAWrapper"},"TestComponentB":{"pluralName":"TestComponentBs","wrapperName":"TestComponentBWrapper"}}[componentName]; -} - - export default function wrapper(root: string = 'body') { return new ElementWrapper(root); } diff --git a/src/converter/test/generate-component-finders.test.tsx b/src/converter/test/generate-component-finders.test.tsx index 3471fd5..0fe2f14 100644 --- a/src/converter/test/generate-component-finders.test.tsx +++ b/src/converter/test/generate-component-finders.test.tsx @@ -59,10 +59,6 @@ describe(`${generateComponentFinders.name}`, () => { expect(sourceFileContent).toMatch('ElementWrapper.prototype.findAllStatus = function(selector)'); }); - test('it exports the component metadata helper', () => { - expect(sourceFileContent).toMatch(`export function getComponentMetadata(componentName: string)`); - }); - test('it exports the wrapper creator', () => { if (testUtilType === 'dom') { expect(sourceFileContent).toMatch('export default function wrapper(root: Element = document.body)'); diff --git a/src/converter/test/utils.test.ts b/src/converter/test/utils.test.ts deleted file mode 100644 index 9c33d38..0000000 --- a/src/converter/test/utils.test.ts +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. -// SPDX-License-Identifier: Apache-2.0 -import { describe, test, expect } from 'vitest'; -import { ComponentWrapperMetadata } from '../interfaces'; -import { buildComponentsMetadataMap } from '../utils'; - -const testComponents: ComponentWrapperMetadata[] = [ - { - name: 'ComponentA', - pluralName: 'ComponentAs', - wrapperImportPath: 'relative/path/to/component/a/wrapper', - wrapperName: 'ComponentAWrapper', - }, - { - name: 'ComponentB', - pluralName: 'ComponentBs', - wrapperImportPath: 'relative/path/to/component/b/wrapper', - wrapperName: 'ComponentBWrapper', - }, -]; - -describe(`${buildComponentsMetadataMap.name}`, () => { - test('builds a map with component name as key', () => { - const metadataMap = buildComponentsMetadataMap(testComponents); - - expect(metadataMap).toEqual( - JSON.stringify({ - ComponentA: { - pluralName: 'ComponentAs', - wrapperName: 'ComponentAWrapper', - }, - ComponentB: { - pluralName: 'ComponentBs', - wrapperName: 'ComponentBWrapper', - }, - }) - ); - }); - - test('does not pass the non-public data', () => { - const metadataMapString = buildComponentsMetadataMap(testComponents); - const metadataMap = JSON.parse(metadataMapString); - - expect(metadataMap.ComponentA).not.toHaveProperty('wrapperImportPath'); - }); -}); diff --git a/src/converter/utils.ts b/src/converter/utils.ts index 2e6880c..deea3b6 100644 --- a/src/converter/utils.ts +++ b/src/converter/utils.ts @@ -2,20 +2,6 @@ // SPDX-License-Identifier: Apache-2.0 import fs from 'fs'; import path from 'path'; -import { ComponentPublicMetadata, ComponentWrapperMetadata } from './interfaces'; - -export function buildComponentsMetadataMap(components: ComponentWrapperMetadata[]): string { - const componentPublicMetadata: Record = {}; - - for (const { name, pluralName, wrapperName } of components) { - componentPublicMetadata[name] = { - pluralName, - wrapperName, - }; - } - - return JSON.stringify(componentPublicMetadata); -} export function writeSourceFile(filepath: string, content: string) { fs.mkdirSync(path.dirname(filepath), { recursive: true });