Skip to content

Commit

Permalink
Merge pull request #1891 from IBMa/dev-1837
Browse files Browse the repository at this point in the history
fix(extension|node|karma|cypress): Properly close the embedded browser
  • Loading branch information
tombrunet authored Apr 17, 2024
2 parents 1288cd0 + 4a371f0 commit 7195485
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 35 deletions.
54 changes: 30 additions & 24 deletions accessibility-checker/src-ts/bin/achecker.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,32 +181,38 @@ getInputFileList().then(async (rptInputFiles) => {
let idx = 0;
let failures = [];
let errors = 0;
for (let f of rptInputFiles) {
let result;
let isFile = false;
try {
isFile = fs.lstatSync(f).isFile();
f = path.resolve(f);
} catch (e) {}
if (isFile) {
result = await aChecker.getCompliance("file://"+f, f.replace(/^file:\/\//,"").replace(/[:?&=]/g,"_"));
} else {
result = await aChecker.getCompliance(f, f.replace(/^(https?:|file:)\/\//,"").replace(/[:?&=]/g,"_"));
}
if (result) {
if (aChecker.assertCompliance(result.report) === 0) {
console.log("Passed:", f);
try {
for (let f of rptInputFiles) {
let result;
let isFile = false;
try {
isFile = fs.lstatSync(f).isFile();
f = path.resolve(f);
} catch (e) {}
if (isFile) {
result = await aChecker.getCompliance("file://"+f, f.replace(/^file:\/\//,"").replace(/[:?&=]/g,"_"));
} else {
failures.push({
file: f,
report: result.report
});
console.log("Failed:", f);
result = await aChecker.getCompliance(f, f.replace(/^(https?:|file:)\/\//,"").replace(/[:?&=]/g,"_"));
}
if (result) {
if (aChecker.assertCompliance(result.report) === 0) {
console.log("Passed:", f);
} else {
failures.push({
file: f,
report: result.report
});
console.log("Failed:", f);
}
} else {
++errors;
console.log("Error:", f);
}
} else {
++errors;
console.log("Error:", f);
}
} catch (e) {
console.error(e);
} finally {
await aChecker.close();
}
if (failures.length > 0) {
console.log();
Expand All @@ -218,7 +224,7 @@ getInputFileList().then(async (rptInputFiles) => {
}
console.log();
console.log(`${rptInputFiles.length-failures.length-errors} of ${rptInputFiles.length} passed.`)
await aChecker.close();
//await aChecker.close();
if (failures.length !== 0 || errors !== 0) {
process.exitCode = 1;
}
Expand Down
74 changes: 63 additions & 11 deletions accessibility-checker/src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,69 @@ The following is how to perform an accessibility scan within your test cases and

```javascript
const aChecker = require("accessibility-checker");
// Perform the accessibility scan using the aChecker.getCompliance API
aChecker.getCompliance(testDataFileContent, testLabel).then((results) => {
const report = results.report;

// Call the aChecker.assertCompliance API which is used to compare the results with the baseline object if we can find one that
// matches the same label which was provided.
const returnCode = aChecker.assertCompliance(report);

// In the case that the violationData is not defined then trigger an error right away.
expect(returnCode).toBe(0, "Scanning " + testLabel + " failed.");
});
try {
// Perform the accessibility scan using the aChecker.getCompliance API
aChecker.getCompliance(testDataFileContent, testLabel).then((results) => {
const report = results.report;

// Call the aChecker.assertCompliance API which is used to compare the results with the baseline object if we can find one that
// matches the same label which was provided.
const returnCode = aChecker.assertCompliance(report);

// In the case that the violationData is not defined then trigger an error right away.
expect(returnCode).toBe(0, "Scanning " + testLabel + " failed.");
});
} catch (err) {
console.error(err);
} finally {
// close the engine
await aChecker.close();
};
```
Note that it's critical to close the engine, otherwise, output files for the report may not be generated properly.
If you execute batch scans, the engine should be closed after all the scans are completed for better performance. The following is a sample usage scenario:
```javascript
async batchScan(rptInputFiles) {
let failures = [];
try {
for (let f of rptInputFiles) {
let result;
let isFile = false;
try {
isFile = fs.lstatSync(f).isFile();
f = path.resolve(f);
} catch (e) {}
if (isFile) {
result = await aChecker.getCompliance("file://"+f, f.replace(/^file:\/\//,"").replace(/[:?&=]/g,"_"));
} else {
result = await aChecker.getCompliance(f, f.replace(/^(https?:|file:)\/\//,"").replace(/[:?&=]/g,"_"));
}
if (result) {
if (aChecker.assertCompliance(result.report) === 0) {
console.log("Passed:", f);
} else {
failures.push({
file: f,
report: result.report
});
console.log("Failed:", f);
}
} else {
console.log("Error:", f);
}
}
if (failures.length > 0) {
console.log("Failing scan details:");
for (const fail of failures) {
console.log(aChecker.stringifyResults(fail.report));
}
}
} catch (e) {
console.error(e);
} finally {
await aChecker.close();
}
}
```

Refer to [Examples](https://github.com/IBMa/equal-access/tree/master/accessibility-checker/boilerplates) for sample usage scenarios.
Expand Down

0 comments on commit 7195485

Please sign in to comment.