Skip to content

Commit 6cd5a5b

Browse files
committed
test: run CLI tests with Webpack inspired harness
1 parent 48eaff5 commit 6cd5a5b

20 files changed

+140
-179
lines changed

.eslintrc.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,13 @@ module.exports = {
4848
},
4949
},
5050
{
51-
files: ['**/*.spec.js'],
51+
files: ['test/**', '**/*.spec.js'],
5252
env: {
5353
jest: true,
5454
},
55+
parserOptions: {
56+
ecmaVersion: 2021,
57+
},
5558
},
5659
],
5760
}

package-lock.json

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
"eslint": "^8.3.0",
8686
"eslint-config-prettier": "^8.3.0",
8787
"eslint-plugin-prettier": "^4.0.0",
88+
"execa": "^5.1.1",
8889
"husky": "^7.0.4",
8990
"jest": "^27.4.3",
9091
"jest-serializer-path": "^0.1.15",

src/cli/formatters/__snapshots__/checkstyle.spec.js.snap

+1-2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,5 @@ exports[`CLI Formatter: checkstyle should have stdout output with formatter chec
2525
<error line=\\"26\\" column=\\"1\\" severity=\\"error\\" message=\\"Tag must be paired, no start tag: [ &lt;/bad&gt; ]\\" source=\\"htmlhint.tag-pair\\"/>
2626
<error line=\\"27\\" column=\\"1\\" severity=\\"error\\" message=\\"Tag must be paired, no start tag: [ &lt;/bad&gt; ]\\" source=\\"htmlhint.tag-pair\\"/>
2727
</file>
28-
</checkstyle>
29-
"
28+
</checkstyle>"
3029
`;

src/cli/formatters/__snapshots__/compact.spec.js.snap

+1-2
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,5 @@ exports[`CLI Formatter: compact should have stdout output with formatter compact
9494
<PROJECT_ROOT>/src/cli/__fixtures__/executable.html: line 96, col 1, error - Tag must be paired, no start tag: [ </bad> ] (tag-pair)
9595
<PROJECT_ROOT>/src/cli/__fixtures__/executable.html: line 97, col 1, error - Tag must be paired, no start tag: [ </bad> ] (tag-pair)
9696
97-
92 problems
98-
"
97+
92 problems"
9998
`;

src/cli/formatters/__snapshots__/default.spec.js.snap

+1-2
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,5 @@ exports[`CLI Formatter: default should have stdout output with formatter default
188188
 L97 |</bad>
189189
 ^ Tag must be paired, no start tag: [ </bad> ] (tag-pair)
190190
191-
Scanned 1 files, found 92 errors in 1 files ((99 ms))
192-
"
191+
Scanned 1 files, found 92 errors in 1 files ((99 ms))"
193192
`;
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`CLI Formatter: html should have stdout output with formatter html 1`] = `
4-
"<html><head><title>HTML Hint Violation Report</title></head><body><center><h2>Violation Report</h2></center><table border=\\"1\\"><tr><th>Number#</th><th>File Name</th><th>Line Number</th><th>Message</th></tr><tr><td>1</td><td><PROJECT_ROOT>/src/cli/formatters/__fixtures__/example.html</td><td>8</td><td>The value of attribute [ bad ] must be in double quotes.</td></tr><tr><td>2</td><td><PROJECT_ROOT>/src/cli/formatters/__fixtures__/example.html</td><td>8</td><td>The value of attribute [ bad ] must be in double quotes.</td></tr><tr><td>3</td><td><PROJECT_ROOT>/src/cli/formatters/__fixtures__/example.html</td><td>8</td><td>Duplicate of attribute name [ bad ] was found.</td></tr><tr><td>4</td><td><PROJECT_ROOT>/src/cli/formatters/__fixtures__/example.html</td><td>9</td><td>The value of attribute [ bad ] must be in double quotes.</td></tr><tr><td>5</td><td><PROJECT_ROOT>/src/cli/formatters/__fixtures__/example.html</td><td>9</td><td>The value of attribute [ bad ] must be in double quotes.</td></tr><tr><td>6</td><td><PROJECT_ROOT>/src/cli/formatters/__fixtures__/example.html</td><td>9</td><td>Duplicate of attribute name [ bad ] was found.</td></tr><tr><td>7</td><td><PROJECT_ROOT>/src/cli/formatters/__fixtures__/example.html</td><td>10</td><td>Tag must be paired, no start tag: [ </input> ]</td></tr><tr><td>8</td><td><PROJECT_ROOT>/src/cli/formatters/__fixtures__/example.html</td><td>11</td><td>Special characters must be escaped : [ < ].</td></tr><tr><td>9</td><td><PROJECT_ROOT>/src/cli/formatters/__fixtures__/example.html</td><td>11</td><td>Special characters must be escaped : [ > ].</td></tr><tr><td>10</td><td><PROJECT_ROOT>/src/cli/formatters/__fixtures__/example.html</td><td>13</td><td>Tag must be paired, no start tag: [ </div> ]</td></tr><tr><td>11</td><td><PROJECT_ROOT>/src/cli/formatters/__fixtures__/example.html</td><td>14</td><td>Tag must be paired, no start tag: [ </div> ]</td></tr><tr><td>12</td><td><PROJECT_ROOT>/src/cli/formatters/__fixtures__/example.html</td><td>15</td><td>Tag must be paired, no start tag: [ </hello> ]</td></tr><tr><td>13</td><td><PROJECT_ROOT>/src/cli/formatters/__fixtures__/example.html</td><td>16</td><td>Tag must be paired, no start tag: [ </test> ]</td></tr><tr><td>14</td><td><PROJECT_ROOT>/src/cli/formatters/__fixtures__/example.html</td><td>17</td><td>Tag must be paired, no start tag: [ </div> ]</td></tr><tr><td>15</td><td><PROJECT_ROOT>/src/cli/formatters/__fixtures__/example.html</td><td>21</td><td>The value of attribute [ class ] must be in double quotes.</td></tr><tr><td>16</td><td><PROJECT_ROOT>/src/cli/formatters/__fixtures__/example.html</td><td>21</td><td>The value of attribute [ what ] must be in double quotes.</td></tr><tr><td>17</td><td><PROJECT_ROOT>/src/cli/formatters/__fixtures__/example.html</td><td>21</td><td>The value of attribute [ something ] must be in double quotes.</td></tr><tr><td>18</td><td><PROJECT_ROOT>/src/cli/formatters/__fixtures__/example.html</td><td>25</td><td>Tag must be paired, no start tag: [ </div> ]</td></tr><tr><td>19</td><td><PROJECT_ROOT>/src/cli/formatters/__fixtures__/example.html</td><td>26</td><td>Tag must be paired, no start tag: [ </bad> ]</td></tr><tr><td>20</td><td><PROJECT_ROOT>/src/cli/formatters/__fixtures__/example.html</td><td>27</td><td>Tag must be paired, no start tag: [ </bad> ]</td></tr></table></body></html>
5-
"
6-
`;
3+
exports[`CLI Formatter: html should have stdout output with formatter html 1`] = `"<html><head><title>HTML Hint Violation Report</title></head><body><center><h2>Violation Report</h2></center><table border=\\"1\\"><tr><th>Number#</th><th>File Name</th><th>Line Number</th><th>Message</th></tr><tr><td>1</td><td><PROJECT_ROOT>/src/cli/formatters/__fixtures__/example.html</td><td>8</td><td>The value of attribute [ bad ] must be in double quotes.</td></tr><tr><td>2</td><td><PROJECT_ROOT>/src/cli/formatters/__fixtures__/example.html</td><td>8</td><td>The value of attribute [ bad ] must be in double quotes.</td></tr><tr><td>3</td><td><PROJECT_ROOT>/src/cli/formatters/__fixtures__/example.html</td><td>8</td><td>Duplicate of attribute name [ bad ] was found.</td></tr><tr><td>4</td><td><PROJECT_ROOT>/src/cli/formatters/__fixtures__/example.html</td><td>9</td><td>The value of attribute [ bad ] must be in double quotes.</td></tr><tr><td>5</td><td><PROJECT_ROOT>/src/cli/formatters/__fixtures__/example.html</td><td>9</td><td>The value of attribute [ bad ] must be in double quotes.</td></tr><tr><td>6</td><td><PROJECT_ROOT>/src/cli/formatters/__fixtures__/example.html</td><td>9</td><td>Duplicate of attribute name [ bad ] was found.</td></tr><tr><td>7</td><td><PROJECT_ROOT>/src/cli/formatters/__fixtures__/example.html</td><td>10</td><td>Tag must be paired, no start tag: [ </input> ]</td></tr><tr><td>8</td><td><PROJECT_ROOT>/src/cli/formatters/__fixtures__/example.html</td><td>11</td><td>Special characters must be escaped : [ < ].</td></tr><tr><td>9</td><td><PROJECT_ROOT>/src/cli/formatters/__fixtures__/example.html</td><td>11</td><td>Special characters must be escaped : [ > ].</td></tr><tr><td>10</td><td><PROJECT_ROOT>/src/cli/formatters/__fixtures__/example.html</td><td>13</td><td>Tag must be paired, no start tag: [ </div> ]</td></tr><tr><td>11</td><td><PROJECT_ROOT>/src/cli/formatters/__fixtures__/example.html</td><td>14</td><td>Tag must be paired, no start tag: [ </div> ]</td></tr><tr><td>12</td><td><PROJECT_ROOT>/src/cli/formatters/__fixtures__/example.html</td><td>15</td><td>Tag must be paired, no start tag: [ </hello> ]</td></tr><tr><td>13</td><td><PROJECT_ROOT>/src/cli/formatters/__fixtures__/example.html</td><td>16</td><td>Tag must be paired, no start tag: [ </test> ]</td></tr><tr><td>14</td><td><PROJECT_ROOT>/src/cli/formatters/__fixtures__/example.html</td><td>17</td><td>Tag must be paired, no start tag: [ </div> ]</td></tr><tr><td>15</td><td><PROJECT_ROOT>/src/cli/formatters/__fixtures__/example.html</td><td>21</td><td>The value of attribute [ class ] must be in double quotes.</td></tr><tr><td>16</td><td><PROJECT_ROOT>/src/cli/formatters/__fixtures__/example.html</td><td>21</td><td>The value of attribute [ what ] must be in double quotes.</td></tr><tr><td>17</td><td><PROJECT_ROOT>/src/cli/formatters/__fixtures__/example.html</td><td>21</td><td>The value of attribute [ something ] must be in double quotes.</td></tr><tr><td>18</td><td><PROJECT_ROOT>/src/cli/formatters/__fixtures__/example.html</td><td>25</td><td>Tag must be paired, no start tag: [ </div> ]</td></tr><tr><td>19</td><td><PROJECT_ROOT>/src/cli/formatters/__fixtures__/example.html</td><td>26</td><td>Tag must be paired, no start tag: [ </bad> ]</td></tr><tr><td>20</td><td><PROJECT_ROOT>/src/cli/formatters/__fixtures__/example.html</td><td>27</td><td>Tag must be paired, no start tag: [ </bad> ]</td></tr></table></body></html>"`;

src/cli/formatters/__snapshots__/junit.spec.js.snap

+1-2
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,5 @@ L27 |</bad>
4747
^ Tag must be paired, no start tag: [ </bad> ] (tag-pair)]]></failure>
4848
</testcase>
4949
</testsuite>
50-
</testsuites>
51-
"
50+
</testsuites>"
5251
`;

src/cli/formatters/__snapshots__/markdown.spec.js.snap

-1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,5 @@ Found 20 errors, 0 warnings
4949
^ Tag must be paired, no start tag: [ </bad> ] (tag-pair)
5050
L27 |</bad>
5151
^ Tag must be paired, no start tag: [ </bad> ] (tag-pair)
52-
5352
"
5453
`;

src/cli/formatters/__snapshots__/unix.spec.js.snap

+1-2
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,5 @@ exports[`CLI Formatter: unix should have stdout output with formatter unix 1`] =
9494
<PROJECT_ROOT>/src/cli/__fixtures__/executable.html:96:1: Tag must be paired, no start tag: [ </bad> ] [error/tag-pair]
9595
<PROJECT_ROOT>/src/cli/__fixtures__/executable.html:97:1: Tag must be paired, no start tag: [ </bad> ] [error/tag-pair]
9696
97-
92 problems
98-
"
97+
92 problems"
9998
`;

src/cli/formatters/checkstyle.spec.js

+11-18
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,23 @@
1-
const ChildProcess = require('child_process')
1+
const run = require('../../../test/test-utils').run
22
const path = require('path')
33
const serializer = require('jest-serializer-path')
44

55
expect.addSnapshotSerializer(serializer)
66

77
describe('CLI', () => {
88
describe('Formatter: checkstyle', () => {
9-
it('should have stdout output with formatter checkstyle', (done) => {
10-
ChildProcess.exec(
11-
[
12-
'node',
13-
path.resolve(__dirname, '../../../bin/htmlhint'),
14-
path.resolve(__dirname, '__fixtures__', 'example.html'),
15-
'--format',
16-
'checkstyle',
17-
].join(' '),
18-
(error, stdout, stderr) => {
19-
expect(typeof error).toBe('object')
20-
expect(error.code).toBe(1)
9+
it('should have stdout output with formatter checkstyle', async () => {
10+
const { exitCode, stdout, stderr } = await run(__dirname, [
11+
path.resolve(__dirname, '__fixtures__', 'example.html'),
12+
'--format',
13+
'checkstyle',
14+
])
2115

22-
expect(stdout).toMatchSnapshot()
16+
expect(exitCode).toBe(1)
2317

24-
expect(stderr).toBe('')
25-
done()
26-
}
27-
)
18+
expect(stdout).toMatchSnapshot()
19+
20+
expect(stderr).toBe('')
2821
})
2922
})
3023
})

src/cli/formatters/compact.spec.js

+10-18
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,22 @@
1-
const ChildProcess = require('child_process')
1+
const run = require('../../../test/test-utils').run
22
const path = require('path')
33
const serializer = require('jest-serializer-path')
44

55
expect.addSnapshotSerializer(serializer)
66

77
describe('CLI', () => {
88
describe('Formatter: compact', () => {
9-
it('should have stdout output with formatter compact', (done) => {
10-
ChildProcess.exec(
11-
[
12-
'node',
13-
path.resolve(__dirname, '../../../bin/htmlhint'),
14-
path.resolve(__dirname, '..', '__fixtures__', 'executable.html'),
15-
'--format',
16-
'compact',
17-
].join(' '),
18-
(error, stdout, stderr) => {
19-
expect(typeof error).toBe('object')
20-
expect(error.code).toBe(1)
9+
it('should have stdout output with formatter compact', async () => {
10+
const { exitCode, stdout, stderr } = await run(__dirname, [
11+
path.resolve(__dirname, '..', '__fixtures__', 'executable.html'),
12+
'--format',
13+
'compact',
14+
])
15+
expect(exitCode).toBe(1)
2116

22-
expect(stdout).toMatchSnapshot()
17+
expect(stdout).toMatchSnapshot()
2318

24-
expect(stderr).toBe('')
25-
done()
26-
}
27-
)
19+
expect(stderr).toBe('')
2820
})
2921
})
3022
})

src/cli/formatters/default.spec.js

+9-16
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,21 @@
1-
const ChildProcess = require('child_process')
1+
const run = require('../../../test/test-utils').run
22
const path = require('path')
33
const serializer = require('jest-serializer-path')
44

55
expect.addSnapshotSerializer(serializer)
66

77
describe('CLI', () => {
88
describe('Formatter: default', () => {
9-
it('should have stdout output with formatter default', (done) => {
10-
ChildProcess.exec(
11-
[
12-
'node',
13-
path.resolve(__dirname, '../../../bin/htmlhint'),
14-
path.resolve(__dirname, '..', '__fixtures__', 'executable.html'),
15-
].join(' '),
16-
(error, stdout, stderr) => {
17-
expect(typeof error).toBe('object')
18-
expect(error.code).toBe(1)
9+
it('should have stdout output with formatter default', async () => {
10+
const { exitCode, stdout, stderr } = await run(__dirname, [
11+
path.resolve(__dirname, '..', '__fixtures__', 'executable.html'),
12+
])
1913

20-
expect(stdout.replace(/(\d+ ms)/, '(99 ms)')).toMatchSnapshot()
14+
expect(exitCode).toBe(1)
2115

22-
expect(stderr).toBe('')
23-
done()
24-
}
25-
)
16+
expect(stdout.replace(/(\d+ ms)/, '(99 ms)')).toMatchSnapshot()
17+
18+
expect(stderr).toBe('')
2619
})
2720
})
2821
})

src/cli/formatters/html.spec.js

+11-18
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,23 @@
1-
const ChildProcess = require('child_process')
1+
const run = require('../../../test/test-utils').run
22
const path = require('path')
33
const serializer = require('jest-serializer-path')
44

55
expect.addSnapshotSerializer(serializer)
66

77
describe('CLI', () => {
88
describe('Formatter: html', () => {
9-
it('should have stdout output with formatter html', (done) => {
10-
ChildProcess.exec(
11-
[
12-
'node',
13-
path.resolve(__dirname, '../../../bin/htmlhint'),
14-
path.resolve(__dirname, '__fixtures__', 'example.html'),
15-
'--format',
16-
'html',
17-
].join(' '),
18-
(error, stdout, stderr) => {
19-
expect(typeof error).toBe('object')
20-
expect(error.code).toBe(1)
9+
it('should have stdout output with formatter html', async () => {
10+
const { exitCode, stdout, stderr } = await run(__dirname, [
11+
path.resolve(__dirname, '__fixtures__', 'example.html'),
12+
'--format',
13+
'html',
14+
])
2115

22-
expect(stdout).toMatchSnapshot()
16+
expect(exitCode).toBe(1)
2317

24-
expect(stderr).toBe('')
25-
done()
26-
}
27-
)
18+
expect(stdout).toMatchSnapshot()
19+
20+
expect(stderr).toBe('')
2821
})
2922
})
3023
})

src/cli/formatters/json.spec.js

+13-20
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,25 @@
1-
const ChildProcess = require('child_process')
1+
const run = require('../../../test/test-utils').run
22
const path = require('path')
33
const serializer = require('jest-serializer-path')
44

55
expect.addSnapshotSerializer(serializer)
66

77
describe('CLI', () => {
88
describe('Formatter: json', () => {
9-
it('should have stdout output with formatter json', (done) => {
10-
ChildProcess.exec(
11-
[
12-
'node',
13-
path.resolve(__dirname, '../../../bin/htmlhint'),
14-
path.resolve(__dirname, '__fixtures__', 'example.html'),
15-
'--format',
16-
'json',
17-
].join(' '),
18-
(error, stdout, stderr) => {
19-
expect(typeof error).toBe('object')
20-
expect(error.code).toBe(1)
9+
it('should have stdout output with formatter json', async () => {
10+
const { exitCode, stdout, stderr } = await run(__dirname, [
11+
path.resolve(__dirname, '__fixtures__', 'example.html'),
12+
'--format',
13+
'json',
14+
])
2115

22-
expect(
23-
JSON.parse(stdout.replace(/"time":\d+/, '"time":99'))
24-
).toMatchSnapshot()
16+
expect(exitCode).toBe(1)
2517

26-
expect(stderr).toBe('')
27-
done()
28-
}
29-
)
18+
expect(
19+
JSON.parse(stdout.replace(/"time":\d+/, '"time":99'))
20+
).toMatchSnapshot()
21+
22+
expect(stderr).toBe('')
3023
})
3124
})
3225
})

src/cli/formatters/junit.spec.js

+12-20
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,24 @@
1-
const ChildProcess = require('child_process')
1+
const run = require('../../../test/test-utils').run
22
const path = require('path')
33
const serializer = require('jest-serializer-path')
44

55
expect.addSnapshotSerializer(serializer)
66

77
describe('CLI', () => {
88
describe('Formatter: junit', () => {
9-
it('should have stdout output with formatter junit', (done) => {
10-
ChildProcess.exec(
11-
[
12-
'node',
13-
path.resolve(__dirname, '../../../bin/htmlhint'),
14-
path.resolve(__dirname, '__fixtures__', 'example.html'),
15-
'--format',
16-
'junit',
17-
].join(' '),
18-
(error, stdout, stderr) => {
19-
expect(typeof error).toBe('object')
20-
expect(error.code).toBe(1)
9+
it('should have stdout output with formatter junit', async () => {
10+
const { exitCode, stdout, stderr } = await run(__dirname, [
11+
path.resolve(__dirname, '__fixtures__', 'example.html'),
12+
'--format',
13+
'junit',
14+
])
15+
expect(exitCode).toBe(1)
2116

22-
expect(
23-
stdout.replace(/time="\d+\.\d+"/g, 'time="0.999"')
24-
).toMatchSnapshot()
17+
expect(
18+
stdout.replace(/time="\d+\.\d+"/g, 'time="0.999"')
19+
).toMatchSnapshot()
2520

26-
expect(stderr).toBe('')
27-
done()
28-
}
29-
)
21+
expect(stderr).toBe('')
3022
})
3123
})
3224
})

src/cli/formatters/markdown.spec.js

+10-18
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,22 @@
1-
const ChildProcess = require('child_process')
1+
const run = require('../../../test/test-utils').run
22
const path = require('path')
33
const serializer = require('jest-serializer-path')
44

55
expect.addSnapshotSerializer(serializer)
66

77
describe('CLI', () => {
88
describe('Formatter: markdown', () => {
9-
it('should have stdout output with formatter markdown', (done) => {
10-
ChildProcess.exec(
11-
[
12-
'node',
13-
path.resolve(__dirname, '../../../bin/htmlhint'),
14-
path.resolve(__dirname, '__fixtures__', 'example.html'),
15-
'--format',
16-
'markdown',
17-
].join(' '),
18-
(error, stdout, stderr) => {
19-
expect(typeof error).toBe('object')
20-
expect(error.code).toBe(1)
9+
it('should have stdout output with formatter markdown', async () => {
10+
const { exitCode, stdout, stderr } = await run(__dirname, [
11+
path.resolve(__dirname, '__fixtures__', 'example.html'),
12+
'--format',
13+
'markdown',
14+
])
15+
expect(exitCode).toBe(1)
2116

22-
expect(stdout).toMatchSnapshot()
17+
expect(stdout).toMatchSnapshot()
2318

24-
expect(stderr).toBe('')
25-
done()
26-
}
27-
)
19+
expect(stderr).toBe('')
2820
})
2921
})
3022
})

0 commit comments

Comments
 (0)