tryscript 0.0.1 → 0.1.1

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/dist/index.d.cts CHANGED
@@ -2,20 +2,48 @@
2
2
  import { z } from "zod";
3
3
 
4
4
  //#region src/lib/types.d.ts
5
+
5
6
  declare const TestConfigSchema: z.ZodObject<{
6
- bin: z.ZodOptional<z.ZodString>;
7
+ cwd: z.ZodOptional<z.ZodString>;
8
+ sandbox: z.ZodOptional<z.ZodUnion<[z.ZodBoolean, z.ZodString]>>;
9
+ fixtures: z.ZodOptional<z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodObject<{
10
+ source: z.ZodString;
11
+ dest: z.ZodOptional<z.ZodString>;
12
+ }, "strip", z.ZodTypeAny, {
13
+ source: string;
14
+ dest?: string | undefined;
15
+ }, {
16
+ source: string;
17
+ dest?: string | undefined;
18
+ }>]>, "many">>;
19
+ before: z.ZodOptional<z.ZodString>;
20
+ after: z.ZodOptional<z.ZodString>;
7
21
  env: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
8
22
  timeout: z.ZodOptional<z.ZodNumber>;
9
23
  patterns: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodString, z.ZodType<RegExp, z.ZodTypeDef, RegExp>]>>>;
10
24
  tests: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
11
25
  }, "strip", z.ZodTypeAny, {
12
- bin?: string | undefined;
26
+ cwd?: string | undefined;
27
+ sandbox?: string | boolean | undefined;
28
+ fixtures?: (string | {
29
+ source: string;
30
+ dest?: string | undefined;
31
+ })[] | undefined;
32
+ before?: string | undefined;
33
+ after?: string | undefined;
13
34
  env?: Record<string, string> | undefined;
14
35
  timeout?: number | undefined;
15
36
  patterns?: Record<string, string | RegExp> | undefined;
16
37
  tests?: string[] | undefined;
17
38
  }, {
18
- bin?: string | undefined;
39
+ cwd?: string | undefined;
40
+ sandbox?: string | boolean | undefined;
41
+ fixtures?: (string | {
42
+ source: string;
43
+ dest?: string | undefined;
44
+ })[] | undefined;
45
+ before?: string | undefined;
46
+ after?: string | undefined;
19
47
  env?: Record<string, string> | undefined;
20
48
  timeout?: number | undefined;
21
49
  patterns?: Record<string, string | RegExp> | undefined;
@@ -35,12 +63,18 @@ interface TestBlock {
35
63
  command: string;
36
64
  /** Expected output (may include elision patterns) */
37
65
  expectedOutput: string;
66
+ /** Expected stderr output (lines starting with ! in expected output) */
67
+ expectedStderr?: string;
38
68
  /** Expected exit code (default: 0) */
39
69
  expectedExitCode: number;
40
70
  /** Line number where this block starts (1-indexed, for error reporting) */
41
71
  lineNumber: number;
42
72
  /** Raw content of the block for update mode */
43
73
  rawContent: string;
74
+ /** Skip this test (from <!-- skip --> annotation) */
75
+ skip?: boolean;
76
+ /** Run only this test (from <!-- only --> annotation) */
77
+ only?: boolean;
44
78
  }
45
79
  /**
46
80
  * A parsed test file with all its blocks.
@@ -62,6 +96,10 @@ interface TestBlockResult {
62
96
  block: TestBlock;
63
97
  passed: boolean;
64
98
  actualOutput: string;
99
+ /** Separate stdout (when stderr is captured separately) */
100
+ actualStdout?: string;
101
+ /** Separate stderr (when stderr is captured separately) */
102
+ actualStderr?: string;
65
103
  actualExitCode: number;
66
104
  /** Diff if test failed (unified diff format) */
67
105
  diff?: string;
@@ -69,6 +107,8 @@ interface TestBlockResult {
69
107
  duration: number;
70
108
  /** Error message if execution failed */
71
109
  error?: string;
110
+ /** Test was skipped */
111
+ skipped?: boolean;
72
112
  }
73
113
  /**
74
114
  * Result of running all blocks in a test file.
@@ -90,14 +130,68 @@ interface TestRunSummary {
90
130
  totalBlocks: number;
91
131
  duration: number;
92
132
  }
133
+ /**
134
+ * Schema for coverage configuration.
135
+ */
136
+ declare const CoverageConfigSchema: z.ZodObject<{
137
+ /** Output directory for coverage reports (default: 'coverage-tryscript') */
138
+ reportsDir: z.ZodOptional<z.ZodString>;
139
+ /** Coverage reporters to use (default: ['text', 'html']) */
140
+ reporters: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
141
+ /** File patterns to include in coverage (default: ['dist/**']) */
142
+ include: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
143
+ /** Source directory for sourcemap mapping (default: 'src') */
144
+ src: z.ZodOptional<z.ZodString>;
145
+ }, "strip", z.ZodTypeAny, {
146
+ reportsDir?: string | undefined;
147
+ reporters?: string[] | undefined;
148
+ include?: string[] | undefined;
149
+ src?: string | undefined;
150
+ }, {
151
+ reportsDir?: string | undefined;
152
+ reporters?: string[] | undefined;
153
+ include?: string[] | undefined;
154
+ src?: string | undefined;
155
+ }>;
156
+ /**
157
+ * Coverage configuration options.
158
+ */
159
+ type CoverageConfig = z.infer<typeof CoverageConfigSchema>;
160
+ /**
161
+ * Runtime context for coverage collection during test execution.
162
+ */
163
+ interface CoverageContext {
164
+ /** Temporary directory for V8 coverage data files */
165
+ tempDir: string;
166
+ /** Resolved coverage options with defaults applied */
167
+ options: Required<CoverageConfig>;
168
+ }
93
169
  //#endregion
94
170
  //#region src/lib/config.d.ts
171
+ /** Fixture configuration for copying files to sandbox directory */
172
+ interface Fixture {
173
+ /** Source path (resolved relative to test file) */
174
+ source: string;
175
+ /** Destination path (resolved relative to sandbox dir) */
176
+ dest?: string;
177
+ }
95
178
  interface TryscriptConfig {
96
- bin?: string;
179
+ /** Working directory for commands (default: test file directory) */
180
+ cwd?: string;
181
+ /** Run in isolated sandbox: true = empty temp, path = copy to temp */
182
+ sandbox?: boolean | string;
183
+ /** Fixtures to copy to sandbox directory before tests */
184
+ fixtures?: (string | Fixture)[];
185
+ /** Script to run before first test block */
186
+ before?: string;
187
+ /** Script to run after all test blocks */
188
+ after?: string;
97
189
  env?: Record<string, string>;
98
190
  timeout?: number;
99
191
  patterns?: Record<string, RegExp | string>;
100
192
  tests?: string[];
193
+ /** Coverage configuration (used with --coverage flag) */
194
+ coverage?: CoverageConfig;
101
195
  }
102
196
  /**
103
197
  * Helper for typed config files.
@@ -113,24 +207,35 @@ declare function parseTestFile(content: string, filePath: string): TestFile;
113
207
  //#region src/lib/runner.d.ts
114
208
  /**
115
209
  * Execution context for a test file.
116
- * Created once per file, contains the temp directory.
210
+ * Created once per file, contains directory paths and config.
117
211
  */
118
212
  interface ExecutionContext {
119
213
  /** Temporary directory for this test file (resolved, no symlinks) */
120
214
  tempDir: string;
121
- /** Directory containing the test file (for portable test commands) */
215
+ /** Directory containing the test file */
122
216
  testDir: string;
123
- /** Resolved binary path */
124
- binPath: string;
217
+ /** Working directory for command execution */
218
+ cwd: string;
219
+ /** Whether running in sandbox mode */
220
+ sandbox: boolean;
125
221
  /** Environment variables */
126
222
  env: Record<string, string>;
127
223
  /** Timeout per command */
128
224
  timeout: number;
225
+ /** Before hook script */
226
+ before?: string;
227
+ /** After hook script */
228
+ after?: string;
229
+ /** Whether before hook has been run */
230
+ beforeRan?: boolean;
129
231
  }
130
232
  /**
131
233
  * Create an execution context for a test file.
234
+ * @param config - Test configuration
235
+ * @param testFilePath - Path to the test file
236
+ * @param coverageEnv - Optional coverage environment variables (e.g., NODE_V8_COVERAGE)
132
237
  */
133
- declare function createExecutionContext(config: TryscriptConfig, testFilePath: string): Promise<ExecutionContext>;
238
+ declare function createExecutionContext(config: TryscriptConfig, testFilePath: string, coverageEnv?: Record<string, string>): Promise<ExecutionContext>;
134
239
  /**
135
240
  * Clean up execution context (remove temp directory).
136
241
  */
@@ -161,5 +266,5 @@ declare function matchOutput(actual: string, expected: string, context: {
161
266
  //#region src/index.d.ts
162
267
  declare const VERSION: string;
163
268
  //#endregion
164
- export { type ExecutionContext, type TestBlock, type TestBlockResult, type TestConfig, type TestFile, type TestFileResult, type TestRunSummary, type TryscriptConfig, VERSION, cleanupExecutionContext, createExecutionContext, defineConfig, matchOutput, normalizeOutput, parseTestFile, runBlock };
269
+ export { type CoverageConfig, type CoverageContext, type ExecutionContext, type TestBlock, type TestBlockResult, type TestConfig, type TestFile, type TestFileResult, type TestRunSummary, type TryscriptConfig, VERSION, cleanupExecutionContext, createExecutionContext, defineConfig, matchOutput, normalizeOutput, parseTestFile, runBlock };
165
270
  //# sourceMappingURL=index.d.cts.map
package/dist/index.d.mts CHANGED
@@ -2,20 +2,48 @@
2
2
  import { z } from "zod";
3
3
 
4
4
  //#region src/lib/types.d.ts
5
+
5
6
  declare const TestConfigSchema: z.ZodObject<{
6
- bin: z.ZodOptional<z.ZodString>;
7
+ cwd: z.ZodOptional<z.ZodString>;
8
+ sandbox: z.ZodOptional<z.ZodUnion<[z.ZodBoolean, z.ZodString]>>;
9
+ fixtures: z.ZodOptional<z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodObject<{
10
+ source: z.ZodString;
11
+ dest: z.ZodOptional<z.ZodString>;
12
+ }, "strip", z.ZodTypeAny, {
13
+ source: string;
14
+ dest?: string | undefined;
15
+ }, {
16
+ source: string;
17
+ dest?: string | undefined;
18
+ }>]>, "many">>;
19
+ before: z.ZodOptional<z.ZodString>;
20
+ after: z.ZodOptional<z.ZodString>;
7
21
  env: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
8
22
  timeout: z.ZodOptional<z.ZodNumber>;
9
23
  patterns: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodString, z.ZodType<RegExp, z.ZodTypeDef, RegExp>]>>>;
10
24
  tests: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
11
25
  }, "strip", z.ZodTypeAny, {
12
- bin?: string | undefined;
26
+ cwd?: string | undefined;
27
+ sandbox?: string | boolean | undefined;
28
+ fixtures?: (string | {
29
+ source: string;
30
+ dest?: string | undefined;
31
+ })[] | undefined;
32
+ before?: string | undefined;
33
+ after?: string | undefined;
13
34
  env?: Record<string, string> | undefined;
14
35
  timeout?: number | undefined;
15
36
  patterns?: Record<string, string | RegExp> | undefined;
16
37
  tests?: string[] | undefined;
17
38
  }, {
18
- bin?: string | undefined;
39
+ cwd?: string | undefined;
40
+ sandbox?: string | boolean | undefined;
41
+ fixtures?: (string | {
42
+ source: string;
43
+ dest?: string | undefined;
44
+ })[] | undefined;
45
+ before?: string | undefined;
46
+ after?: string | undefined;
19
47
  env?: Record<string, string> | undefined;
20
48
  timeout?: number | undefined;
21
49
  patterns?: Record<string, string | RegExp> | undefined;
@@ -35,12 +63,18 @@ interface TestBlock {
35
63
  command: string;
36
64
  /** Expected output (may include elision patterns) */
37
65
  expectedOutput: string;
66
+ /** Expected stderr output (lines starting with ! in expected output) */
67
+ expectedStderr?: string;
38
68
  /** Expected exit code (default: 0) */
39
69
  expectedExitCode: number;
40
70
  /** Line number where this block starts (1-indexed, for error reporting) */
41
71
  lineNumber: number;
42
72
  /** Raw content of the block for update mode */
43
73
  rawContent: string;
74
+ /** Skip this test (from <!-- skip --> annotation) */
75
+ skip?: boolean;
76
+ /** Run only this test (from <!-- only --> annotation) */
77
+ only?: boolean;
44
78
  }
45
79
  /**
46
80
  * A parsed test file with all its blocks.
@@ -62,6 +96,10 @@ interface TestBlockResult {
62
96
  block: TestBlock;
63
97
  passed: boolean;
64
98
  actualOutput: string;
99
+ /** Separate stdout (when stderr is captured separately) */
100
+ actualStdout?: string;
101
+ /** Separate stderr (when stderr is captured separately) */
102
+ actualStderr?: string;
65
103
  actualExitCode: number;
66
104
  /** Diff if test failed (unified diff format) */
67
105
  diff?: string;
@@ -69,6 +107,8 @@ interface TestBlockResult {
69
107
  duration: number;
70
108
  /** Error message if execution failed */
71
109
  error?: string;
110
+ /** Test was skipped */
111
+ skipped?: boolean;
72
112
  }
73
113
  /**
74
114
  * Result of running all blocks in a test file.
@@ -90,14 +130,68 @@ interface TestRunSummary {
90
130
  totalBlocks: number;
91
131
  duration: number;
92
132
  }
133
+ /**
134
+ * Schema for coverage configuration.
135
+ */
136
+ declare const CoverageConfigSchema: z.ZodObject<{
137
+ /** Output directory for coverage reports (default: 'coverage-tryscript') */
138
+ reportsDir: z.ZodOptional<z.ZodString>;
139
+ /** Coverage reporters to use (default: ['text', 'html']) */
140
+ reporters: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
141
+ /** File patterns to include in coverage (default: ['dist/**']) */
142
+ include: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
143
+ /** Source directory for sourcemap mapping (default: 'src') */
144
+ src: z.ZodOptional<z.ZodString>;
145
+ }, "strip", z.ZodTypeAny, {
146
+ reportsDir?: string | undefined;
147
+ reporters?: string[] | undefined;
148
+ include?: string[] | undefined;
149
+ src?: string | undefined;
150
+ }, {
151
+ reportsDir?: string | undefined;
152
+ reporters?: string[] | undefined;
153
+ include?: string[] | undefined;
154
+ src?: string | undefined;
155
+ }>;
156
+ /**
157
+ * Coverage configuration options.
158
+ */
159
+ type CoverageConfig = z.infer<typeof CoverageConfigSchema>;
160
+ /**
161
+ * Runtime context for coverage collection during test execution.
162
+ */
163
+ interface CoverageContext {
164
+ /** Temporary directory for V8 coverage data files */
165
+ tempDir: string;
166
+ /** Resolved coverage options with defaults applied */
167
+ options: Required<CoverageConfig>;
168
+ }
93
169
  //#endregion
94
170
  //#region src/lib/config.d.ts
171
+ /** Fixture configuration for copying files to sandbox directory */
172
+ interface Fixture {
173
+ /** Source path (resolved relative to test file) */
174
+ source: string;
175
+ /** Destination path (resolved relative to sandbox dir) */
176
+ dest?: string;
177
+ }
95
178
  interface TryscriptConfig {
96
- bin?: string;
179
+ /** Working directory for commands (default: test file directory) */
180
+ cwd?: string;
181
+ /** Run in isolated sandbox: true = empty temp, path = copy to temp */
182
+ sandbox?: boolean | string;
183
+ /** Fixtures to copy to sandbox directory before tests */
184
+ fixtures?: (string | Fixture)[];
185
+ /** Script to run before first test block */
186
+ before?: string;
187
+ /** Script to run after all test blocks */
188
+ after?: string;
97
189
  env?: Record<string, string>;
98
190
  timeout?: number;
99
191
  patterns?: Record<string, RegExp | string>;
100
192
  tests?: string[];
193
+ /** Coverage configuration (used with --coverage flag) */
194
+ coverage?: CoverageConfig;
101
195
  }
102
196
  /**
103
197
  * Helper for typed config files.
@@ -113,24 +207,35 @@ declare function parseTestFile(content: string, filePath: string): TestFile;
113
207
  //#region src/lib/runner.d.ts
114
208
  /**
115
209
  * Execution context for a test file.
116
- * Created once per file, contains the temp directory.
210
+ * Created once per file, contains directory paths and config.
117
211
  */
118
212
  interface ExecutionContext {
119
213
  /** Temporary directory for this test file (resolved, no symlinks) */
120
214
  tempDir: string;
121
- /** Directory containing the test file (for portable test commands) */
215
+ /** Directory containing the test file */
122
216
  testDir: string;
123
- /** Resolved binary path */
124
- binPath: string;
217
+ /** Working directory for command execution */
218
+ cwd: string;
219
+ /** Whether running in sandbox mode */
220
+ sandbox: boolean;
125
221
  /** Environment variables */
126
222
  env: Record<string, string>;
127
223
  /** Timeout per command */
128
224
  timeout: number;
225
+ /** Before hook script */
226
+ before?: string;
227
+ /** After hook script */
228
+ after?: string;
229
+ /** Whether before hook has been run */
230
+ beforeRan?: boolean;
129
231
  }
130
232
  /**
131
233
  * Create an execution context for a test file.
234
+ * @param config - Test configuration
235
+ * @param testFilePath - Path to the test file
236
+ * @param coverageEnv - Optional coverage environment variables (e.g., NODE_V8_COVERAGE)
132
237
  */
133
- declare function createExecutionContext(config: TryscriptConfig, testFilePath: string): Promise<ExecutionContext>;
238
+ declare function createExecutionContext(config: TryscriptConfig, testFilePath: string, coverageEnv?: Record<string, string>): Promise<ExecutionContext>;
134
239
  /**
135
240
  * Clean up execution context (remove temp directory).
136
241
  */
@@ -161,5 +266,5 @@ declare function matchOutput(actual: string, expected: string, context: {
161
266
  //#region src/index.d.ts
162
267
  declare const VERSION: string;
163
268
  //#endregion
164
- export { type ExecutionContext, type TestBlock, type TestBlockResult, type TestConfig, type TestFile, type TestFileResult, type TestRunSummary, type TryscriptConfig, VERSION, cleanupExecutionContext, createExecutionContext, defineConfig, matchOutput, normalizeOutput, parseTestFile, runBlock };
269
+ export { type CoverageConfig, type CoverageContext, type ExecutionContext, type TestBlock, type TestBlockResult, type TestConfig, type TestFile, type TestFileResult, type TestRunSummary, type TryscriptConfig, VERSION, cleanupExecutionContext, createExecutionContext, defineConfig, matchOutput, normalizeOutput, parseTestFile, runBlock };
165
270
  //# sourceMappingURL=index.d.mts.map
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
1
 
2
- import { a as createExecutionContext, c as defineConfig, i as cleanupExecutionContext, n as matchOutput, o as runBlock, r as normalizeOutput, s as parseTestFile, t as VERSION } from "./src-UjaSQrqA.mjs";
2
+ import { a as createExecutionContext, c as parseTestFile, i as cleanupExecutionContext, l as defineConfig, n as matchOutput, r as normalizeOutput, s as runBlock, t as VERSION } from "./src-CndHSuTT.mjs";
3
3
 
4
4
  export { VERSION, cleanupExecutionContext, createExecutionContext, defineConfig, matchOutput, normalizeOutput, parseTestFile, runBlock };