rsnext/test/lib/amp-test-utils.js
JJ Kasper 6344c5f0c1
Add optimizing AMP pages (#6835)
* 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
2019-04-02 13:01:34 -05:00

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')
}