UNPKG

sitespeed.io

Version:

sitespeed.io is an open-source tool for comprehensive web performance analysis, enabling you to test, monitor, and optimize your website’s speed using real browsers in various environments.

67 lines (61 loc) 1.77 kB
import path from 'node:path'; import { readFileSync } from 'node:fs'; import { fileURLToPath } from 'node:url'; import { getLogger } from '@sitespeed.io/log'; import axe from 'axe-core'; const { version: axeVersion } = axe; import { SitespeedioPlugin } from '@sitespeed.io/plugin'; const log = getLogger('sitespeedio.plugin.axe'); const __dirname = fileURLToPath(new URL('.', import.meta.url)); export default class AxePlugin extends SitespeedioPlugin { constructor(options, context, queue) { super({ name: 'axe', options, context, queue }); } open(context, options) { this.options = options; this.make = context.messageMaker('axe').make; this.pug = readFileSync( path.resolve(__dirname, 'pug', 'index.pug'), 'utf8' ); log.info(`Axe version %s plugin activated`, axeVersion); } processMessage(message, queue) { const make = this.make; switch (message.type) { case 'browsertime.setup': { queue.postMessage( make('browsertime.config', { postURLScript: path.resolve(__dirname, 'axePostScript.cjs') }) ); break; } case 'axe.run': { break; } case 'sitespeedio.setup': { // Tell other plugins that axe will run queue.postMessage(make('axe.setup', { version: axeVersion })); // Add the HTML pugs queue.postMessage( make('html.pug', { id: 'axe', name: 'axe', pug: this.pug, type: 'pageSummary' }) ); queue.postMessage( make('html.pug', { id: 'axe', name: 'axe', pug: this.pug, type: 'run' }) ); break; } } } }