6344c5f0c1
* Added amp-toolbox-optimizer and added optimizing AMP pages as dirty and clean * Fix amp-optimizer breaking serverless build * Exclude amp-toolbox-optimizer from serverless build * Added check to make sure hybrid AMP pages optimize cleanly during export * Add check to make sure noDirtyAmp is applied
21 lines
719 B
JavaScript
21 lines
719 B
JavaScript
/* eslint-env jest */
|
|
import amphtmlValidator from 'amphtml-validator'
|
|
|
|
export async function validateAMP (html, expectFail) {
|
|
const validator = await amphtmlValidator.getInstance()
|
|
const result = validator.validateString(html)
|
|
if (result.status !== 'PASS') {
|
|
for (let ii = 0; ii < result.errors.length; ii++) {
|
|
const error = result.errors[ii]
|
|
let msg =
|
|
'line ' + error.line + ', col ' + error.col + ': ' + error.message
|
|
if (error.specUrl !== null) {
|
|
msg += ' (see ' + error.specUrl + ')'
|
|
}
|
|
if (!expectFail) {
|
|
;(error.severity === 'ERROR' ? console.error : console.warn)(msg)
|
|
}
|
|
}
|
|
}
|
|
expect(result.status).toBe(expectFail ? 'FAIL' : 'PASS')
|
|
}
|