@testsmith/testblocks 0.8.4 → 0.8.5

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.
Files changed (2) hide show
  1. package/dist/cli/index.js +74 -46
  2. package/package.json +1 -1
package/dist/cli/index.js CHANGED
@@ -280,52 +280,60 @@ program
280
280
  // Run tests
281
281
  const allResults = [];
282
282
  let hasFailures = false;
283
- for (const file of files) {
284
- // Skip _hooks.testblocks.json files - these are folder hooks, not test files
285
- const basename = path.basename(file);
286
- if (basename === '_hooks.testblocks.json') {
287
- continue;
288
- }
289
- console.log(`Running: ${basename}`);
290
- const content = fs.readFileSync(file, 'utf-8');
291
- let testFile = JSON.parse(content);
292
- // Skip files that have no tests array (e.g., hooks-only files)
293
- if (!testFile.tests || !Array.isArray(testFile.tests)) {
294
- console.log(' (no tests in file)\n');
295
- continue;
296
- }
297
- // Load and merge folder hooks
298
- const globalsDir = fs.existsSync(globalsPath) ? path.dirname(globalsPath) : null;
299
- const folderHooks = loadFolderHooks(file, globalsDir);
300
- if (folderHooks.length > 0) {
301
- testFile = mergeFolderHooksIntoTestFile(testFile, folderHooks);
302
- }
303
- // Apply filter if specified
304
- if (options.filter) {
305
- const filterRegex = new RegExp(options.filter, 'i');
306
- testFile.tests = testFile.tests.filter(t => filterRegex.test(t.name));
307
- }
308
- if (testFile.tests.length === 0) {
309
- console.log(' (no tests match filter)\n');
310
- continue;
311
- }
312
- const executor = new executor_1.TestExecutor(executorOptions);
313
- const results = await executor.runTestFile(testFile);
314
- allResults.push({ file, results });
315
- // Report results to all reporters
316
- reporters.forEach(r => r.onTestFileComplete(file, testFile, results));
317
- // Check for failures
318
- const failed = results.some(r => r.status !== 'passed');
319
- if (failed) {
320
- hasFailures = true;
321
- if (options.failFast) {
322
- console.log('\nStopping due to --fail-fast\n');
323
- break;
283
+ try {
284
+ for (const file of files) {
285
+ // Skip _hooks.testblocks.json files - these are folder hooks, not test files
286
+ const basename = path.basename(file);
287
+ if (basename === '_hooks.testblocks.json') {
288
+ continue;
289
+ }
290
+ console.log(`Running: ${basename}`);
291
+ const content = fs.readFileSync(file, 'utf-8');
292
+ let testFile = JSON.parse(content);
293
+ // Skip files that have no tests array (e.g., hooks-only files)
294
+ if (!testFile.tests || !Array.isArray(testFile.tests)) {
295
+ console.log(' (no tests in file)\n');
296
+ continue;
297
+ }
298
+ // Load and merge folder hooks
299
+ const globalsDir = fs.existsSync(globalsPath) ? path.dirname(globalsPath) : null;
300
+ const folderHooks = loadFolderHooks(file, globalsDir);
301
+ if (folderHooks.length > 0) {
302
+ testFile = mergeFolderHooksIntoTestFile(testFile, folderHooks);
303
+ }
304
+ // Apply filter if specified
305
+ if (options.filter) {
306
+ const filterRegex = new RegExp(options.filter, 'i');
307
+ testFile.tests = testFile.tests.filter(t => filterRegex.test(t.name));
308
+ }
309
+ if (testFile.tests.length === 0) {
310
+ console.log(' (no tests match filter)\n');
311
+ continue;
312
+ }
313
+ const executor = new executor_1.TestExecutor(executorOptions);
314
+ const results = await executor.runTestFile(testFile);
315
+ allResults.push({ file, results });
316
+ // Report results to all reporters
317
+ reporters.forEach(r => r.onTestFileComplete(file, testFile, results));
318
+ // Check for failures
319
+ const failed = results.some(r => r.status !== 'passed');
320
+ if (failed) {
321
+ hasFailures = true;
322
+ if (options.failFast) {
323
+ console.log('\nStopping due to --fail-fast\n');
324
+ break;
325
+ }
324
326
  }
325
327
  }
326
328
  }
327
- // Generate final reports
328
- reporters.forEach(r => r.onComplete(allResults));
329
+ catch (error) {
330
+ console.error('Error during test execution:', error.message);
331
+ hasFailures = true;
332
+ }
333
+ finally {
334
+ // Always generate final reports, even on errors
335
+ reporters.forEach(r => r.onComplete(allResults));
336
+ }
329
337
  // Exit with appropriate code
330
338
  process.exit(hasFailures ? 1 : 0);
331
339
  }
@@ -435,7 +443,7 @@ program
435
443
  'test:ci': 'testblocks run tests/**/*.testblocks.json -r console,html,junit -o reports',
436
444
  },
437
445
  devDependencies: {
438
- '@testsmith/testblocks': '^0.8.4',
446
+ '@testsmith/testblocks': '^0.8.5',
439
447
  },
440
448
  };
441
449
  fs.writeFileSync(packagePath, JSON.stringify(packageJson, null, 2));
@@ -575,7 +583,7 @@ jobs:
575
583
  run: npm ci
576
584
 
577
585
  - name: Install Playwright browsers
578
- run: npx playwright install --with-deps chromium
586
+ run: npx testblocks install-browsers
579
587
 
580
588
  - name: Run tests
581
589
  run: npm run test:ci
@@ -611,10 +619,30 @@ jobs:
611
619
  console.log('Next steps:');
612
620
  console.log(' 1. cd ' + (directory === '.' ? '' : directory));
613
621
  console.log(' 2. npm install');
614
- console.log(' 3. npm test\n');
622
+ console.log(' 3. npx testblocks install-browsers');
623
+ console.log(' 4. npm test\n');
615
624
  console.log('To open the visual test editor:');
616
625
  console.log(' testblocks serve\n');
617
626
  });
627
+ program
628
+ .command('install-browsers')
629
+ .description('Install Playwright browsers for running web tests')
630
+ .option('--browser <browser>', 'Browser to install (chromium, firefox, webkit, all)', 'chromium')
631
+ .action(async (options) => {
632
+ const { execSync } = await Promise.resolve().then(() => __importStar(require('child_process')));
633
+ const browser = options.browser === 'all' ? '' : options.browser;
634
+ console.log(`Installing Playwright browser${browser ? `: ${browser}` : 's'}...`);
635
+ try {
636
+ // Use execSync to run playwright install with inherited stdio
637
+ const command = `npx playwright install${browser ? ` ${browser}` : ''} --with-deps`;
638
+ execSync(command, { stdio: 'inherit' });
639
+ console.log('\n✓ Browsers installed successfully!');
640
+ }
641
+ catch (error) {
642
+ console.error('\nFailed to install browsers:', error instanceof Error ? error.message : error);
643
+ process.exit(1);
644
+ }
645
+ });
618
646
  program
619
647
  .command('list')
620
648
  .description('List tests in test files')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@testsmith/testblocks",
3
- "version": "0.8.4",
3
+ "version": "0.8.5",
4
4
  "description": "Visual test automation tool with Blockly - API and Playwright testing",
5
5
  "author": "Roy de Kleijn",
6
6
  "license": "MIT",