diff --git a/src/HTMLValidatorCommand.ts b/src/HTMLValidatorCommand.ts index b8c2146..a8bc7f6 100644 --- a/src/HTMLValidatorCommand.ts +++ b/src/HTMLValidatorCommand.ts @@ -176,6 +176,13 @@ export class HTMLValidatorCommand extends Command { results.push({ data, isSuccess: false }) const messagesTable: string[][] = [] for (const message of result.messages) { + if ( + !severities.includes(message.type as Severity) && + !severities.includes(message.subType as Severity) + ) { + continue + } + const row: string[] = [] if (message.type === 'info') { if (message.subType === 'warning') { diff --git a/src/__test__/HTMLValidatorCommand.test.ts b/src/__test__/HTMLValidatorCommand.test.ts index 2ede0a2..49c99b3 100644 --- a/src/__test__/HTMLValidatorCommand.test.ts +++ b/src/__test__/HTMLValidatorCommand.test.ts @@ -374,4 +374,43 @@ await test('html-w3c-validator', async (t) => { errors.join('\n') ) }) + + await t.test('fails with invalid W3C HTML', async () => { + const workingDirectory = path.join(FIXTURES_PATH, 'error-invalid-w3c-html') + const errors: string[] = [] + sinon.stub(console, 'error').value((error: string) => { + errors.push(error) + }) + const consoleErrorSpy = sinon.spy(console, 'error') + const stream = new PassThrough() + const exitCode = await cli.run( + [`--current-working-directory=${workingDirectory}`], + { + stdin: process.stdin, + stdout: stream, + stderr: stream + } + ) + stream.end() + assert.strictEqual(exitCode, 1) + const messagesTable = [ + [ + chalk.yellow('warning'), + 'Consider adding a “lang” attribute to the “html” start tag to declare the language of this document.', + 'line: 2, column: 16-6' + ] + ] + assert.strictEqual( + consoleErrorSpy.calledWith( + chalk.bold.red('Error:') + ' HTML validation (W3C) failed!' + ), + true, + errors.join('\n') + ) + assert.strictEqual( + consoleErrorSpy.calledWith(table(messagesTable)), + true, + errors.join('\n') + ) + }) }) diff --git a/src/__test__/fixtures/error-invalid-w3c-html/.html-w3c-validatorrc.json b/src/__test__/fixtures/error-invalid-w3c-html/.html-w3c-validatorrc.json new file mode 100644 index 0000000..a4a2392 --- /dev/null +++ b/src/__test__/fixtures/error-invalid-w3c-html/.html-w3c-validatorrc.json @@ -0,0 +1,3 @@ +{ + "files": ["./build/index.html", "./build/about.html"] +} diff --git a/src/__test__/fixtures/error-invalid-w3c-html/build/about.html b/src/__test__/fixtures/error-invalid-w3c-html/build/about.html new file mode 100644 index 0000000..e393d8f --- /dev/null +++ b/src/__test__/fixtures/error-invalid-w3c-html/build/about.html @@ -0,0 +1,9 @@ + + +
+ + +