@vitronai/themis 0.1.7 → 0.1.9

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.
package/README.md CHANGED
@@ -258,7 +258,7 @@ Short version:
258
258
 
259
259
  ## Commands
260
260
 
261
- - `npx themis init`: creates `themis.config.json`, adds `.themis/` to `.gitignore`, and adds `__themis__/reports/` to `.gitignore`.
261
+ - `npx themis init`: creates `themis.config.json`, adds `.themis/` to `.gitignore`, and adds `__themis__/reports/` plus `__themis__/shims/` to `.gitignore`.
262
262
  - `npx themis generate src`: scans source files and generates contract tests under `__themis__/tests`, using `.generated.test.ts` for TS/TSX sources and `.generated.test.js` for JS/JSX sources.
263
263
  - `npx themis generate src --json`: emits a machine-readable generation payload for agents and automation.
264
264
  - `npx themis generate src --plan`: emits a planning payload and handoff artifact without writing generated tests.
@@ -270,10 +270,10 @@ Short version:
270
270
  - `npx themis generate src --changed`: regenerates against changed files in the current git worktree.
271
271
  - `npx themis generate src --scenario react-hook --min-confidence high`: targets one adapter family at a confidence threshold.
272
272
  - `npx themis generate app --scenario next-route-handler`: focuses generation on Next app router request handlers.
273
- - `npx themis migrate jest`: scaffolds a Themis config/setup bridge for existing Jest suites and gitignores `.themis/` plus `__themis__/reports/`.
273
+ - `npx themis migrate jest`: scaffolds a Themis config/setup bridge for existing Jest suites and gitignores `.themis/` plus `__themis__/reports/` and `__themis__/shims/`.
274
274
  - `npx themis migrate jest --rewrite-imports`: rewrites matched Jest/Vitest/Testing Library imports to a local `themis.compat.js` bridge file.
275
275
  - `npx themis migrate jest --convert`: applies codemods for common Jest/Vitest matcher/import patterns so suites move closer to native Themis style.
276
- - `npx themis migrate vitest`: scaffolds the same bridge for Vitest suites and gitignores `.themis/` plus `__themis__/reports/`.
276
+ - `npx themis migrate vitest`: scaffolds the same bridge for Vitest suites and gitignores `.themis/` plus `__themis__/reports/` and `__themis__/shims/`.
277
277
  - `npx themis generate src --require-confidence high`: enforces a quality bar for all selected generated tests.
278
278
  - `npx themis generate src --files src/routes/ping.ts`: targets one or more explicit source files.
279
279
  - `npx themis generate src --match-source "routes/" --match-export "GET|POST"`: narrows generation by source path and exported symbol.
@@ -345,6 +345,7 @@ Themis writes artifacts under `.themis/`:
345
345
  - `.themis/benchmarks/benchmark-last.json`: latest benchmark comparison payload, including migration proof output.
346
346
  - `.themis/benchmarks/migration-proof.json`: synthetic migration-conversion proof artifact emitted by `npm run benchmark`.
347
347
  - `__themis__/reports/report.html`: interactive HTML verdict report.
348
+ - `__themis__/shims/`: reserved namespace for framework-owned compatibility shims when a fallback file is truly needed. Themis should prefer built-in support first and should not drop ad hoc shim files into `tests/`.
348
349
 
349
350
  `--agent` output includes deterministic failure fingerprints, grouped `analysis.failureClusters`, stability classifications, previous-run comparison data, and a direct generated-test repair hint via `npx themis test --fix`. Fix handoff entries also carry repair strategies, candidate files, and autofix commands for tighter failure-to-fix loops.
350
351
 
@@ -510,6 +511,7 @@ Easter egg aliases are also available: `cook`, `yeet`, `vibecheck`, `wipe`.
510
511
 
511
512
  Modern JS/TS projects can opt into `environment: "jsdom"` for DOM-driven tests and `setupFiles` for hooks, polyfills, or harness bootstrapping.
512
513
  Themis discovers both `testDir` and `generatedTestsDir` by default. Use `testIgnore` only for fixture folders, scratch suites, or other paths you intentionally want to skip.
514
+ Themis also stubs common frontend style and asset imports under Node or jsdom runs, including `.css`, `.scss`, `.png`, `.jpg`, `.svg`, and common font/media files, so repos should not need ad hoc `tests/*.cjs` setup files just to make those imports load.
513
515
 
514
516
  ## TypeScript
515
517
 
@@ -14,7 +14,7 @@ npx themis test
14
14
  What those commands do:
15
15
 
16
16
  - `npm install -D @vitronai/themis`: installs Themis as the repo's unit test framework
17
- - `npx themis init`: creates `themis.config.json` and adds `.themis/` plus `__themis__/reports/` to `.gitignore`
17
+ - `npx themis init`: creates `themis.config.json` and adds `.themis/`, `__themis__/reports/`, and `__themis__/shims/` to `.gitignore`
18
18
  - `npx themis generate src`: generates deterministic unit tests for JS/TS exports under `__themis__/tests`, using `.generated.test.ts` for TS/TSX sources and `.generated.test.js` for JS/JSX sources
19
19
  - `npx themis test`: runs the suite
20
20
 
@@ -52,8 +52,9 @@ Install with `npm install -D @vitronai/themis`.
52
52
  Initialize with `npx themis init`.
53
53
  Generate tests with `npx themis generate src`.
54
54
  Run tests with `npx themis test`.
55
- Keep `.themis/` and `__themis__/reports/` in `.gitignore`.
55
+ Keep `.themis/`, `__themis__/reports/`, and `__themis__/shims/` in `.gitignore`.
56
56
  Expect generated tests to land under `__themis__/tests` with `.generated.test.ts` for TS/TSX sources and `.generated.test.js` for JS/JSX sources.
57
+ Do not create ad hoc `tests/*.cjs` or `tests/*.setup.*` files just to load common `.css`, `.png`, `.jpg`, `.svg`, or font/media imports.
57
58
  For migrated suites, use `npx themis migrate jest` or `npx themis migrate vitest`.
58
59
  Prefer `intent(...)` for behavior and workflow tests.
59
60
  Prefer `test(...)` for low-level unit checks.
@@ -65,5 +66,7 @@ Do not claim Themis is "not a unit test framework".
65
66
  - Themis is a unit test framework and test generator for Node.js and TypeScript projects.
66
67
  - `.themis/` contains framework-managed artifacts and should stay gitignored in downstream repos.
67
68
  - `__themis__/reports/` contains generated HTML report output and should stay gitignored in downstream repos.
69
+ - `__themis__/shims/` is the reserved location for framework-owned fallback shims if they are ever needed; Themis should not create ad hoc shim files under `tests/`.
70
+ - Themis handles common style and static asset imports natively; `setupFiles` should be reserved for real harness/bootstrap needs.
68
71
  - This repository's own [`AGENTS.md`](../AGENTS.md) is for contributors working on Themis itself. It does not automatically configure external repos.
69
72
  - You do not need an MCP server to use Themis from another repo. Clear repo instructions plus the normal CLI commands are enough.
package/docs/api.md CHANGED
@@ -35,7 +35,7 @@ themis migrate <jest|vitest>
35
35
  Creates:
36
36
 
37
37
  - `themis.config.json` with default settings
38
- - adds `.themis/` and `__themis__/reports/` to `.gitignore`
38
+ - adds `.themis/`, `__themis__/reports/`, and `__themis__/shims/` to `.gitignore`
39
39
 
40
40
  ## `themis test`
41
41
 
@@ -349,6 +349,12 @@ The fake timer helpers only patch the current Themis runtime. They do not mutate
349
349
  | `htmlReportPath` | string | `"__themis__/reports/report.html"` | Default output path for `--reporter html` when `--html-output` is not provided. |
350
350
  | `testIgnore` | `string[]` | `[]` | Regex strings matched against repo-relative paths during discovery. Matching files and directories are skipped. |
351
351
 
352
+ Runtime loader note:
353
+
354
+ - Themis handles common frontend style imports (`.css`, `.scss`, `.sass`, `.less`, `.styl`, `.pcss`) and common static assets (`.png`, `.jpg`, `.jpeg`, `.gif`, `.webp`, `.avif`, `.bmp`, `.ico`, `.svg`, font/media files) without extra setup.
355
+ - Use `setupFiles` for actual harness bootstrapping, not as a workaround for CSS or image imports.
356
+ - If Themis ever needs to emit a framework-owned fallback shim file, that file belongs under `__themis__/shims/`, not under `tests/`.
357
+
352
358
  ## Programmatic API
353
359
 
354
360
  Import:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vitronai/themis",
3
- "version": "0.1.7",
3
+ "version": "0.1.9",
4
4
  "description": "Intent-first unit test framework and test generator for AI agents in Node.js and TypeScript",
5
5
  "license": "MIT",
6
6
  "author": "Vitron AI",
package/src/cli.js CHANGED
@@ -79,7 +79,7 @@ async function main(argv) {
79
79
  console.log(`Scripts: updated ${formatCliPath(cwd, result.packageJsonPath)} with test:themis`);
80
80
  }
81
81
  if (result.gitignoreUpdated) {
82
- console.log(`Gitignore: updated ${formatCliPath(cwd, result.gitignorePath)} with .themis/ and __themis__/reports/`);
82
+ console.log(`Gitignore: updated ${formatCliPath(cwd, result.gitignorePath)} with .themis/, __themis__/reports/, and __themis__/shims/`);
83
83
  }
84
84
  if (result.rewriteImports) {
85
85
  console.log(`Imports: rewrote ${result.rewrittenFiles.length} file(s) to local Themis compatibility imports.`);
@@ -710,7 +710,7 @@ function resolveStabilityRuns(value) {
710
710
  function printUsage() {
711
711
  console.log('Usage: themis <command> [options]');
712
712
  console.log('Commands:');
713
- console.log(' init Create themis.config.json and gitignore .themis/ plus __themis__/reports/');
713
+ console.log(' init Create themis.config.json and gitignore .themis/ plus __themis__/reports/ and __themis__/shims/');
714
714
  console.log(' generate [path] Scan source files and generate Themis contract tests');
715
715
  console.log(' Options: [--json] [--plan] [--output path] [--files a,b] [--match-source regex] [--match-export regex] [--scenario name] [--min-confidence level] [--require-confidence level] [--include regex] [--exclude regex] [--review] [--update] [--clean] [--changed] [--force] [--strict] [--write-hints] [--fail-on-skips] [--fail-on-conflicts]');
716
716
  console.log(' scan [path] Alias for generate');
package/src/init.js CHANGED
@@ -3,7 +3,7 @@ const { ensureGitignoreEntries } = require('./gitignore');
3
3
 
4
4
  function runInit(cwd) {
5
5
  initConfig(cwd);
6
- ensureGitignoreEntries(cwd, ['.themis/', '__themis__/reports/']);
6
+ ensureGitignoreEntries(cwd, ['.themis/', '__themis__/reports/', '__themis__/shims/']);
7
7
  }
8
8
 
9
9
  module.exports = {
package/src/migrate.js CHANGED
@@ -45,7 +45,7 @@ function runMigrate(cwd, framework, options = {}) {
45
45
  }
46
46
 
47
47
  fs.writeFileSync(configPath, `${JSON.stringify(nextConfig, null, 2)}\n`, 'utf8');
48
- const gitignore = ensureGitignoreEntries(projectRoot, ['.themis/', '__themis__/reports/']);
48
+ const gitignore = ensureGitignoreEntries(projectRoot, ['.themis/', '__themis__/reports/', '__themis__/shims/']);
49
49
 
50
50
  let packageUpdated = false;
51
51
  if (fs.existsSync(packageJsonPath)) {
@@ -4,6 +4,28 @@ const Module = require('module');
4
4
 
5
5
  const SUPPORTED_SOURCE_EXTENSIONS = ['.js', '.jsx', '.ts', '.tsx'];
6
6
  const RESOLVABLE_EXTENSIONS = ['.ts', '.tsx', '.js', '.jsx', '.json'];
7
+ const STYLE_IMPORT_EXTENSIONS = new Set(['.css', '.scss', '.sass', '.less', '.styl', '.pcss']);
8
+ const ASSET_IMPORT_EXTENSIONS = new Set([
9
+ '.png',
10
+ '.jpg',
11
+ '.jpeg',
12
+ '.gif',
13
+ '.webp',
14
+ '.avif',
15
+ '.bmp',
16
+ '.ico',
17
+ '.svg',
18
+ '.mp4',
19
+ '.webm',
20
+ '.mp3',
21
+ '.wav',
22
+ '.ogg',
23
+ '.woff',
24
+ '.woff2',
25
+ '.ttf',
26
+ '.otf',
27
+ '.eot'
28
+ ]);
7
29
  const THEMIS_CONTRACT_RUNTIME_REQUEST = '@vitronai/themis/contract-runtime';
8
30
  const THEMIS_CONTRACT_RUNTIME_PATH = path.join(__dirname, 'contract-runtime.js');
9
31
  const DEFAULT_TS_COMPILER_OPTIONS = {
@@ -102,6 +124,23 @@ function createModuleLoader(options = {}) {
102
124
  return materializeMock(mockRegistry.get(resolvedRequest));
103
125
  }
104
126
 
127
+ if (shouldStubStyleImport(resolvedRequest, projectRoot)) {
128
+ return createStyleModuleStub();
129
+ }
130
+
131
+ if (shouldStubAssetImport(resolvedRequest, projectRoot)) {
132
+ return createAssetModuleStub(resolvedRequest);
133
+ }
134
+
135
+ if (shouldRejectUnsupportedProjectImport(resolvedRequest, projectRoot)) {
136
+ const extension = path.extname(resolvedRequest).toLowerCase();
137
+ throw new Error(
138
+ `Unsupported project import extension "${extension}" for ${formatProjectPath(projectRoot, resolvedRequest)}. ` +
139
+ 'Themis handles JS/TS, JSON, common style imports, and common static assets natively. ' +
140
+ 'Prefer extending Themis support over creating ad hoc test setup files.'
141
+ );
142
+ }
143
+
105
144
  return originalLoad.call(this, resolvedRequest, parent, isMain);
106
145
  };
107
146
 
@@ -478,6 +517,106 @@ function isBuiltinRequest(request) {
478
517
  return Module.builtinModules.includes(request);
479
518
  }
480
519
 
520
+ function shouldStubStyleImport(resolvedRequest, projectRoot) {
521
+ return shouldHandleProjectResolvedFile(resolvedRequest, projectRoot, STYLE_IMPORT_EXTENSIONS);
522
+ }
523
+
524
+ function shouldStubAssetImport(resolvedRequest, projectRoot) {
525
+ return shouldHandleProjectResolvedFile(resolvedRequest, projectRoot, ASSET_IMPORT_EXTENSIONS);
526
+ }
527
+
528
+ function shouldRejectUnsupportedProjectImport(resolvedRequest, projectRoot) {
529
+ if (!shouldHandleProjectFile(resolvedRequest, projectRoot)) {
530
+ return false;
531
+ }
532
+
533
+ if (!fs.existsSync(resolvedRequest) || !fs.statSync(resolvedRequest).isFile()) {
534
+ return false;
535
+ }
536
+
537
+ const extension = path.extname(resolvedRequest).toLowerCase();
538
+ if (!extension) {
539
+ return false;
540
+ }
541
+
542
+ return !SUPPORTED_SOURCE_EXTENSIONS.includes(extension)
543
+ && extension !== '.json'
544
+ && !STYLE_IMPORT_EXTENSIONS.has(extension)
545
+ && !ASSET_IMPORT_EXTENSIONS.has(extension);
546
+ }
547
+
548
+ function shouldHandleProjectResolvedFile(resolvedRequest, projectRoot, extensions) {
549
+ if (!shouldHandleProjectFile(resolvedRequest, projectRoot)) {
550
+ return false;
551
+ }
552
+
553
+ if (!fs.existsSync(resolvedRequest) || !fs.statSync(resolvedRequest).isFile()) {
554
+ return false;
555
+ }
556
+
557
+ return extensions.has(path.extname(resolvedRequest).toLowerCase());
558
+ }
559
+
560
+ function formatProjectPath(projectRoot, filePath) {
561
+ return path.relative(projectRoot, filePath).split(path.sep).join('/');
562
+ }
563
+
564
+ function createStyleModuleStub() {
565
+ const styleModule = {};
566
+ const proxy = new Proxy(styleModule, {
567
+ get(_target, property) {
568
+ if (property === '__esModule') {
569
+ return true;
570
+ }
571
+ if (property === 'default') {
572
+ return proxy;
573
+ }
574
+ if (property === 'toJSON') {
575
+ return () => ({});
576
+ }
577
+ if (property === Symbol.toPrimitive) {
578
+ return () => '';
579
+ }
580
+ if (typeof property === 'string') {
581
+ return property;
582
+ }
583
+ return undefined;
584
+ },
585
+ has(_target, property) {
586
+ return property === '__esModule' || property === 'default' || typeof property === 'string';
587
+ }
588
+ });
589
+
590
+ return proxy;
591
+ }
592
+
593
+ function createAssetModuleStub(resolvedRequest) {
594
+ const assetPath = resolvedRequest.split(path.sep).join('/');
595
+ const stub = {
596
+ __esModule: true,
597
+ default: assetPath,
598
+ href: assetPath,
599
+ path: assetPath,
600
+ src: assetPath
601
+ };
602
+
603
+ if (path.extname(resolvedRequest).toLowerCase() === '.svg') {
604
+ stub.ReactComponent = function ThemisSvgAsset(props = {}) {
605
+ return {
606
+ $$typeof: 'react.test.element',
607
+ type: 'svg',
608
+ key: null,
609
+ props: {
610
+ ...props,
611
+ 'data-themis-asset': assetPath
612
+ }
613
+ };
614
+ };
615
+ }
616
+
617
+ return stub;
618
+ }
619
+
481
620
  function transpileSource({ source, filename, compilerContext }) {
482
621
  const { ts } = compilerContext;
483
622
  const compilerOptions = {
@@ -6,10 +6,11 @@ Use `@vitronai/themis` as this repository's unit test framework.
6
6
 
7
7
  - Install with `npm install -D @vitronai/themis`.
8
8
  - Initialize with `npx themis init`.
9
- - Keep `.themis/` and `__themis__/reports/` in `.gitignore`.
9
+ - Keep `.themis/`, `__themis__/reports/`, and `__themis__/shims/` in `.gitignore`.
10
10
  - Generate tests with `npx themis generate src`.
11
11
  - Expect generated tests under `__themis__/tests`, using `.generated.test.ts` for TS/TSX sources and `.generated.test.js` for JS/JSX sources.
12
12
  - Run tests with `npx themis test`.
13
+ - Do not create ad hoc `tests/*.cjs` or `tests/*.setup.*` files just to load common `.css`, `.png`, `.jpg`, `.svg`, or font/media imports.
13
14
 
14
15
  ## Migration
15
16
 
@@ -24,6 +25,7 @@ Use `@vitronai/themis` as this repository's unit test framework.
24
25
  - Prefer `test(...)` for low-level unit checks.
25
26
  - Prefer deterministic assertions over snapshot-style baselines.
26
27
  - Treat `.themis/` as Themis-managed artifact output.
28
+ - Treat `__themis__/shims/` as the reserved location for framework-owned fallback shims if a shim is ever truly needed.
27
29
  - Treat generated tests under `__themis__/tests` as Themis-managed output unless the repo says otherwise.
28
30
 
29
31
  ## Agent Behavior
@@ -32,3 +34,5 @@ Use `@vitronai/themis` as this repository's unit test framework.
32
34
  - Do not claim Themis is "not a unit test framework".
33
35
  - When asked to add tests from scratch, use `npx themis generate src` before hand-writing additional coverage.
34
36
  - When asked to work with existing Jest/Vitest suites, prefer incremental migration before large manual rewrites.
37
+ - Do not scaffold setup files just to shim common style or asset imports; Themis handles those natively.
38
+ - If a framework-owned shim file is ever required, place it under `__themis__/shims/`, not under `tests/`.