@acot/core
Advanced tools
Comparing version 0.0.16 to 0.0.17-canary.0
@@ -92,7 +92,4 @@ "use strict"; | ||
this._available.add(browser); | ||
if (this._queue.size > 0) { | ||
this._work(); | ||
} | ||
} | ||
} | ||
exports.BrowserPool = BrowserPool; |
@@ -16,2 +16,3 @@ "use strict"; | ||
const writeFile = (0, util_1.promisify)(fs_1.default.writeFile); | ||
const errorMessage = (e) => e instanceof Error ? e.message : String(e); | ||
const buildFilename = (...args) => { | ||
@@ -32,3 +33,3 @@ return args | ||
catch (e) { | ||
(0, logging_1.debug)('Element to Selector Error:', e); | ||
(0, logging_1.debug)('Element to Selector Error: %s', errorMessage(e)); | ||
return null; | ||
@@ -46,3 +47,3 @@ } | ||
catch (e) { | ||
(0, logging_1.debug)('Screenshot Error:', e); | ||
(0, logging_1.debug)('Screenshot Error: %s', errorMessage(e)); | ||
return false; | ||
@@ -49,0 +50,0 @@ } |
@@ -1,2 +0,2 @@ | ||
import type { NormalizedRuleConfig, TestResult, CoreEventMap } from '@acot/types'; | ||
import type { CoreEventMap, NormalizedRuleConfig, TestResult } from '@acot/types'; | ||
import type { Viewport } from 'puppeteer-core'; | ||
@@ -31,6 +31,5 @@ import type { BrowserPool } from './browser-pool'; | ||
private _createPage; | ||
private _cleanupPage; | ||
private _waitForReady; | ||
private _execute; | ||
private _waitForReady; | ||
private _debug; | ||
} |
@@ -7,8 +7,7 @@ "use strict"; | ||
exports.Tester = void 0; | ||
const factory_1 = require("@acot/factory"); | ||
const schema_validator_1 = require("@acot/schema-validator"); | ||
const factory_1 = require("@acot/factory"); | ||
const lodash_1 = __importDefault(require("lodash")); | ||
const p_series_1 = __importDefault(require("p-series")); | ||
const logging_1 = require("./logging"); | ||
const rule_context_1 = require("./rule-context"); | ||
const logging_1 = require("./logging"); | ||
const timing_1 = require("./timing"); | ||
@@ -28,40 +27,20 @@ class Tester { | ||
const { priority, url, onTestStart, onTestComplete } = this._config; | ||
const { immutable, mutable } = this._prepare(); | ||
const ids = [...immutable, ...mutable].map(([id]) => id); | ||
const rules = this._prepare(); | ||
const ids = rules.map(([id]) => id); | ||
await onTestStart(url, ids); | ||
const measure = (0, timing_1.mark)(); | ||
this._debug(`start ${ids.length} rules`); | ||
await Promise.allSettled([ | ||
immutable.length > 0 | ||
? pool.execute(priority, async (browser) => { | ||
const page = await this._createPage(browser); | ||
try { | ||
await (0, p_series_1.default)(immutable.map((args) => async () => { | ||
await this._execute(browser, page, args); | ||
await this._cleanupPage(page); | ||
})); | ||
} | ||
catch (e) { | ||
this._debug(e); | ||
} | ||
finally { | ||
await page.close(); | ||
} | ||
}) | ||
: Promise.resolve(), | ||
...mutable.map(async (loop) => { | ||
await pool.execute(priority, async (browser, args) => { | ||
const page = await this._createPage(browser); | ||
try { | ||
await this._execute(browser, page, args); | ||
} | ||
catch (e) { | ||
this._debug(e); | ||
} | ||
finally { | ||
await page.close(); | ||
} | ||
}, loop); | ||
}), | ||
]); | ||
await Promise.allSettled(rules.map((loop) => pool.execute(priority, async (browser, args) => { | ||
let page = null; | ||
try { | ||
page = await this._createPage(browser); | ||
await this._execute(browser, page, args); | ||
} | ||
catch (e) { | ||
this._debug(e); | ||
} | ||
finally { | ||
await (page === null || page === void 0 ? void 0 : page.close()); | ||
} | ||
}, loop))); | ||
const rulesAndStat = this._results.reduce((acc, cur) => { | ||
@@ -130,6 +109,7 @@ const rules = acc.rules; | ||
(0, logging_1.debug)('validation error:', e); | ||
const msg = e instanceof Error ? e.message : String(e); | ||
this._results.push((0, factory_1.createTestcaseResult)({ | ||
status: 'error', | ||
rule: id, | ||
message: `${id} validation error: ${e instanceof Error ? e.message : String(e)}`, | ||
message: `${id} validation error: ${msg}`, | ||
})); | ||
@@ -139,14 +119,5 @@ return acc; | ||
} | ||
const group = [id, rule, opts]; | ||
if (rule.immutable) { | ||
acc.immutable.push(group); | ||
} | ||
else { | ||
acc.mutable.push(group); | ||
} | ||
acc.push([id, rule, opts]); | ||
return acc; | ||
}, { | ||
immutable: [], | ||
mutable: [], | ||
}); | ||
}, []); | ||
} | ||
@@ -167,4 +138,20 @@ async _createPage(browser) { | ||
} | ||
async _cleanupPage(page) { | ||
await page.focus('body'); | ||
async _waitForReady(page) { | ||
const { url, readyTimeout: timeout } = this._config; | ||
try { | ||
await Promise.all([ | ||
page.goto(url, { | ||
waitUntil: 'networkidle2', | ||
timeout, | ||
}), | ||
page.waitForNavigation({ | ||
waitUntil: 'domcontentloaded', | ||
timeout, | ||
}), | ||
]); | ||
} | ||
catch (e) { | ||
this._debug(e); | ||
throw e; | ||
} | ||
} | ||
@@ -214,21 +201,2 @@ async _execute(browser, page, [id, rule, options]) { | ||
} | ||
async _waitForReady(page) { | ||
const { url, readyTimeout: timeout } = this._config; | ||
try { | ||
await Promise.all([ | ||
page.goto(url, { | ||
waitUntil: 'networkidle2', | ||
timeout, | ||
}), | ||
page.waitForNavigation({ | ||
waitUntil: 'domcontentloaded', | ||
timeout, | ||
}), | ||
]); | ||
} | ||
catch (e) { | ||
this._debug(e); | ||
throw e; | ||
} | ||
} | ||
_debug(...args) { | ||
@@ -235,0 +203,0 @@ const { url, priority } = this._config; |
{ | ||
"name": "@acot/core", | ||
"version": "0.0.16", | ||
"version": "0.0.17-canary.0", | ||
"description": "More accessible web, all over the world.", | ||
@@ -39,3 +39,3 @@ "keywords": [ | ||
"dependencies": { | ||
"@acot/factory": "0.0.16", | ||
"@acot/factory": "0.0.17-canary.0", | ||
"@acot/find-chrome": "0.0.16", | ||
@@ -46,3 +46,3 @@ "@acot/html-pickup": "0.0.16", | ||
"@acot/schema-validator": "0.0.16", | ||
"@acot/types": "0.0.16", | ||
"@acot/types": "0.0.17-canary.0", | ||
"@acot/utils": "0.0.16", | ||
@@ -58,5 +58,5 @@ "debug": "^4.3.1", | ||
"devDependencies": { | ||
"@acot/mock": "0.0.16", | ||
"@types/lodash": "4.14.180", | ||
"puppeteer": "13.5.1" | ||
"@acot/mock": "0.0.17-canary.0", | ||
"@types/lodash": "4.14.182", | ||
"puppeteer": "13.7.0" | ||
}, | ||
@@ -66,3 +66,3 @@ "publishConfig": { | ||
}, | ||
"gitHead": "7535e01cafd25fc1d6c32c31a1ae9fce5326b3d8" | ||
"gitHead": "613ef7fb03389f03ccc7ddeb63f3dec9d967cfd7" | ||
} |
38779
29
973
+ Added@acot/factory@0.0.17-canary.0(transitive)
+ Added@acot/types@0.0.17-canary.0(transitive)
+ Addedtype-fest@2.19.0(transitive)
- Removed@acot/factory@0.0.16(transitive)
- Removed@acot/types@0.0.16(transitive)
- Removedtype-fest@0.20.2(transitive)
Updated@acot/types@0.0.17-canary.0