@acot/core
Advanced tools
Comparing version 0.0.4 to 0.0.5
@@ -6,2 +6,12 @@ # Change Log | ||
## [0.0.5](https://github.com/acot-a11y/acot/compare/@acot/core@0.0.4...@acot/core@0.0.5) (2021-01-01) | ||
### Bug Fixes | ||
- fix summary duration bug ([a5fb2d3](https://github.com/acot-a11y/acot/commit/a5fb2d34bc30967d284b37b24a0ea54220bf3565)) | ||
### Features | ||
- **core:** add chromium auto detection for `BrowserPool` ([21f7228](https://github.com/acot-a11y/acot/commit/21f722882efe18605dc3867ddf328f31aede160a)) | ||
## [0.0.4](https://github.com/acot-a11y/acot/compare/@acot/core@0.0.4-canary.0...@acot/core@0.0.4) (2020-12-29) | ||
@@ -8,0 +18,0 @@ |
@@ -16,2 +16,3 @@ "use strict"; | ||
const tester_1 = require("./tester"); | ||
const timing_1 = require("./timing"); | ||
class Acot { | ||
@@ -85,2 +86,3 @@ constructor(config = {}) { | ||
async audit() { | ||
const measure = timing_1.mark(); | ||
const urls = this._testers.map((tester) => tester.url()); | ||
@@ -106,3 +108,3 @@ // working directory | ||
})); | ||
const summary = this._summarize(results); | ||
const summary = this._summarize(results, measure()); | ||
await this._emitter.emit('audit:complete', [summary]); | ||
@@ -124,5 +126,4 @@ // close | ||
} | ||
_summarize(results) { | ||
_summarize(results, duration) { | ||
const rulesAndStat = results.reduce((acc, cur) => { | ||
acc.duration += cur.duration; | ||
acc.passCount += cur.passCount; | ||
@@ -147,2 +148,3 @@ acc.errorCount += cur.errorCount; | ||
...rulesAndStat, | ||
duration, | ||
results: lodash_1.default.orderBy(results, [(res) => res.url], ['asc']), | ||
@@ -149,0 +151,0 @@ }; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.BrowserPool = void 0; | ||
const find_chrome_1 = require("@acot/find-chrome"); | ||
const browser_1 = require("./browser"); | ||
const queue_1 = require("./queue"); | ||
const logging_1 = require("./logging"); | ||
const WORK_INTERVAL = 30; | ||
@@ -35,5 +37,17 @@ class BrowserPool { | ||
async bootstrap(parallel) { | ||
const { launchOptions } = this._config; | ||
let opts = this._config.launchOptions; | ||
if (!opts.executablePath) { | ||
logging_1.debug('try chrome auto detection...'); | ||
const chrome = await find_chrome_1.findChrome(); | ||
if (chrome == null) { | ||
throw new Error('Executable Chromium was not found.'); | ||
} | ||
logging_1.debug('auto detected chrome: %O', chrome); | ||
opts = { | ||
...opts, | ||
executablePath: chrome.executablePath, | ||
}; | ||
} | ||
await Promise.all(Array.from(Array(parallel || 1)).map(async (_, i) => { | ||
this._available.add(await new browser_1.Browser(i).launch(launchOptions)); | ||
this._available.add(await new browser_1.Browser(i).launch(opts)); | ||
})); | ||
@@ -40,0 +54,0 @@ this._interval = setInterval(() => this._work(), WORK_INTERVAL); |
import type { Rule } from '@acot/types'; | ||
export declare const createRule: <T = unknown>(descriptor: Rule<T>) => Rule<T>; | ||
export declare const createRule: <T extends Record<string, any>>(descriptor: Rule<T>) => Rule<T>; |
@@ -183,44 +183,22 @@ "use strict"; | ||
}); | ||
const handleUnexpectedError = (e) => { | ||
logging_1.debug('Unexpected error occurred:', e); | ||
results.push(factory_1.createTestcaseResult({ | ||
process: browser.id(), | ||
const factory = (...args) => factory_1.createTestcaseResult({ | ||
process: browser.id(), | ||
duration: measure(), | ||
rule: id, | ||
...args[0], | ||
}); | ||
try { | ||
await rule.test(context); | ||
} | ||
catch (e) { | ||
this._debug('Unexpected error occurred:', e); | ||
results.push(factory({ | ||
status: 'error', | ||
rule: id, | ||
duration: measure(), | ||
message: e instanceof Error ? e.message : `Unexpected error occurred: ${e}`, | ||
})); | ||
}; | ||
switch (rule.type) { | ||
case 'global': { | ||
await rule.test(context).catch(handleUnexpectedError); | ||
break; | ||
} | ||
case 'contextual': { | ||
try { | ||
const nodes = await page.$$(rule.selector); | ||
await Promise.all(nodes.map((node) => rule.test(context, node).catch(handleUnexpectedError))); | ||
} | ||
catch (e) { | ||
logging_1.debug('Not found elements (rule="%s", url="%s")', id, url, e); | ||
} | ||
break; | ||
} | ||
default: | ||
results.push(factory_1.createTestcaseResult({ | ||
process: browser.id(), | ||
status: 'error', | ||
rule: id, | ||
message: `The rule type "${rule.type}" is invalid.`, | ||
duration: measure(), | ||
})); | ||
break; | ||
} | ||
// pass | ||
if (results.length === 0) { | ||
results.push(factory_1.createTestcaseResult({ | ||
process: browser.id(), | ||
results.push(factory({ | ||
status: 'pass', | ||
rule: id, | ||
duration: measure(), | ||
})); | ||
@@ -227,0 +205,0 @@ } |
{ | ||
"name": "@acot/core", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"description": "More accessible web, all over the world.", | ||
@@ -36,3 +36,4 @@ "homepage": "https://github.com/acot-a11y/acot/tree/main/packages/core", | ||
"dependencies": { | ||
"@acot/factory": "0.0.4", | ||
"@acot/factory": "0.0.5", | ||
"@acot/find-chrome": "0.0.4", | ||
"@acot/html-pickup": "0.0.4", | ||
@@ -42,3 +43,3 @@ "@acot/logger": "0.0.4", | ||
"@acot/schema-validator": "0.0.4", | ||
"@acot/types": "0.0.4", | ||
"@acot/types": "0.0.5", | ||
"@acot/utils": "0.0.4", | ||
@@ -54,4 +55,3 @@ "debug": "^4.3.1", | ||
"devDependencies": { | ||
"@acot/find-chrome": "0.0.4", | ||
"@acot/mock": "0.0.2", | ||
"@acot/mock": "0.0.3", | ||
"@types/lodash": "^4.14.165", | ||
@@ -64,3 +64,3 @@ "@types/puppeteer-core": "^2.0.0", | ||
}, | ||
"gitHead": "0531a93558a269870a369dcd9cdd450e3812f1a2" | ||
"gitHead": "9e986f72955e83d9aa0030d9e22e003d2fd4167a" | ||
} |
@@ -19,5 +19,7 @@ # @acot/core | ||
In the simple example, the following package is used. | ||
In the simple example, it depends on the following package. | ||
- [puppeteer](https://github.com/puppeteer/puppeteer) | ||
```bash | ||
$ npm install --save puppeteer | ||
``` | ||
@@ -27,3 +29,2 @@ The following is an example of specifying all audited pages and their configuration. | ||
```typescript | ||
import puppeteer from 'puppeteer'; | ||
import { Acot, PresetLoader } from '@acot/core'; | ||
@@ -40,5 +41,2 @@ | ||
presets: [loader.load('@acot/wcag')], | ||
launchOptions: { | ||
executablePath: puppeteer.executablePath(), | ||
}, | ||
cwd, | ||
@@ -45,0 +43,0 @@ }); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4
44691
15
1000
104
+ Added@acot/find-chrome@0.0.4
+ Added@acot/factory@0.0.5(transitive)
+ Added@acot/types@0.0.5(transitive)
- Removed@acot/factory@0.0.4(transitive)
- Removed@acot/types@0.0.4(transitive)
Updated@acot/factory@0.0.5
Updated@acot/types@0.0.5