Skip to content

Commit

Permalink
test: add automated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
theoludwig committed Aug 9, 2023
1 parent 1ae47aa commit 284b9fb
Show file tree
Hide file tree
Showing 20 changed files with 587 additions and 21 deletions.
3 changes: 3 additions & 0 deletions .html-w3c-validatorrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"files": ["./example/build/index.html", "./example/build/about.html"]
}
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fixtures
2 changes: 2 additions & 0 deletions example/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

146 changes: 146 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"@types/html-validator": "5.0.3",
"@types/mock-fs": "4.13.1",
"@types/node": "20.4.9",
"@types/sinon": "10.0.16",
"@typescript-eslint/eslint-plugin": "6.3.0",
"@typescript-eslint/parser": "6.3.0",
"editorconfig-checker": "5.1.1",
Expand All @@ -85,6 +86,7 @@
"rimraf": "5.0.1",
"semantic-release": "21.0.7",
"serve": "14.2.0",
"sinon": "15.2.0",
"typescript": "5.1.6"
}
}
23 changes: 10 additions & 13 deletions src/HTMLValidatorCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ import { isExistingPath } from './utils/isExistingPath.js'

export const CONFIG_FILE_NAME = '.html-w3c-validatorrc.json'

const severities = ['error', 'warning', 'info'] as const
export const SEVERITIES = ['error', 'warning', 'info'] as const

export type Severity = (typeof severities)[number]
export type Severity = (typeof SEVERITIES)[number]

interface Config {
urls?: string[]
Expand Down Expand Up @@ -113,22 +113,19 @@ export class HTMLValidatorCommand extends Command {
`Invalid config file at "${configPath}". Please add URLs or files.`
)
}
const configSeverities: Severity[] = config.severities ?? [
'warning',
'error'
]
for (const severity of configSeverities) {
if (!severities.includes(severity)) {
const severities: Severity[] = config.severities ?? ['warning', 'error']
for (const severity of severities) {
if (!SEVERITIES.includes(severity)) {
throw new Error(
`Invalid config file at "${configPath}". Please add valid severities (${severities.join(
`Invalid config file at "${configPath}". Please add valid severities (${SEVERITIES.join(
', '
)}).`
)
}
}
if (configSeverities.length === 0) {
if (severities.length === 0) {
throw new Error(
`Invalid config file at "${configPath}". Please add valid severities (${severities.join(
`Invalid config file at "${configPath}". Please add valid severities (${SEVERITIES.join(
', '
)}).`
)
Expand Down Expand Up @@ -169,8 +166,8 @@ export class HTMLValidatorCommand extends Command {
}
const hasErrors = result.messages.some((message) => {
return (
configSeverities.includes(message.type as Severity) ||
configSeverities.includes(message.subType as Severity)
severities.includes(message.type as Severity) ||
severities.includes(message.subType as Severity)
)
})
if (!hasErrors) {
Expand Down
Loading

0 comments on commit 284b9fb

Please sign in to comment.