Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve messaging #56

Open
wants to merge 14 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61,869 changes: 15,294 additions & 46,575 deletions actions/ui-check/package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions actions/ui-check/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
"test:e2e:interactive": "PUPPETEER_HEADLESS=false wp-scripts test-e2e --config tests/e2e/jest.config.js",
"test:e2e": "wp-scripts test-e2e --config tests/e2e/jest.config.js",
"test:e2e:dev": "DEV_MODE=true wp-scripts test-e2e --config tests/e2e/jest.config.js",
"test:e2e:sanity": "SANITY_MODE=true DEV_MODE=true wp-scripts test-e2e --config tests/e2e/jest.sanity.js",
"test:e2e:sanity": "SANITY_MODE=true wp-scripts test-e2e --config tests/e2e/jest.sanity.js",
"test:unit": "wp-scripts test-unit-js --config tests/unit/jest.config.js --passWithNoTests",
"test:unit:dev": "DEV_MODE=true wp-scripts test-unit-js --config tests/unit/jest.config.js",
"test:unit:sanity": "SANITY_MODE=true DEV_MODE=true wp-scripts test-e2e --config tests/unit/jest.sanity.js",
"test:unit:sanity": "SANITY_MODE=true wp-scripts test-e2e --config tests/unit/jest.sanity.js",
"start": "npm run install:environment && npm run test:unit && npm run test:e2e"
},
"author": "The WordPress Contributors",
Expand Down
5 changes: 5 additions & 0 deletions actions/ui-check/tests/e2e/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,13 @@ let configs = {
// Exclude any sanity tests
'!**/e2e/**/sanity/**',
],
reporters: [ '<rootDir>/../reporters/index.js' ],
};

if ( process.env.DEV_MODE ) {
configs.reporters = [ 'default' ];
}

// When run using NPX there are issues related to running in a `node_modules` folder.
if (
process.env.INIT_CWD &&
Expand Down
52 changes: 30 additions & 22 deletions actions/ui-check/tests/e2e/specs/a11y/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,23 @@
import urls from './pages';
import {
createURL,
cleanErrorMessage,
printMessage,
getEnvironmentVariable,
} from '../../../utils';

describe( 'Accessibility', () => {
/**
* Removes some noise that exists in the testing framework error messages.
* @param {string} msg Error message thrown by testing framework.
* @returns {string}
*/
export const cleanErrorMessage = ( msg ) => {
return msg
.replace( 'expect(received).toPassAxeTests(expected)', '' )
.replace( 'Expected page to pass Axe accessibility tests.', '' )
.replace( /^\s*$(?:\r\n?|\n)/, '\n' );
};

describe.each( urls, () => {
const envVar = getEnvironmentVariable( process.env.TEST_ACCESSIBILITY );
const testAccessibility = envVar === 'true';
const accessibilityTest = testAccessibility ? 'wcag2a' : 'best-practice';
Expand All @@ -18,27 +29,24 @@ describe( 'Accessibility', () => {
// Temporarily set everything as a warning.
const noticeType = 'warnings';

test.each( urls )(
`Should pass ${ accessibilityTest } Axe tests on %s`,
async ( name, path, query ) => {
await page.goto( createURL( path, query ) );
test( `Should pass ${ accessibilityTest } Axe tests on %s`, async ( name, path, query ) => {
await page.goto( createURL( path, query ) );

try {
await expect( page ).toPassAxeTests( {
options: {
runOnly: {
type: 'tag',
values: [ accessibilityTest ],
},
try {
await expect( page ).toPassAxeTests( {
options: {
runOnly: {
type: 'tag',
values: [ accessibilityTest ],
},
exclude: [ [ '.entry-content' ] ],
} );
} catch ( e ) {
printMessage( noticeType, [
`Running tests on ${ name } ${ path }${ query } using: \nhttps://github.com/wpaccessibility/a11y-theme-unit-test`,
cleanErrorMessage( e.message ),
] );
}
},
exclude: [ [ '.entry-content' ] ],
} );
} catch ( e ) {
printMessage( noticeType, [
`Running tests on ${ name } ${ path }${ query } using: \nhttps://github.com/wpaccessibility/a11y-theme-unit-test`,
cleanErrorMessage( e.message ),
] );
}
);
} );
} );
3 changes: 1 addition & 2 deletions actions/ui-check/tests/e2e/specs/page/body-class/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ export default async ( url, bodyClass ) => {
const bodyClassName = await getElementPropertyAsync( body, 'className' );

return errorWithMessageOnFail(
`${ url } does not contain a body class`,
'page-should-contain-body-class',
`Unable to find body class when loading a page using ${ url }`,
() => {
expect( bodyClassName.split( ' ' ) ).toContain( bodyClass );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import { errorWithMessageOnFail } from '../../../../utils';

export default async ( url, responseText ) => {
return errorWithMessageOnFail(
`${ url } contains incomplete output. Make sure the page contains valid html.`,
'page-should-have-complete-output',
`Loading a page using ${ url } contains incomplete output. Make sure the page contains valid html.`,
() => {
expect( responseText ).toMatch( /<\/(html|rss)>\s*$/ );
}
Expand Down
18 changes: 8 additions & 10 deletions actions/ui-check/tests/e2e/specs/page/frontpage-template/index.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
/**
* Internal dependencies
*/
import {
errorWithMessageOnFail,
getFileNameFromPath,
} from '../../../../utils';
import { errorWithMessageOnFail, getFileNameFromPath } from '../../../../utils';

export default async ( url ) => {
let template, filename;

const template = await page.$eval( '#template', (el) => el.value);
const filename = getFileNameFromPath( template );
try {
template = await page.$eval( '#template', ( el ) => el.value );
filename = getFileNameFromPath( template );
} catch ( ex ) {}

return errorWithMessageOnFail(
`${url} Frontpage template file must not be page.php`,
'frontpage-should-show-correct-content',
`Frontpage template file must not be page.php`,
() => {
expect( filename ).not.toBe( 'page.php' );
},
}
);

};
6 changes: 2 additions & 4 deletions actions/ui-check/tests/e2e/specs/page/frontpage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@ export default async ( url ) => {
const bodyClassName = await getElementPropertyAsync( body, 'className' );

return errorWithMessageOnFail(
`${url} does not contain the blog body class`,
'frontpage-should-show-correct-content',
`${ url } does not contain the blog body class`,
() => {
expect( bodyClassName.split( ' ' ) ).toContain( 'blog' );
},
}
);

};
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ describe( 'Sanity: Blog Body Class Test', () => {
} );

it( 'Page should FAIL when response is empty', async () => {
await page.goto( `file:${ path.join( __dirname, 'html/empty.html' ) }` );
await page.goto(
`file:${ path.join( __dirname, 'html/empty.html' ) }`
);

expect( await test( '', 'frontpage' ) ).toBeFalsy();
} );

} );
32 changes: 17 additions & 15 deletions actions/ui-check/tests/e2e/specs/page/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ const fetch = require( 'node-fetch' );
/**
* Internal dependencies
*/
import { getFileNameFromPath, getTestUrls, goTo, getSiteInfo } from '../../../utils';
import {
getFileNameFromPath,
getTestUrls,
goTo,
getSiteInfo,
} from '../../../utils';

import bodyClassTest from './body-class';
import phpErrorsTest from './php-errors';
Expand All @@ -23,11 +28,11 @@ let urls = [ [ '/', '?feed=rss2', '' ], ...getTestUrls() ];

const getUrlPathWithTemplate = async ( urlPath ) => {
const template = await page.$eval( '#template', ( el ) => el.value );
return `${ urlPath } (via: ${ getFileNameFromPath( template ) })`;
return getFileNameFromPath( template );
};

// Some basic tests that apply to every page
describe.each( urls )( 'Test URL %s%s', ( url, queryString, bodyClass ) => {
describe.each( urls )( '%s%s', ( url, queryString, bodyClass ) => {
let pageResponse, urlPath;

beforeAll( async () => {
Expand All @@ -39,7 +44,7 @@ describe.each( urls )( 'Test URL %s%s', ( url, queryString, bodyClass ) => {
} catch ( ex ) {}
} );

it( 'Page should contain body class ' + bodyClass, async () => {
it( 'Page should contain body class', async () => {
// Make sure the page content appears to be appropriate for the URL.
await bodyClassTest( urlPath, bodyClass );
} );
Expand Down Expand Up @@ -68,13 +73,12 @@ describe.each( urls )( 'Test URL %s%s', ( url, queryString, bodyClass ) => {
// See https://make.wordpress.org/themes/handbook/review/required/#selling-credits-and-links
await unexpectedLinksTest( urlPath );
} );

} );

// Some basic tests that apply only to the frontpage
let homeurl = [ [ '/', '', 'home' ] ];

describe.each( homeurl )( 'Test URL %s%s', ( url, queryString ) => {
describe.each( homeurl )( '%s%s', ( url, queryString ) => {
let pageResponse, urlPath;

beforeAll( async () => {
Expand All @@ -93,25 +97,23 @@ describe.each( homeurl )( 'Test URL %s%s', ( url, queryString ) => {
it( 'Frontpage template should not be page.php', async () => {
await frontpageTemplateTest( urlPath );
} );

} );

// Test if theme and author URI have a valid responses
const siteInfo = getSiteInfo();
let theme_urls = [...siteInfo.theme_urls];
let theme_urls = [ ...siteInfo.theme_urls ];

if ( theme_urls[0] ) {
describe.each( theme_urls )('Test URL %s', ( url ) => {
if ( theme_urls[ 0 ] ) {
describe.each( theme_urls )( '%s', ( url ) => {
let pageResponse;

beforeAll(async () => {
beforeAll( async () => {
pageResponse = await page.goto( url );
});
} );

it( 'Page should return 200 status', async () => {
const status = await pageResponse.status();
await pageStatusTest( url, status );
});

});
} );
} );
}
3 changes: 1 addition & 2 deletions actions/ui-check/tests/e2e/specs/page/js-errors/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ page.on( 'pageerror', ( error ) => {

export default async ( url ) => {
return errorWithMessageOnFail(
`${ url } contains javascript errors. Found ${ removeLocalPathRefs(
`Loading the page using ${ url } contains javascript errors. Found ${ removeLocalPathRefs(
jsError
) }`,
'browser-console-should-not-contain-errors',
() => {
expect( jsError ).toBeFalsy();
}
Expand Down
1 change: 0 additions & 1 deletion actions/ui-check/tests/e2e/specs/page/page-status/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { errorWithMessageOnFail } from '../../../../utils';
export default async ( url, status ) => {
return errorWithMessageOnFail(
`Expected to received a 200 status for ${ url }. Received ${ status }.`,
'page-should-return-200-status',
() => {
expect( status ).toBe( 200 );
}
Expand Down
5 changes: 3 additions & 2 deletions actions/ui-check/tests/e2e/specs/page/php-errors/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ export default async ( url ) => {
const pageError = await getPageError();

return errorWithMessageOnFail(
`${ url } contains PHP errors: ${ removeLocalPathRefs( pageError ) }`,
'page-should-not-have-php-errors',
`Loading the page using ${ url } contains PHP errors: ${ removeLocalPathRefs(
pageError
) }`,
() => {
expect( pageError ).toBe( null );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ export default async ( url ) => {
let hostname = removeWWW( href_url.hostname );
const result = errorWithMessageOnFail(
`"${ hostname }" found when viewing ${ url } is not an approved link.`,
'page-should-not-have-unexpected-links',
() => {
expect( allowed_hosts ).toContain( hostname );
}
Expand Down
10 changes: 3 additions & 7 deletions actions/ui-check/tests/e2e/specs/ui/element-focus/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,9 @@ export default async () => {
return await test();
} catch ( ex ) {
if ( ex instanceof FailedTestException ) {
warnWithMessageOnFail(
ex.messages,
'should-have-element-focus-state',
() => {
expect( false ).toEqual( true );
}
);
warnWithMessageOnFail( ex.messages, () => {
expect( false ).toEqual( true );
} );
} else {
console.log( ex );
}
Expand Down
2 changes: 1 addition & 1 deletion actions/ui-check/tests/e2e/specs/ui/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import subMenuTest from './sub-menu';
import elementFocusTest from './element-focus';
import tabbingTest from './tabbing';

describe( 'Accessibility: UI', () => {
describe( '/', () => {
beforeAll( async () => {
await goTo( '/' );
} );
Expand Down
10 changes: 3 additions & 7 deletions actions/ui-check/tests/e2e/specs/ui/skip-links/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,9 @@ export default async () => {
return await test();
} catch ( ex ) {
if ( ex instanceof FailedTestException ) {
return warnWithMessageOnFail(
ex.messages,
'should-have-skip-links',
() => {
expect( false ).toEqual( true );
}
);
return warnWithMessageOnFail( ex.messages, () => {
expect( false ).toEqual( true );
} );
} else {
console.log( ex );
}
Expand Down
12 changes: 3 additions & 9 deletions actions/ui-check/tests/e2e/specs/ui/sub-menu/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,10 @@ export default async () => {
return await test();
} catch ( ex ) {
if ( ex instanceof FailedTestException ) {
warnWithMessageOnFail(
ex.messages,
'should-have-appropriate-submenus',

() => {
expect( false ).toEqual( true );
}
);
warnWithMessageOnFail( ex.messages, () => {
expect( false ).toEqual( true );
} );
} else {
console.log( ex );
}

return false;
Expand Down
11 changes: 3 additions & 8 deletions actions/ui-check/tests/e2e/specs/ui/tabbing/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,9 @@ export default async () => {
await makeGif( 1280, 800, SCREENSHOT_TABBING_TEST, 100 );
}

warnWithMessageOnFail(
ex.messages,
'should-have-logical-tabbing',

() => {
expect( false ).toEqual( true );
}
);
warnWithMessageOnFail( ex.messages, () => {
expect( false ).toEqual( true );
} );
} else {
console.log( ex );
}
Expand Down
Loading