@motion-proto/live-tokens 0.76.0 → 0.77.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.
@@ -7,7 +7,7 @@ import {
7
7
  requiresInteraction,
8
8
  selectedContracts,
9
9
  shippedContracts
10
- } from "./chunk-LXR3MN6N.js";
10
+ } from "./chunk-4JQX6WWL.js";
11
11
  import {
12
12
  createVitestConfig
13
13
  } from "./chunk-FAFOAWYL.js";
@@ -116,16 +116,6 @@ async function createPlaywrightConfig(options = {}) {
116
116
  const baseURL = `http://${HOST}:${port}`;
117
117
  process.env[COMPONENTS_PATH_ENV] = settings.componentsPath;
118
118
  if (settings.contractsModule) process.env[CONTRACTS_MODULE_ENV] = settings.contractsModule;
119
- const requested = process.env[COMPONENT_ENV];
120
- if (requested) {
121
- const matches = await selectedContracts();
122
- if (matches.length === 0) {
123
- const all = await allContracts();
124
- throw new Error(
125
- `${COMPONENT_ENV}=${requested} names a component with no contract. Declared: ${all.map((contract) => contract.id).sort().join(", ")}`
126
- );
127
- }
128
- }
129
119
  return defineConfig({
130
120
  testDir: options.testDir ?? CONTRACT_TEST_DIR,
131
121
  // The component suites carry their serial and parallel intent per file:
@@ -1 +1 @@
1
- {"version":3,"sources":["../testing/playwright.ts","../testing/isolation.ts","../testing/port.ts"],"sourcesContent":["import path from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport {\n defineConfig,\n devices,\n type PlaywrightTestConfig,\n type PlaywrightTestProject,\n} from '@playwright/test';\nimport {\n COMPONENT_ENV,\n COMPONENTS_PATH_ENV,\n devServerCommand,\n resolveTestingConfig,\n type LiveTokensTestingConfig,\n} from './config';\nimport { allContracts, CONTRACTS_MODULE_ENV, selectedContracts } from './contracts';\nimport { DATA_DIR_ENV, TEST_DATA_DIR_ENV, isolateDataDir } from './isolation';\nimport { resolvePort } from './port';\n\nconst HOST = '127.0.0.1';\n\n/** The shipped suites, wherever the package is installed. */\nconst CONTRACT_TEST_DIR = path.dirname(fileURLToPath(import.meta.url));\n\nexport interface PlaywrightConfigOptions extends LiveTokensTestingConfig {\n /** Project root the settings resolve against. Default `process.cwd()`. */\n root?: string;\n /** Projects that run beside the contract project. */\n extraProjects?: PlaywrightTestProject[];\n /** Where projects that declare no `testDir` of their own look. */\n testDir?: string;\n}\n\n/**\n * The contract project, its dev server, and the data isolation the two share.\n *\n * Isolation runs here rather than in a global setup because the config is the\n * first thing every process in the run evaluates: the environment it leaves\n * behind reaches the workers and the dev server, and nothing in the run can\n * observe the state before it.\n */\nexport async function createPlaywrightConfig(\n options: PlaywrightConfigOptions = {},\n): Promise<PlaywrightTestConfig> {\n const settings = resolveTestingConfig(options, options.root);\n const { dataDir } = isolateDataDir(settings.dataDir);\n const port = resolvePort(settings.port);\n const baseURL = `http://${HOST}:${port}`;\n\n process.env[COMPONENTS_PATH_ENV] = settings.componentsPath;\n if (settings.contractsModule) process.env[CONTRACTS_MODULE_ENV] = settings.contractsModule;\n\n const requested = process.env[COMPONENT_ENV];\n if (requested) {\n const matches = await selectedContracts();\n if (matches.length === 0) {\n const all = await allContracts();\n throw new Error(\n `${COMPONENT_ENV}=${requested} names a component with no contract. `\n + `Declared: ${all.map((contract) => contract.id).sort().join(', ')}`,\n );\n }\n }\n\n return defineConfig({\n testDir: options.testDir ?? CONTRACT_TEST_DIR,\n // The component suites carry their serial and parallel intent per file:\n // `component-editor.contract.ts` runs each component's save and reset\n // cycles in order against one data tree. Turning this on would interleave\n // them.\n fullyParallel: false,\n // One worker is the safe default: the specs share a dev server and a data\n // directory. A run that can afford more passes a worker count on the\n // command line.\n workers: 1,\n timeout: 30_000,\n expect: { timeout: 5_000 },\n // A shared-server suite times out under CI load in ways it never does\n // locally, and without a retry budget one wobble aborts a tagged release.\n retries: process.env.CI ? 2 : 0,\n // Absolute and rooted at the consumer project, not the config file's own\n // directory: `check-component --tests`'s generated config lives in a\n // temporary directory that gets removed on completion, and a relative\n // `outputDir` would put every trace and screenshot in there too.\n outputDir: path.join(settings.root, 'test-results/playwright'),\n reporter: process.env.CI ? [['line'], ['html', { open: 'never' }]] : 'list',\n use: {\n baseURL,\n // Unset, both of these are unbounded: a locator that never resolves waits\n // out the whole test timeout and reports nothing about where it stopped.\n actionTimeout: 10_000,\n navigationTimeout: 30_000,\n trace: 'on-first-retry',\n screenshot: 'only-on-failure',\n // `retain-on-failure` still records every passing test and throws the\n // file away, which costs ~28% CPU. Match the trace policy instead.\n video: 'on-first-retry',\n },\n projects: [\n ...(options.extraProjects ?? []),\n {\n name: 'contract',\n testDir: CONTRACT_TEST_DIR,\n // `.ts` in this repo, `.js` once tsup compiles the shipped build into\n // `src/testing-js`; matching both here needs no build-time swap.\n testMatch: '**/component-*.contract.{ts,js}',\n // `.tabs-preview` now caps its sticky band at 50vh, which is enough for\n // image, panel, card and sidenavigation to pass alone at 1280x720. A\n // full parallel run still fails panel's gradient radio there, so the\n // band can cover a control at some scroll positions. Until that is\n // fixed the suite runs taller. See docs/contract-test-defects.md.\n use: { ...devices['Desktop Chrome'], viewport: { width: 1280, height: 900 } },\n },\n ],\n webServer: {\n command: devServerCommand(settings.devCommand, HOST, port),\n // Otherwise defaults to the config file's own directory. A generated\n // config that lives outside the consumer root (`check-component\n // --tests`'s temporary config) would run `npm run dev` from wherever\n // that happens to be instead.\n cwd: settings.root,\n url: baseURL,\n // A server this run did not start carries none of these variables, so it\n // would write the project's own data tree.\n reuseExistingServer: false,\n timeout: 120_000,\n env: {\n ...process.env,\n [TEST_DATA_DIR_ENV]: dataDir,\n [DATA_DIR_ENV]: dataDir,\n },\n },\n });\n}\n","import fs from 'node:fs';\nimport os from 'node:os';\nimport path from 'node:path';\n\n/**\n * The plugin reads this name ahead of its own options and\n * `live-tokens.config.json`, so setting it redirects every server-side write —\n * the data tree, `tokens.generated.css`, and `fonts.css` — into the copy.\n */\nexport const TEST_DATA_DIR_ENV = 'LIVE_TOKENS_TEST_DATA_DIR';\n\n/** What the suites and the harness read component configs from in the runner's\n * own process. It names the same directory and is a separate variable because\n * it answers a different question: where a reader looks, not where the server\n * is confined. */\nexport const DATA_DIR_ENV = 'LIVE_TOKENS_DATA_DIR';\n\n/**\n * A developer's current session rather than the document under test. Each one\n * is gitignored or dev-written, so leaving it in the copy would make the run\n * pass or fail on whichever theme the maintainer has open.\n *\n * _working.json an unsaved buffer, which reads as a dirty document and\n * can raise a destructive confirmation dialog\n * _active.json the theme the editor has open. One carrying a sketchstyle\n * boots the suite with the sketch layer on, which paints\n * every fill onto a pseudo-element and leaves the real\n * background transparent\n * _production.json the theme baked into tokens.generated.css\n *\n * A missing pointer resolves to \"default\" at runtime, so removing them is the\n * whole reset.\n */\nconst SESSION_FILES = new Set(['_working.json', '_active.json', '_production.json']);\n\nexport interface IsolatedData {\n dataDir: string;\n /** True when this process made the copy and owns removing it. */\n created: boolean;\n}\n\nlet removed = false;\n\nfunction registerCleanup(dataDir: string): void {\n const remove = () => {\n if (removed) return;\n removed = true;\n fs.rmSync(dataDir, { recursive: true, force: true });\n };\n process.once('exit', remove);\n // Playwright owns the exit path on a signal: it stops the workers and kills\n // the dev server's process group, then exits, which reaches `exit` above.\n // These two only make sure the copy is gone before that teardown starts.\n process.once('SIGINT', remove);\n process.once('SIGTERM', remove);\n}\n\n/**\n * Copy `sourceDataDir` into a unique temporary directory and point both the\n * server and the runner at it. Idempotent across processes: Playwright loads\n * the config again in every worker, and each inherits the parent's environment,\n * so only the first call copies anything.\n */\nexport function isolateDataDir(sourceDataDir: string): IsolatedData {\n const existing = process.env[TEST_DATA_DIR_ENV];\n if (existing) {\n const dataDir = path.resolve(existing);\n if (!fs.existsSync(dataDir)) {\n throw new Error(`${TEST_DATA_DIR_ENV} names ${dataDir}, which does not exist`);\n }\n process.env[DATA_DIR_ENV] = dataDir;\n return { dataDir, created: false };\n }\n\n const source = path.resolve(sourceDataDir);\n if (!fs.existsSync(source)) {\n throw new Error(\n `No data directory at ${source}. Set \\`dataDir\\` in live-tokens.testing.ts `\n + 'when the project keeps its live-tokens data somewhere else.',\n );\n }\n\n // realpath: macOS resolves os.tmpdir() through a symlink, and the plugin\n // compares resolved paths when it decides whether a write is in scope.\n const dataDir = fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), 'live-tokens-contract-')));\n fs.cpSync(source, dataDir, { recursive: true });\n for (const entry of fs.readdirSync(dataDir, { recursive: true }) as string[]) {\n if (SESSION_FILES.has(path.basename(entry))) {\n fs.rmSync(path.join(dataDir, entry), { force: true });\n }\n }\n\n process.env[TEST_DATA_DIR_ENV] = dataDir;\n process.env[DATA_DIR_ENV] = dataDir;\n registerCleanup(dataDir);\n return { dataDir, created: true };\n}\n","import { execFileSync } from 'node:child_process';\n\nexport const PORT_ENV = 'LIVE_TOKENS_TEST_PORT';\n\nconst PREFERRED_PORT = 4173;\n\n/** Bind the preferred port, fall back to whatever the OS hands out, print the\n * answer. A Playwright config is evaluated synchronously, so the check runs in\n * a child rather than on a listener callback. */\nconst PROBE = `\nconst net = require('net');\nconst listen = (port) => new Promise((resolve, reject) => {\n const server = net.createServer();\n server.once('error', reject);\n server.listen(port, '127.0.0.1', () => {\n const { port: bound } = server.address();\n server.close(() => resolve(bound));\n });\n});\n// process.stdout.write, not console.log: the parent's FORCE_COLOR makes\n// console.log wrap a number in ANSI escapes.\nlisten(Number(process.argv[1])).catch(() => listen(0)).then((port) => process.stdout.write(String(port)));\n`;\n\n/**\n * The port the dev server and `baseURL` share. Cached in the environment so\n * every Playwright worker, which loads the config again in its own process,\n * reads the port the main process settled on.\n */\nexport function resolvePort(preferred?: number): number {\n const cached = process.env[PORT_ENV];\n if (cached) return Number(cached);\n\n const port = preferred\n ?? Number(execFileSync(process.execPath, ['-e', PROBE, String(PREFERRED_PORT)], {\n encoding: 'utf-8',\n }).trim());\n if (!Number.isInteger(port) || port <= 0) {\n throw new Error(`Could not settle on a dev-server port (read ${port})`);\n }\n process.env[PORT_ENV] = String(port);\n return port;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAOA,WA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AY,MAAM,IAAI;AAAA;AAAA;AAAA;AAAA;AAAA,MAKzD,KAAK,SAAS;AAAA,MACd,KAAK;AAAA;AAAA;AAAA,MAGL,qBAAqB;AAAA,MACrB,SAAS;AAAA,MACT,KAAK;AAAA,QACH,GAAG,QAAQ;AAAA,QACX,CAAC,iBAAiB,GAAG;AAAA,QACrB,CAAC,YAAY,GAAG;AAAA,MAClB;AAAA,IACF;AAAA,EACF,CAAC;AACH;","names":["path","dataDir","path"]}
1
+ {"version":3,"sources":["../testing/playwright.ts","../testing/isolation.ts","../testing/port.ts"],"sourcesContent":["import path from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport {\n defineConfig,\n devices,\n type PlaywrightTestConfig,\n type PlaywrightTestProject,\n} from '@playwright/test';\nimport {\n COMPONENT_ENV,\n COMPONENTS_PATH_ENV,\n devServerCommand,\n resolveTestingConfig,\n type LiveTokensTestingConfig,\n} from './config';\nimport { CONTRACTS_MODULE_ENV } from './contracts';\nimport { DATA_DIR_ENV, TEST_DATA_DIR_ENV, isolateDataDir } from './isolation';\nimport { resolvePort } from './port';\n\nconst HOST = '127.0.0.1';\n\n/** The shipped suites, wherever the package is installed. */\nconst CONTRACT_TEST_DIR = path.dirname(fileURLToPath(import.meta.url));\n\nexport interface PlaywrightConfigOptions extends LiveTokensTestingConfig {\n /** Project root the settings resolve against. Default `process.cwd()`. */\n root?: string;\n /** Projects that run beside the contract project. */\n extraProjects?: PlaywrightTestProject[];\n /** Where projects that declare no `testDir` of their own look. */\n testDir?: string;\n}\n\n/**\n * The contract project, its dev server, and the data isolation the two share.\n *\n * Isolation runs here rather than in a global setup because the config is the\n * first thing every process in the run evaluates: the environment it leaves\n * behind reaches the workers and the dev server, and nothing in the run can\n * observe the state before it.\n */\nexport async function createPlaywrightConfig(\n options: PlaywrightConfigOptions = {},\n): Promise<PlaywrightTestConfig> {\n const settings = resolveTestingConfig(options, options.root);\n const { dataDir } = isolateDataDir(settings.dataDir);\n const port = resolvePort(settings.port);\n const baseURL = `http://${HOST}:${port}`;\n\n process.env[COMPONENTS_PATH_ENV] = settings.componentsPath;\n if (settings.contractsModule) process.env[CONTRACTS_MODULE_ENV] = settings.contractsModule;\n\n return defineConfig({\n testDir: options.testDir ?? CONTRACT_TEST_DIR,\n // The component suites carry their serial and parallel intent per file:\n // `component-editor.contract.ts` runs each component's save and reset\n // cycles in order against one data tree. Turning this on would interleave\n // them.\n fullyParallel: false,\n // One worker is the safe default: the specs share a dev server and a data\n // directory. A run that can afford more passes a worker count on the\n // command line.\n workers: 1,\n timeout: 30_000,\n expect: { timeout: 5_000 },\n // A shared-server suite times out under CI load in ways it never does\n // locally, and without a retry budget one wobble aborts a tagged release.\n retries: process.env.CI ? 2 : 0,\n // Absolute and rooted at the consumer project, not the config file's own\n // directory: `check-component --tests`'s generated config lives in a\n // temporary directory that gets removed on completion, and a relative\n // `outputDir` would put every trace and screenshot in there too.\n outputDir: path.join(settings.root, 'test-results/playwright'),\n reporter: process.env.CI ? [['line'], ['html', { open: 'never' }]] : 'list',\n use: {\n baseURL,\n // Unset, both of these are unbounded: a locator that never resolves waits\n // out the whole test timeout and reports nothing about where it stopped.\n actionTimeout: 10_000,\n navigationTimeout: 30_000,\n trace: 'on-first-retry',\n screenshot: 'only-on-failure',\n // `retain-on-failure` still records every passing test and throws the\n // file away, which costs ~28% CPU. Match the trace policy instead.\n video: 'on-first-retry',\n },\n projects: [\n ...(options.extraProjects ?? []),\n {\n name: 'contract',\n testDir: CONTRACT_TEST_DIR,\n // `.ts` in this repo, `.js` once tsup compiles the shipped build into\n // `src/testing-js`; matching both here needs no build-time swap.\n testMatch: '**/component-*.contract.{ts,js}',\n // `.tabs-preview` now caps its sticky band at 50vh, which is enough for\n // image, panel, card and sidenavigation to pass alone at 1280x720. A\n // full parallel run still fails panel's gradient radio there, so the\n // band can cover a control at some scroll positions. Until that is\n // fixed the suite runs taller. See docs/contract-test-defects.md.\n use: { ...devices['Desktop Chrome'], viewport: { width: 1280, height: 900 } },\n },\n ],\n webServer: {\n command: devServerCommand(settings.devCommand, HOST, port),\n // Otherwise defaults to the config file's own directory. A generated\n // config that lives outside the consumer root (`check-component\n // --tests`'s temporary config) would run `npm run dev` from wherever\n // that happens to be instead.\n cwd: settings.root,\n url: baseURL,\n // A server this run did not start carries none of these variables, so it\n // would write the project's own data tree.\n reuseExistingServer: false,\n timeout: 120_000,\n env: {\n ...process.env,\n [TEST_DATA_DIR_ENV]: dataDir,\n [DATA_DIR_ENV]: dataDir,\n },\n },\n });\n}\n","import fs from 'node:fs';\nimport os from 'node:os';\nimport path from 'node:path';\n\n/**\n * The plugin reads this name ahead of its own options and\n * `live-tokens.config.json`, so setting it redirects every server-side write —\n * the data tree, `tokens.generated.css`, and `fonts.css` — into the copy.\n */\nexport const TEST_DATA_DIR_ENV = 'LIVE_TOKENS_TEST_DATA_DIR';\n\n/** What the suites and the harness read component configs from in the runner's\n * own process. It names the same directory and is a separate variable because\n * it answers a different question: where a reader looks, not where the server\n * is confined. */\nexport const DATA_DIR_ENV = 'LIVE_TOKENS_DATA_DIR';\n\n/**\n * A developer's current session rather than the document under test. Each one\n * is gitignored or dev-written, so leaving it in the copy would make the run\n * pass or fail on whichever theme the maintainer has open.\n *\n * _working.json an unsaved buffer, which reads as a dirty document and\n * can raise a destructive confirmation dialog\n * _active.json the theme the editor has open. One carrying a sketchstyle\n * boots the suite with the sketch layer on, which paints\n * every fill onto a pseudo-element and leaves the real\n * background transparent\n * _production.json the theme baked into tokens.generated.css\n *\n * A missing pointer resolves to \"default\" at runtime, so removing them is the\n * whole reset.\n */\nconst SESSION_FILES = new Set(['_working.json', '_active.json', '_production.json']);\n\nexport interface IsolatedData {\n dataDir: string;\n /** True when this process made the copy and owns removing it. */\n created: boolean;\n}\n\nlet removed = false;\n\nfunction registerCleanup(dataDir: string): void {\n const remove = () => {\n if (removed) return;\n removed = true;\n fs.rmSync(dataDir, { recursive: true, force: true });\n };\n process.once('exit', remove);\n // Playwright owns the exit path on a signal: it stops the workers and kills\n // the dev server's process group, then exits, which reaches `exit` above.\n // These two only make sure the copy is gone before that teardown starts.\n process.once('SIGINT', remove);\n process.once('SIGTERM', remove);\n}\n\n/**\n * Copy `sourceDataDir` into a unique temporary directory and point both the\n * server and the runner at it. Idempotent across processes: Playwright loads\n * the config again in every worker, and each inherits the parent's environment,\n * so only the first call copies anything.\n */\nexport function isolateDataDir(sourceDataDir: string): IsolatedData {\n const existing = process.env[TEST_DATA_DIR_ENV];\n if (existing) {\n const dataDir = path.resolve(existing);\n if (!fs.existsSync(dataDir)) {\n throw new Error(`${TEST_DATA_DIR_ENV} names ${dataDir}, which does not exist`);\n }\n process.env[DATA_DIR_ENV] = dataDir;\n return { dataDir, created: false };\n }\n\n const source = path.resolve(sourceDataDir);\n if (!fs.existsSync(source)) {\n throw new Error(\n `No data directory at ${source}. Set \\`dataDir\\` in live-tokens.testing.ts `\n + 'when the project keeps its live-tokens data somewhere else.',\n );\n }\n\n // realpath: macOS resolves os.tmpdir() through a symlink, and the plugin\n // compares resolved paths when it decides whether a write is in scope.\n const dataDir = fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), 'live-tokens-contract-')));\n fs.cpSync(source, dataDir, { recursive: true });\n for (const entry of fs.readdirSync(dataDir, { recursive: true }) as string[]) {\n if (SESSION_FILES.has(path.basename(entry))) {\n fs.rmSync(path.join(dataDir, entry), { force: true });\n }\n }\n\n process.env[TEST_DATA_DIR_ENV] = dataDir;\n process.env[DATA_DIR_ENV] = dataDir;\n registerCleanup(dataDir);\n return { dataDir, created: true };\n}\n","import { execFileSync } from 'node:child_process';\n\nexport const PORT_ENV = 'LIVE_TOKENS_TEST_PORT';\n\nconst PREFERRED_PORT = 4173;\n\n/** Bind the preferred port, fall back to whatever the OS hands out, print the\n * answer. A Playwright config is evaluated synchronously, so the check runs in\n * a child rather than on a listener callback. */\nconst PROBE = `\nconst net = require('net');\nconst listen = (port) => new Promise((resolve, reject) => {\n const server = net.createServer();\n server.once('error', reject);\n server.listen(port, '127.0.0.1', () => {\n const { port: bound } = server.address();\n server.close(() => resolve(bound));\n });\n});\n// process.stdout.write, not console.log: the parent's FORCE_COLOR makes\n// console.log wrap a number in ANSI escapes.\nlisten(Number(process.argv[1])).catch(() => listen(0)).then((port) => process.stdout.write(String(port)));\n`;\n\n/**\n * The port the dev server and `baseURL` share. Cached in the environment so\n * every Playwright worker, which loads the config again in its own process,\n * reads the port the main process settled on.\n */\nexport function resolvePort(preferred?: number): number {\n const cached = process.env[PORT_ENV];\n if (cached) return Number(cached);\n\n const port = preferred\n ?? Number(execFileSync(process.execPath, ['-e', PROBE, String(PREFERRED_PORT)], {\n encoding: 'utf-8',\n }).trim());\n if (!Number.isInteger(port) || port <= 0) {\n throw new Error(`Could not settle on a dev-server port (read ${port})`);\n }\n process.env[PORT_ENV] = String(port);\n return port;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAOA,WAAU;AACjB,SAAS,qBAAqB;AAC9B;AAAA,EACE;AAAA,EACA;AAAA,OAGK;;;ACPP,OAAO,QAAQ;AACf,OAAO,QAAQ;AACf,OAAO,UAAU;AAOV,IAAM,oBAAoB;AAM1B,IAAM,eAAe;AAkB5B,IAAM,gBAAgB,oBAAI,IAAI,CAAC,iBAAiB,gBAAgB,kBAAkB,CAAC;AAQnF,IAAI,UAAU;AAEd,SAAS,gBAAgB,SAAuB;AAC9C,QAAM,SAAS,MAAM;AACnB,QAAI,QAAS;AACb,cAAU;AACV,OAAG,OAAO,SAAS,EAAE,WAAW,MAAM,OAAO,KAAK,CAAC;AAAA,EACrD;AACA,UAAQ,KAAK,QAAQ,MAAM;AAI3B,UAAQ,KAAK,UAAU,MAAM;AAC7B,UAAQ,KAAK,WAAW,MAAM;AAChC;AAQO,SAAS,eAAe,eAAqC;AAClE,QAAM,WAAW,QAAQ,IAAI,iBAAiB;AAC9C,MAAI,UAAU;AACZ,UAAMC,WAAU,KAAK,QAAQ,QAAQ;AACrC,QAAI,CAAC,GAAG,WAA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ACE,MAAM;AAAA,QACN,SAAS;AAAA;AAAA;AAAA,QAGT,WAAW;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,QAMX,KAAK,EAAE,GAAG,QAAQ,gBAAgB,GAAG,UAAU,EAAE,OAAO,MAAM,QAAQ,IAAI,EAAE;AAAA,MAC9E;AAAA,IACF;AAAA,IACA,WAAW;AAAA,MACT,SAAS,iBAAiB,SAAS,YAAY,MAAM,IAAI;AAAA;AAAA;AAAA;AAAA;AAAA,MAKzD,KAAK,SAAS;AAAA,MACd,KAAK;AAAA;AAAA;AAAA,MAGL,qBAAqB;AAAA,MACrB,SAAS;AAAA,MACT,KAAK;AAAA,QACH,GAAG,QAAQ;AAAA,QACX,CAAC,iBAAiB,GAAG;AAAA,QACrB,CAAC,YAAY,GAAG;AAAA,MAClB;AAAA,IACF;AAAA,EACF,CAAC;AACH;","names":["path","dataDir","path"]}
@@ -45,11 +45,16 @@ npx @motion-proto/live-tokens setup-claude
45
45
 
46
46
  `npm run test:design` runs `check-component --tests`: the static checks plus
47
47
  the registry contract and the component contract suites, in a browser, against
48
- this project. It needs three devDependencies the template does not install:
48
+ this project. Playwright, Vitest, and happy-dom are installed; the browser is
49
+ a one-time download:
49
50
 
50
51
  ```bash
51
- npm install -D @playwright/test vitest happy-dom
52
52
  npx playwright install chromium
53
53
  ```
54
54
 
55
+ `live-tokens.testing.ts` names the two files the run reads: `src/registerComponents.ts`
56
+ registers your components, and `tests/contracts.ts` holds one contract per
57
+ component, which is what the browser suites drive. The create-component skill
58
+ writes both.
59
+
55
60
  A failing run leaves its report under `test-results/`, gitignored.
@@ -0,0 +1,6 @@
1
+ import { defineTestingConfig } from '@motion-proto/live-tokens/testing/vitest';
2
+
3
+ export default defineTestingConfig({
4
+ registrySetup: 'src/registerComponents.ts',
5
+ contractsModule: 'tests/contracts.ts',
6
+ });
@@ -16,12 +16,15 @@
16
16
  "@motion-proto/live-tokens": "__LT_VERSION__"
17
17
  },
18
18
  "devDependencies": {
19
+ "@playwright/test": "^1.62.1",
19
20
  "@sveltejs/vite-plugin-svelte": "^7.1.2",
20
21
  "@types/node": "^25.9.1",
22
+ "happy-dom": "^20.9.0",
21
23
  "sass": "^1.98.0",
22
24
  "svelte": "^5.55.5",
23
25
  "svelte-check": "^4.4.8",
24
26
  "typescript": "~6.0.3",
25
- "vite": "^8.0.14"
27
+ "vite": "^8.0.14",
28
+ "vitest": "^4.1.4"
26
29
  }
27
30
  }
@@ -6,6 +6,7 @@ import '@motion-proto/live-tokens/app/fonts.css';
6
6
 
7
7
  import { bootLiveTokens, configureEditor } from '@motion-proto/live-tokens';
8
8
  import App from './App.svelte';
9
+ import './registerComponents';
9
10
 
10
11
  configureEditor({ storagePrefix: 'app-' });
11
12
 
@@ -0,0 +1,4 @@
1
+ // Registration only. `src/main.ts` imports it for the app and
2
+ // `live-tokens.testing.ts` names it for `check-component --tests`, so a
3
+ // component registered here reaches both without mounting the app.
4
+ export {};
@@ -0,0 +1,3 @@
1
+ import type { ComponentContract } from '@motion-proto/live-tokens/testing';
2
+
3
+ export const contracts: ComponentContract[] = [];
@@ -13,5 +13,5 @@
13
13
  "verbatimModuleSyntax": true,
14
14
  "types": ["vite/client"]
15
15
  },
16
- "include": ["src/**/*.ts", "src/**/*.svelte"]
16
+ "include": ["src/**/*.ts", "src/**/*.svelte", "tests/**/*.ts", "live-tokens.testing.ts"]
17
17
  }