about summary refs log tree commit diff stats
path: root/tree-sitter/dsk/dsk-cli/src/commands/test.ts
diff options
context:
space:
mode:
Diffstat (limited to 'tree-sitter/dsk/dsk-cli/src/commands/test.ts')
-rw-r--r--tree-sitter/dsk/dsk-cli/src/commands/test.ts50
1 files changed, 50 insertions, 0 deletions
diff --git a/tree-sitter/dsk/dsk-cli/src/commands/test.ts b/tree-sitter/dsk/dsk-cli/src/commands/test.ts
new file mode 100644
index 0000000..694acc7
--- /dev/null
+++ b/tree-sitter/dsk/dsk-cli/src/commands/test.ts
@@ -0,0 +1,50 @@
+/**
+ * Test Command - Wrapper around `tree-sitter test`
+ *
+ * Streams test output directly to the console.
+ */
+
+import { Command } from 'commander';
+import { execa } from 'execa';
+import chalk from 'chalk';
+import { existsSync } from 'fs';
+
+/**
+ * Create the test command
+ */
+export function createTestCommand(): Command {
+  const testCommand = new Command('test');
+
+  testCommand
+    .description('Run tree-sitter tests and stream output')
+    .allowExcessArguments(true)
+    .option('-u, --update', 'Update expected outputs (snapshots)')
+    .option('-f, --filter <regex>', 'Only run tests whose descriptions match the regex')
+    .option('--cwd <dir>', 'Run tests with a different working directory')
+    .option('-v, --verbose', 'Show verbose output (passes through to tree-sitter)')
+    .argument('[patterns...]', 'Optional test patterns (filenames or test names)')
+    .action(async (patterns: string[], options) => {
+      if (!existsSync('grammar.js')) {
+        console.error(chalk.red('โŒ No grammar.js found. Are you in a DSL project directory?'));
+        process.exit(1);
+      }
+
+      try {
+        console.log(chalk.blue('๐Ÿงช Running tests...'));
+        const args = ['test'];
+        if (options.update) args.push('-u');
+        if (options.filter) args.push('-f', String(options.filter));
+        if (options.verbose) args.push('--verbose');
+        args.push(...patterns);
+        await execa('tree-sitter', args, { stdio: 'inherit', cwd: options.cwd || process.cwd() });
+      } catch (error: any) {
+        const message = error?.message || error || 'Unknown error';
+        console.error(chalk.red('โŒ Tests failed:'), message);
+        process.exit(1);
+      }
+    });
+
+  return testCommand;
+}
+
+