Skip to content

Commit

Permalink
temp: Went half way through the test for the entry file
Browse files Browse the repository at this point in the history
  • Loading branch information
orangevolon committed Jan 10, 2025
1 parent 9abf2ce commit 7d6968b
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/converter/generate-test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ function generateSelectorUtils(testUtilsPath: string) {
const domFolderPath = path.join(testUtilsPath, 'dom');

Check warning on line 32 in src/converter/generate-test-utils.ts

View check run for this annotation

Codecov / codecov/patch

src/converter/generate-test-utils.ts#L27-L32

Added lines #L27 - L32 were not covered by tests
const selectorsFolderPath = path.join(testUtilsPath, 'selectors');
const conversionTargetRelativePaths = glob.sync(`**/*.{ts,tsx}`, { cwd: domFolderPath });

Check warning on line 34 in src/converter/generate-test-utils.ts

View check run for this annotation

Codecov / codecov/patch

src/converter/generate-test-utils.ts#L34

Added line #L34 was not covered by tests
console.log('bura', path.join(__dirname, domFolderPath), conversionTargetRelativePaths);

for (const fileRelativePath of conversionTargetRelativePaths) {
const domFilePath = path.join(domFolderPath, fileRelativePath);
Expand Down
43 changes: 43 additions & 0 deletions src/converter/test/generate-test-utils.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import { readFileSync } from 'fs';
import { describe, test, expect, beforeAll, beforeEach, vi } from 'vitest';
import { convertToSelectorUtil } from '../convert-to-selectors';
import { generateTestUtils } from '../generate-test-utils';
import { ComponentMetadata } from '../interfaces';

vi.mock('fs');
vi.mock('../convert-to-selectors');

const mockComponents: ComponentMetadata[] = [
{
name: 'Alert',
pluralName: 'Alerts',
testUtilsFolderName: '../test-utils',
},
{
name: 'Status',
pluralName: 'Status', // The plural name is deliberately the same as singular
testUtilsFolderName: '../test-utils',
},
];

describe(`${generateTestUtils.name}`, () => {
beforeAll(() => {
vi.mocked(readFileSync).mockReturnValue('file content');
vi.mocked(convertToSelectorUtil).mockImplementation(input => input);
});

beforeEach(() => {
vi.clearAllMocks();
});

test('generates the selector utils for the given dom utils', () => {
generateTestUtils({
components: mockComponents,
testUtilsPath: './test/mock-test-utils',
});

expect(readFileSync).toHaveBeenCalledWith('mock-test-utils/dom');
});
});

0 comments on commit 7d6968b

Please sign in to comment.