Skip to content
Merged
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
36 changes: 36 additions & 0 deletions packages/superdoc/src/assets/styles/helpers/compat.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { fileURLToPath } from 'node:url';
const __dirname = dirname(fileURLToPath(import.meta.url));
const variablesCss = readFileSync(resolve(__dirname, 'variables.css'), 'utf-8');
const compatCss = readFileSync(resolve(__dirname, 'compat.css'), 'utf-8');
const themesCss = readFileSync(resolve(__dirname, 'themes.css'), 'utf-8');

/** Extract all --sd-* variable declarations from a CSS string. */
const extractDeclaredVars = (css: string): Set<string> => {
Expand Down Expand Up @@ -130,4 +131,39 @@ describe('backward compatibility', () => {
}
});
});

describe('preset themes', () => {
/** Extract variables declared inside each .sd-theme-* block. */
const extractThemeBlocks = (css: string): Map<string, Set<string>> => {
const themes = new Map<string, Set<string>>();
const blockRegex = /\.(sd-theme-[\w-]+)\s*\{([^}]+)\}/g;
for (const match of css.matchAll(blockRegex)) {
const vars = new Set<string>();
for (const decl of match[2].matchAll(/(--sd-[\w-]+)\s*:/g)) {
vars.add(decl[1]);
}
themes.set(match[1], vars);
}
return themes;
};

const themeBlocks = extractThemeBlocks(themesCss);

it('contains all expected preset themes', () => {
expect([...themeBlocks.keys()].sort()).toEqual(['sd-theme-blueprint', 'sd-theme-docs', 'sd-theme-word']);
});

it('every theme variable is declared in variables.css', () => {
const declaredInVariables = extractDeclaredVars(variablesCss);
const broken: string[] = [];
for (const [theme, vars] of themeBlocks) {
for (const v of vars) {
if (!declaredInVariables.has(v)) {
broken.push(`${theme}: ${v}`);
}
}
}
expect(broken, `Theme variables not in variables.css: ${broken.join(', ')}`).toEqual([]);
});
});
});
15 changes: 11 additions & 4 deletions packages/superdoc/tests/consumer-types/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,21 @@

// Main entry point
import type { SuperDoc } from 'superdoc';
import { createTheme, buildTheme } from 'superdoc';

// Super-editor entry point
import type { EditorView, EditorState, Transaction, Schema } from 'superdoc/super-editor';

// Types entry point
import type { ProseMirrorJSON, NodeConfig, MarkConfig } from 'superdoc/types';

// Verify the types are usable (not just importable)
type _AssertSuperDoc = SuperDoc extends object ? true : never;
type _AssertEditorView = EditorView extends object ? true : never;
type _AssertJSON = ProseMirrorJSON extends object ? true : never;
// Verify the types are usable (not just importable).
// AssertExtends<false> is a compile error, so signature mismatches fail the build.
type AssertExtends<T extends true> = T;
type _AssertSuperDoc = AssertExtends<SuperDoc extends object ? true : false>;
type _AssertEditorView = AssertExtends<EditorView extends object ? true : false>;
type _AssertJSON = AssertExtends<ProseMirrorJSON extends object ? true : false>;
type _AssertCreateTheme = AssertExtends<typeof createTheme extends (...args: any[]) => string ? true : false>;
type _AssertBuildTheme = AssertExtends<
typeof buildTheme extends (...args: any[]) => { className: string; css: string } ? true : false
>;