@kabmo-labs/kabmo 0.29.0 → 0.30.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -21,6 +21,7 @@ import type { h as PreactH, render as PreactRender } from 'preact';
21
21
  import type { act as PreactAct } from 'preact/test-utils';
22
22
  import { installDomGlobals, restoreDomGlobals } from '@/test-support/pristine-globals';
23
23
  import type {
24
+ FileEditorTarget,
24
25
  UseFileEditorOptions,
25
26
  UseFileEditorResult,
26
27
  useFileEditor as UseFileEditorHook,
@@ -143,7 +144,7 @@ export interface EditorHarness {
143
144
  /** Latest render's result — re-read after every settle, never held across one. */
144
145
  readonly mounted: UseFileEditorResult | null;
145
146
  settle(): Promise<void>;
146
- mount(target?: typeof TARGET, options?: UseFileEditorOptions): Promise<void>;
147
+ mount(target?: FileEditorTarget, options?: UseFileEditorOptions): Promise<void>;
147
148
  /** Run a state update inside Preact's `act`, then settle. */
148
149
  run(update: () => void): Promise<void>;
149
150
  /**
@@ -177,7 +178,7 @@ export function createEditorHarness(): EditorHarness {
177
178
  });
178
179
  }
179
180
 
180
- async function mount(target: typeof TARGET = TARGET, options: UseFileEditorOptions = {}) {
181
+ async function mount(target: FileEditorTarget = TARGET, options: UseFileEditorOptions = {}) {
181
182
  const Probe = () => {
182
183
  mounted = useFileEditor(target, options);
183
184
  return null;
@@ -0,0 +1,30 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * Reading the client's own CSS in a test.
8
+ *
9
+ * The glass contract is asserted against the stylesheets themselves — a token
10
+ * declared in the wrong block is invisible to `getComputedStyle` in a way no
11
+ * component test can see — so more than one spec needs to read a file and pull
12
+ * one rule's body out of it. Both helpers live here rather than in each spec:
13
+ * a second copy of `ruleBody`'s selector escaping is how one spec starts
14
+ * matching a rule the other does not.
15
+ */
16
+
17
+ const CLIENT_DIR = new URL('../client/', import.meta.url);
18
+
19
+ /** The text of a stylesheet under `src/client/`, e.g. `readClientCss('glass.css')`. */
20
+ export const readClientCss = (file: string): Promise<string> => Bun.file(new URL(file, CLIENT_DIR)).text();
21
+
22
+ /** The body of the first rule whose selector starts a line, e.g. `[x] {`. */
23
+ export function ruleBody(css: string, selector: string): string {
24
+ const start = css.search(new RegExp(`^${selector.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')} \\{`, 'm'));
25
+ if (start < 0) throw new Error(`no rule for ${selector}`);
26
+ const open = css.indexOf('{', start);
27
+ const close = css.indexOf('\n}', open);
28
+ if (close < 0) throw new Error(`unterminated rule for ${selector}`);
29
+ return css.slice(open + 1, close);
30
+ }