Skip to content

Commit 23c3a63

Browse files
committed
feat: snapshot
1 parent 40922c0 commit 23c3a63

2 files changed

Lines changed: 22 additions & 16 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "regressify",
3-
"version": "1.8.6",
3+
"version": "1.8.7",
44
"description": "Visual regression tests support",
55
"main": "src/index.ts",
66
"type": "module",

src/snapshot.ts

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,24 @@ import { Config } from 'backstopjs';
44
import chalk from 'chalk';
55
import { BackstopReport, HtmlReportSummary } from './types';
66

7-
async function processTestSuite(backstopDir: string, config: Config) {
7+
async function processTestSuite(backstopDir: string, config: Config): HtmlReportSummary | null {
88
const testDir = path.join(backstopDir, config.id);
99
if (!fs.existsSync(testDir)) {
1010
console.log(chalk.red(`Test directory does not exist: ${testDir}`));
11-
return;
11+
return null;
1212
}
1313

1414
const htmlReportDir = path.join(testDir, 'html_report');
1515
const bitmapTestDir = path.join(testDir, 'bitmaps_test');
1616

1717
if (!fs.existsSync(htmlReportDir)) {
18-
return;
18+
return null;
1919
}
2020

2121
const configPath = path.join(htmlReportDir, 'config.js');
2222

2323
if (!fs.existsSync(configPath)) {
24-
return;
24+
return null;
2525
}
2626

2727
const configText = fs.readFileSync(configPath, 'utf-8');
@@ -31,9 +31,7 @@ async function processTestSuite(backstopDir: string, config: Config) {
3131
.filter((dirent) => dirent.isDirectory())
3232
.map((dirent) => dirent.name);
3333

34-
const htmlReportSummary: HtmlReportSummary[] = [];
35-
36-
subDirs.forEach((subDir) => {
34+
for (const subDir of subDirs) {
3735
const subDirFullPath = path.join(bitmapTestDir, subDir);
3836

3937
if (!configText.includes(`bitmaps_test/${subDir}`) && !configText.includes(`bitmaps_test\\\\${subDir}`)) {
@@ -48,18 +46,20 @@ async function processTestSuite(backstopDir: string, config: Config) {
4846
const report = JSON.parse(reportText) as BackstopReport;
4947
const passCount = report?.tests?.filter((t) => t.status === 'pass').length ?? 0;
5048
const failCount = report?.tests?.filter((t) => t.status === 'fail').length ?? 0;
51-
htmlReportSummary.push({
49+
50+
console.log(chalk.green(`Snapshot directory: ${subDir}, Passed: ${passCount}, Failed: ${failCount}`));
51+
52+
return {
5253
id: report.id,
5354
totalTests: report.tests.length,
5455
totalPassed: passCount,
5556
totalFailed: failCount,
56-
});
57-
console.log(chalk.green(`Snapshot directory: ${subDir}, Passed: ${passCount}, Failed: ${failCount}`));
57+
};
5858
}
5959
}
60-
});
60+
}
6161

62-
generateHtmlReportSummary(backstopDir, htmlReportSummary);
62+
return null;
6363
}
6464

6565
const generateHtmlReportSummary = (backstopDir: string, summaries: HtmlReportSummary[]) => {
@@ -126,7 +126,7 @@ const generateHtmlReportSummary = (backstopDir: string, summaries: HtmlReportSum
126126
`;
127127
let html = '';
128128

129-
summaries.forEach((summary) => {
129+
for (const summary of summaries) {
130130
const successClass = summary.totalPassed === summary.totalTests ? 'class="success"' : '';
131131
const dangerClass = summary.totalFailed > 0 ? 'class="danger"' : '';
132132

@@ -136,7 +136,7 @@ const generateHtmlReportSummary = (backstopDir: string, summaries: HtmlReportSum
136136
html += `<td ${successClass}>${summary.totalPassed}</td>`;
137137
html += `<td ${dangerClass}>${summary.totalFailed}</td>`;
138138
html += `</tr>`;
139-
});
139+
}
140140

141141
const finalHtml = htmlTemplate.replace('<!-- PLACEHOLDER -->', html);
142142

@@ -152,5 +152,11 @@ export async function snapshot({ configs, backstopDirName }: { configs: Config[]
152152
return;
153153
}
154154

155-
configs.forEach((config) => processTestSuite(backstopDir, config));
155+
const htmlReportSummary: HtmlReportSummary[] = [];
156+
157+
for (const config of configs) {
158+
processTestSuite(backstopDir, config);
159+
}
160+
161+
generateHtmlReportSummary(backstopDir, htmlReportSummary);
156162
}

0 commit comments

Comments
 (0)