ShtukbaseStandard
archivo del paquete→ .shtukbase/packages/design-lenses/test/override.test.ts

test/override.test.ts

64 líneas, 3.2 KB.

El archivo tal como está en el paquete: el código y sus comentarios no se traducen.

  1. import { expect, test } from 'bun:test';
  2. import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
  3. import { tmpdir } from 'node:os';
  4. import { join } from 'node:path';
  5. import { BASE, IDS, OVERRIDE, packages, writeOverride } from './fixtures/override.ts';
  6. test('installed partial library supplies the catalog and shared lens kit, then can be removed from the design', () => {
  7. const temp = mkdtempSync(join(tmpdir(), 'design-override-'));
  8. const root = join(temp, 'project');
  9. const fixture = join(temp, OVERRIDE);
  10. const cli = join(packages, '../../shtuk/src/cli.ts');
  11. const run = (...args: string[]) => {
  12. const result = Bun.spawnSync([process.execPath, cli, ...args], { cwd: root });
  13. const output = result.stdout.toString() + result.stderr.toString();
  14. if (result.exitCode !== 0) throw new Error(output);
  15. return output;
  16. };
  17. try {
  18. mkdirSync(root);
  19. writeOverride(fixture);
  20. for (const pkg of ['shtukbase-style', BASE, 'shtukbase-ui-react', 'design-lenses'])
  21. run('install', join(packages, pkg), '--defaults', '--trust', pkg);
  22. run('install', fixture, '--defaults', '--trust', OVERRIDE);
  23. const read = (rel: string) => readFileSync(join(root, rel), 'utf8');
  24. const design = read('design/design.md');
  25. const resolve = (libraries: string[]) => {
  26. writeFileSync(join(root, 'design/design.md'), design.replace(/^libraries:.*$/m, `libraries: [${libraries.join(', ')}]`));
  27. const sync = run('run', 'design-components', 'sync');
  28. expect(sync).not.toContain('warning: my-ui');
  29. run('run', 'lenses', 'build');
  30. const w: Record<string, any> = {};
  31. new Function('window', read('lib/design/components.data.js'))(w);
  32. expect(w.SB_COMPONENTS.css).toContain('/lib/design/ui.css');
  33. return new Map<string, any>(w.SB_COMPONENTS.components.map((c: any) => [c.id, c]));
  34. };
  35. const withOverride = resolve([OVERRIDE, BASE, 'shtukbase-ui-react']);
  36. const activeCss = read('lib/design/ui.css');
  37. expect(read('lib/kit.css')).toContain(activeCss);
  38. for (const id of IDS) {
  39. const entry = withOverride.get(id);
  40. expect(entry.html).toMatchObject({ library: OVERRIDE, overrides: BASE });
  41. expect(entry.html.source).toContain(`/design/${OVERRIDE}/`);
  42. expect(entry.react.library).toBe('shtukbase-ui-react');
  43. expect(activeCss).toContain(`/* Project UI ${id} */`);
  44. }
  45. expect(withOverride.get('card').html.library).toBe(BASE);
  46. expect(withOverride.get('sidebar').html.library).toBe(BASE); expect(withOverride.has('shell')).toBe(false);
  47. const original = resolve([BASE, 'shtukbase-ui-react']);
  48. const restoredCss = read('lib/design/ui.css');
  49. for (const id of IDS) {
  50. expect(original.get(id).html.library).toBe(BASE);
  51. expect(original.get(id).html.overrides).toBeUndefined();
  52. expect(original.get(id).html.templates).toEqual(withOverride.get(id).html.templates);
  53. expect(restoredCss).not.toContain(`/* Project UI ${id} */`);
  54. }
  55. expect(original.get('card')).toEqual(withOverride.get('card'));
  56. expect(read('lib/kit.css')).toContain(restoredCss);
  57. expect(read('lib/kit.css')).not.toContain('/* Project UI');
  58. } finally {
  59. rmSync(temp, { recursive: true, force: true });
  60. }
  61. }, 30_000);