@testsmith/testblocks 0.8.0 → 0.8.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.
@@ -20,8 +20,8 @@ export declare class TestExecutor {
20
20
  private requiresBrowser;
21
21
  runTestFile(testFile: TestFile): Promise<TestResult[]>;
22
22
  private createBaseContext;
23
- runTestWithData(test: TestCase, testFile: TestFile, dataSet: TestDataSet, dataIndex: number): Promise<TestResult>;
24
- runTest(test: TestCase, testFile: TestFile): Promise<TestResult>;
23
+ runTestWithData(test: TestCase, testFile: TestFile, dataSet: TestDataSet, dataIndex: number, sharedVariables?: Map<string, unknown>): Promise<TestResult>;
24
+ runTest(test: TestCase, testFile: TestFile, sharedVariables?: Map<string, unknown>): Promise<TestResult>;
25
25
  private runSteps;
26
26
  private resolveVariableDefaults;
27
27
  private registerCustomBlocksFromProcedures;
@@ -99,20 +99,20 @@ class TestExecutor {
99
99
  const steps = this.extractStepsFromBlocklyState(testFile.beforeAll);
100
100
  await this.runSteps(steps, baseContext, 'beforeAll');
101
101
  }
102
- // Run each test
102
+ // Run each test - pass baseContext variables so beforeAll state persists
103
103
  for (const test of testFile.tests) {
104
104
  // Check if test has data-driven sets
105
105
  if (test.data && test.data.length > 0) {
106
106
  // Run test for each data set
107
107
  for (let i = 0; i < test.data.length; i++) {
108
108
  const dataSet = test.data[i];
109
- const result = await this.runTestWithData(test, testFile, dataSet, i);
109
+ const result = await this.runTestWithData(test, testFile, dataSet, i, baseContext.variables);
110
110
  results.push(result);
111
111
  }
112
112
  }
113
113
  else {
114
114
  // Run test once without data
115
- const result = await this.runTest(test, testFile);
115
+ const result = await this.runTest(test, testFile, baseContext.variables);
116
116
  results.push(result);
117
117
  }
118
118
  }
@@ -141,7 +141,7 @@ class TestExecutor {
141
141
  procedures: this.procedures,
142
142
  };
143
143
  }
144
- async runTestWithData(test, testFile, dataSet, dataIndex) {
144
+ async runTestWithData(test, testFile, dataSet, dataIndex, sharedVariables) {
145
145
  const testName = dataSet.name
146
146
  ? `${test.name} [${dataSet.name}]`
147
147
  : `${test.name} [${dataIndex + 1}]`;
@@ -155,6 +155,17 @@ class TestExecutor {
155
155
  currentData: dataSet,
156
156
  dataIndex,
157
157
  };
158
+ // Merge shared variables from beforeAll (if any)
159
+ if (sharedVariables) {
160
+ for (const [key, value] of sharedVariables) {
161
+ if (!context.variables.has(key) || context.variables.get(key) === '' || context.variables.get(key) === undefined) {
162
+ context.variables.set(key, value);
163
+ }
164
+ else if (key.startsWith('__')) {
165
+ context.variables.set(key, value);
166
+ }
167
+ }
168
+ }
158
169
  // Inject data values into variables
159
170
  for (const [key, value] of Object.entries(dataSet.values)) {
160
171
  context.variables.set(key, value);
@@ -239,12 +250,25 @@ class TestExecutor {
239
250
  },
240
251
  };
241
252
  }
242
- async runTest(test, testFile) {
253
+ async runTest(test, testFile, sharedVariables) {
243
254
  console.log(` Running: ${test.name}`);
244
255
  const startedAt = new Date().toISOString();
245
256
  const startTime = Date.now();
246
257
  const stepResults = [];
247
258
  const context = this.createBaseContext(testFile.variables);
259
+ // Merge shared variables from beforeAll (if any)
260
+ if (sharedVariables) {
261
+ for (const [key, value] of sharedVariables) {
262
+ // Only copy if not already set (don't override file-level defaults)
263
+ if (!context.variables.has(key) || context.variables.get(key) === '' || context.variables.get(key) === undefined) {
264
+ context.variables.set(key, value);
265
+ }
266
+ else if (key.startsWith('__')) {
267
+ // Always copy internal state variables like __requestHeaders
268
+ context.variables.set(key, value);
269
+ }
270
+ }
271
+ }
248
272
  for (const plugin of this.plugins.values()) {
249
273
  if (plugin.hooks?.beforeTest) {
250
274
  await plugin.hooks.beforeTest(context, test);
package/dist/cli/index.js CHANGED
@@ -212,9 +212,19 @@ program
212
212
  const allResults = [];
213
213
  let hasFailures = false;
214
214
  for (const file of files) {
215
- console.log(`Running: ${path.basename(file)}`);
215
+ // Skip _hooks.testblocks.json files - these are folder hooks, not test files
216
+ const basename = path.basename(file);
217
+ if (basename === '_hooks.testblocks.json') {
218
+ continue;
219
+ }
220
+ console.log(`Running: ${basename}`);
216
221
  const content = fs.readFileSync(file, 'utf-8');
217
222
  const testFile = JSON.parse(content);
223
+ // Skip files that have no tests array (e.g., hooks-only files)
224
+ if (!testFile.tests || !Array.isArray(testFile.tests)) {
225
+ console.log(' (no tests in file)\n');
226
+ continue;
227
+ }
218
228
  // Apply filter if specified
219
229
  if (options.filter) {
220
230
  const filterRegex = new RegExp(options.filter, 'i');
@@ -266,7 +276,13 @@ program
266
276
  }
267
277
  let hasErrors = false;
268
278
  for (const file of files) {
269
- console.log(`Validating: ${path.basename(file)}`);
279
+ const basename = path.basename(file);
280
+ // Skip _hooks.testblocks.json files from validation (they're hooks, not test files)
281
+ if (basename === '_hooks.testblocks.json') {
282
+ console.log(`Skipping: ${basename} (folder hooks file)`);
283
+ continue;
284
+ }
285
+ console.log(`Validating: ${basename}`);
270
286
  try {
271
287
  const content = fs.readFileSync(file, 'utf-8');
272
288
  const testFile = JSON.parse(content);
@@ -277,7 +293,8 @@ program
277
293
  errors.forEach(err => console.log(` - ${err}`));
278
294
  }
279
295
  else {
280
- console.log(` ✓ Valid (${testFile.tests.length} tests)`);
296
+ const testCount = testFile.tests?.length || 0;
297
+ console.log(` ✓ Valid (${testCount} tests)`);
281
298
  }
282
299
  }
283
300
  catch (error) {
@@ -342,7 +359,7 @@ program
342
359
  'test:junit': 'testblocks run tests/**/*.testblocks.json -r junit -o reports',
343
360
  },
344
361
  devDependencies: {
345
- '@testsmith/testblocks': '^0.8.0',
362
+ '@testsmith/testblocks': '^0.8.1',
346
363
  },
347
364
  };
348
365
  fs.writeFileSync(packagePath, JSON.stringify(packageJson, null, 2));
@@ -522,9 +539,18 @@ program
522
539
  process.exit(1);
523
540
  }
524
541
  for (const file of files) {
525
- console.log(`\n${path.basename(file)}:`);
542
+ // Skip _hooks.testblocks.json files
543
+ const basename = path.basename(file);
544
+ if (basename === '_hooks.testblocks.json') {
545
+ continue;
546
+ }
547
+ console.log(`\n${basename}:`);
526
548
  const content = fs.readFileSync(file, 'utf-8');
527
549
  const testFile = JSON.parse(content);
550
+ if (!testFile.tests || !Array.isArray(testFile.tests)) {
551
+ console.log(' (no tests in file)');
552
+ continue;
553
+ }
528
554
  testFile.tests.forEach((test, index) => {
529
555
  const tags = test.tags?.length ? ` [${test.tags.join(', ')}]` : '';
530
556
  console.log(` ${index + 1}. ${test.name}${tags}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@testsmith/testblocks",
3
- "version": "0.8.0",
3
+ "version": "0.8.1",
4
4
  "description": "Visual test automation tool with Blockly - API and Playwright testing",
5
5
  "author": "Roy de Kleijn",
6
6
  "license": "MIT",