Skip to content
Closed
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
4 changes: 3 additions & 1 deletion services/w3c/w3c-validation-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ The rules are as follows:
<li>non-document-error: These messages are counted as errors</li>
</ul>

This badge relies on the https://validator.nu/ service to perform the validation.
This badge relies on the Nu validator service to perform the validation. By default it
uses https://validator.nu/; pass \`validator=validator.w3.org\` to use the W3C-hosted
deployment at https://validator.w3.org/nu/ instead.
Please refer to https://about.validator.nu/ for the full documentation and Terms of service.
`

Expand Down
31 changes: 27 additions & 4 deletions services/w3c/w3c-validation.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ const schema = Joi.object({
const queryParamSchema = Joi.object({
targetUrl: url,
preset: Joi.string().regex(presetRegex).allow(''),
validator: Joi.equal('validator.nu', 'validator.w3.org').default(
'validator.nu',
),
}).required()

const parserDescription = `The parser that is used for validation. This is a passthru value to the service
Expand Down Expand Up @@ -85,6 +88,17 @@ export default class W3cValidation extends BaseJsonService {
],
},
}),
queryParam({
name: 'validator',
example: 'validator.w3.org',
description: `The Nu validator deployment to use. This is a passthru choice of host, both run the same engine and API:
- \`validator.nu\` (default): the original hsivonen-hosted service
- \`validator.w3.org\`: the W3C-hosted deployment, at https://validator.w3.org/nu/`,
schema: {
type: 'string',
enum: ['validator.nu', 'validator.w3.org'],
},
}),
],
},
},
Expand All @@ -101,9 +115,13 @@ export default class W3cValidation extends BaseJsonService {
}
}

async fetch(targetUrl, preset, parser) {
async fetch(targetUrl, preset, parser, validator) {
const validatorUrl =
validator === 'validator.w3.org'
? 'https://validator.w3.org/nu/'
: 'https://validator.nu/'
return this._requestJson({
url: 'https://validator.nu/',
url: validatorUrl,
schema,
options: {
searchParams: {
Expand Down Expand Up @@ -155,8 +173,13 @@ export default class W3cValidation extends BaseJsonService {
}, {})
}

async handle({ parser }, { targetUrl, preset }) {
const { url, messages } = await this.fetch(targetUrl, preset, parser)
async handle({ parser }, { targetUrl, preset, validator }) {
const { url, messages } = await this.fetch(
targetUrl,
preset,
parser,
validator,
)
return this.constructor.render({
messageTypes: this.transform(url, messages),
})
Expand Down
24 changes: 24 additions & 0 deletions services/w3c/w3c-validation.tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,27 @@ t.create('W3C Validation page has multiple of validation errors with red badge')
message: isW3CMessage,
color: isW3CColors,
})

t.create(
'W3C Validation via validator.w3.org: page conforms to standards with brightgreen badge',
)
.get(
'/default.json?targetUrl=https://hsivonen.com/test/moz/messages-types/no-message.html&validator=validator.w3.org',
)
.expectBadge({
label: 'w3c',
message: isW3CMessage,
color: isW3CColors,
})

t.create(
'W3C Validation via validator.w3.org: page has 1 validation error with red badge',
)
.get(
'/html.json?targetUrl=http://hsivonen.com/test/moz/messages-types/warning.html&validator=validator.w3.org',
)
.expectBadge({
label: 'w3c',
message: isW3CMessage,
color: isW3CColors,
})
Loading