UNPKG

site-validator-cli

Version:

A command line tool that takes a URL or a file, then uses html-validator (a wrapper for https://validator.w3.org/nu/) to validate each page.

51 lines (47 loc) 1.34 kB
'use strict' module.exports = (output) => { /* Currently this is not meant to be a thorough check because it could open a can of worms for unit testing. The idea is if this test passed, the similarity in object structure means the file was most likely generated by site-validator-cli. */ // validate top level structure const schema = { url: 'string', pages: [], quiet: true, singlePage: true, passed: true, results: {} } for (const [key, value] of Object.entries(schema)) { if (output[key] === undefined || typeof output[key] !== typeof value) { return false } } // validate results structure const resultsSchema = { passed: [], failed: [] } for (const [key, value] of Object.entries(resultsSchema)) { if (output.results[key] === undefined || typeof output.results[key] !== typeof value) { return false } } // validate individual result structure const resultSchema = { url: 'string', status: 'string', errors: [] } const resultList = [].concat(output.results.passed, output.results.failed) for (const result of resultList) { for (const [key, value] of Object.entries(resultSchema)) { if (result[key] === undefined || typeof result[key] !== typeof value) { return false } } } return true }