@testsmith/testblocks 0.8.4 → 0.8.6
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/cli/executor.js +13 -0
- package/dist/cli/index.js +74 -46
- package/package.json +1 -1
package/dist/cli/executor.js
CHANGED
|
@@ -544,6 +544,18 @@ class TestExecutor {
|
|
|
544
544
|
stack: err.stack,
|
|
545
545
|
};
|
|
546
546
|
}
|
|
547
|
+
// Capture screenshot on failure if page is available
|
|
548
|
+
let screenshot;
|
|
549
|
+
if (status === 'failed' && this.page) {
|
|
550
|
+
try {
|
|
551
|
+
const buffer = await this.page.screenshot({ type: 'png' });
|
|
552
|
+
screenshot = `data:image/png;base64,${buffer.toString('base64')}`;
|
|
553
|
+
}
|
|
554
|
+
catch (screenshotError) {
|
|
555
|
+
// Silently ignore screenshot errors
|
|
556
|
+
console.debug('Failed to capture screenshot:', screenshotError);
|
|
557
|
+
}
|
|
558
|
+
}
|
|
547
559
|
const result = {
|
|
548
560
|
stepId: step.id,
|
|
549
561
|
stepType: step.type,
|
|
@@ -551,6 +563,7 @@ class TestExecutor {
|
|
|
551
563
|
duration: Date.now() - startTime,
|
|
552
564
|
output,
|
|
553
565
|
error,
|
|
566
|
+
screenshot,
|
|
554
567
|
};
|
|
555
568
|
for (const plugin of this.plugins.values()) {
|
|
556
569
|
if (plugin.hooks?.afterStep) {
|
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
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
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
|
-
|
|
328
|
-
|
|
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.
|
|
446
|
+
'@testsmith/testblocks': '^0.8.6',
|
|
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
|
|
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.
|
|
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')
|