All files / src/commands add-a11y.js

83.33% Statements 10/12
75% Branches 3/4
75% Functions 6/8
83.33% Lines 10/12

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49                    6x       2x     2x       2x         2x     6x       1x     1x       1x         1x      
import {
    PackageJsonEditor,
    allDoExist,
    install,
    uninstall
} from '../api';
/**
 * @type {task[]}
 * @see http://pa11y.org/
 */
export const addA11y = [
    {
        text: 'Add accessibility tasks to package.json',
        task: async ({outputDirectory}) => {
            const scripts = {
                'lint:aria': `pa11y ${outputDirectory}/index.html`
            };
            await (new PackageJsonEditor())
                .extend({scripts})
                .commit();
        },
        condition: () => allDoExist('package.json')
    },
    {
        text: 'Install pa11y for checking accessibility rules',
        task: ({skipInstall}) => install(['pa11y'], {dev: true, skipInstall}),
        condition: ({skipInstall}) => !skipInstall && allDoExist('package.json')
    }
];
export const removeA11y = [
    {
        text: 'Remove accessibility tasks from package.json',
        task: async () => {
            const scripts = {
                'lint:aria': undefined
            };
            await (new PackageJsonEditor())
                .extend({scripts})
                .commit();
        },
        condition: () => allDoExist('package.json')
    },
    {
        text: 'Uninstall pa11y',
        task: () => uninstall(['pa11y']),
        condition: () => allDoExist('package.json') && (new PackageJsonEditor()).hasAll('pa11y')
    }
];
export default addA11y;