Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions src-themeable/__tests__/theming.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
const preset = {
secondary: [{ id: 'one-theme' }],
};

jest.mock('@cloudscape-design/theming-build', () => ({
buildThemedComponents: jest.fn().mockResolvedValue(undefined),
}));

jest.mock('../internal/template/internal/generated/theming/index.cjs', () => ({
preset,
}));

import { buildThemedComponents as themingCoreBuild } from '@cloudscape-design/theming-build';

import { buildThemedComponents } from '../theming';

describe('buildThemedComponents', () => {
test('passes secondary themes by default', async () => {
await buildThemedComponents({ theme: {} as any, outputDir: '/tmp/output', baseThemeId: 'visual-refresh' });

expect(themingCoreBuild).toHaveBeenCalledWith(
expect.objectContaining({
preset,
})
);
});

test('omits secondary themes when includeSecondaryThemes is false', async () => {
await buildThemedComponents({
theme: {} as any,
outputDir: '/tmp/output',
baseThemeId: 'visual-refresh',
includeSecondaryThemes: false,
});

expect(themingCoreBuild).toHaveBeenCalledWith(
expect.objectContaining({
preset: {
...preset,
secondary: [],
},
})
);
});
});
13 changes: 11 additions & 2 deletions src-themeable/theming.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,21 @@ export interface BuildThemedComponentsParams {
theme: Theme;
outputDir: string;
baseThemeId?: string;
includeSecondaryThemes?: boolean;
}

export function buildThemedComponents({ theme, outputDir, baseThemeId }: BuildThemedComponentsParams): Promise<void> {
export function buildThemedComponents({
theme,
outputDir,
baseThemeId,
includeSecondaryThemes = true,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not make public API changes like that without good justification.

}: BuildThemedComponentsParams): Promise<void> {
return themingCoreBuild({
override: theme,
preset,
preset: {
...preset,
secondary: includeSecondaryThemes ? preset.secondary : [],
},
baseThemeId,
componentsOutputDir: join(outputDir, 'components'),
designTokensOutputDir: join(outputDir, 'design-tokens'),
Expand Down
Loading