Skip to content

Commit e084633

Browse files
committed
test: consolidate and expand multi-theme tests
- Consolidate duplicate tests for default color behavior - Use test.each for parameterized theme configuration tests - Add coverage for 3+ themes (light/dark/dim) - Add coverage for mixed configs (bundled strings + custom objects)
1 parent 05b6cb2 commit e084633

File tree

1 file changed

+60
-44
lines changed

1 file changed

+60
-44
lines changed

package/tests/hook.test.tsx

Lines changed: 60 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,26 @@ describe('useShikiHighlighter Hook', () => {
257257
const code = 'console.log("test");';
258258
const themes = { light: 'github-light', dark: 'github-dark' };
259259

260-
test('renders CSS variables for non-default theme', async () => {
260+
const customLightTheme = {
261+
name: 'custom-light',
262+
tokenColors: [
263+
{ scope: 'keyword', settings: { foreground: '#ff0000' } },
264+
],
265+
};
266+
const customDarkTheme = {
267+
name: 'custom-dark',
268+
tokenColors: [
269+
{ scope: 'keyword', settings: { foreground: '#00ff00' } },
270+
],
271+
};
272+
const customDimTheme = {
273+
name: 'custom-dim',
274+
tokenColors: [
275+
{ scope: 'keyword', settings: { foreground: '#888888' } },
276+
],
277+
};
278+
279+
test('renders with light as default and CSS variables for other themes', async () => {
261280
const { getByTestId } = renderComponent({
262281
code,
263282
language: 'javascript',
@@ -271,33 +290,12 @@ describe('useShikiHighlighter Hook', () => {
271290
expect(pre).toBeInTheDocument();
272291
expect(pre).toHaveClass('shiki');
273292

274-
// Find spans with CSS variables
275-
const spans = container.querySelectorAll(
276-
'span[style*="--shiki-"]'
277-
);
278-
expect(spans.length).toBeGreaterThan(0);
279-
280-
// When no defaultColor is specified, light is default, so we should have --shiki-dark
281-
const span = spans[0];
282-
const style = span?.getAttribute('style');
283-
expect(style).toContain('--shiki-dark');
284-
});
285-
});
286-
287-
test('uses light as default when no defaultColor is passed', async () => {
288-
const { getByTestId } = renderComponent({
289-
code,
290-
language: 'javascript',
291-
theme: themes,
292-
});
293-
294-
await waitFor(() => {
295-
const container = getByTestId('highlighted');
296293
const spans = container.querySelectorAll(
297294
'span[style*="--shiki-"]'
298295
);
299296
expect(spans.length).toBeGreaterThan(0);
300297

298+
// Light is default, so we should have --shiki-dark CSS variable
301299
const span = spans[0];
302300
const style = span?.getAttribute('style');
303301
expect(style).toContain('--shiki-dark');
@@ -348,38 +346,56 @@ describe('useShikiHighlighter Hook', () => {
348346
});
349347
});
350348

351-
test('multi-theme with two TextMate theme objects works', async () => {
352-
const code = 'const x = 1;';
353-
// Both values are TextMate theme objects (no strings)
354-
const lightTheme = {
355-
name: 'test-light',
356-
tokenColors: [
357-
{ scope: 'keyword', settings: { foreground: '#ff0000' } },
358-
],
359-
};
360-
const darkTheme = {
361-
name: 'test-dark',
362-
tokenColors: [
363-
{ scope: 'keyword', settings: { foreground: '#00ff00' } },
364-
],
365-
};
366-
const themes = { light: lightTheme, dark: darkTheme };
367-
349+
test.each([
350+
{
351+
name: 'two bundled string themes',
352+
theme: { light: 'github-light', dark: 'github-dark' },
353+
},
354+
{
355+
name: 'two custom TextMate objects',
356+
theme: { light: customLightTheme, dark: customDarkTheme },
357+
},
358+
{
359+
name: 'mixed: bundled string + custom object',
360+
theme: { light: 'github-light', dark: customDarkTheme },
361+
},
362+
{
363+
name: 'mixed: custom object + bundled string',
364+
theme: { light: customLightTheme, dark: 'github-dark' },
365+
},
366+
{
367+
name: 'three themes with custom dim',
368+
theme: {
369+
light: 'github-light',
370+
dark: 'github-dark',
371+
dim: customDimTheme,
372+
},
373+
},
374+
{
375+
name: 'three custom TextMate objects',
376+
theme: {
377+
light: customLightTheme,
378+
dark: customDarkTheme,
379+
dim: customDimTheme,
380+
},
381+
},
382+
])('works with $name', async ({ theme }) => {
368383
const { getByTestId } = renderComponent({
369-
code,
384+
code: 'const x = 1;',
370385
language: 'javascript',
371-
theme: themes,
386+
theme,
372387
});
373388

374389
await waitFor(() => {
375390
const container = getByTestId('highlighted');
376391
const pre = container.querySelector('pre');
377-
// Should have multi-theme CSS variables
392+
expect(pre).toBeInTheDocument();
393+
expect(pre).toHaveClass('shiki');
394+
378395
const spans = container.querySelectorAll(
379396
'span[style*="--shiki-"]'
380397
);
381398
expect(spans.length).toBeGreaterThan(0);
382-
expect(pre).toBeInTheDocument();
383399
});
384400
});
385401
});

0 commit comments

Comments
 (0)