1 | const assert = require('assert')
|
2 |
|
3 | function assertErrorMessage(...args) {
|
4 | const report = args[0]
|
5 | let index
|
6 | let message
|
7 |
|
8 | if (args.length === 3) {
|
9 | index = args[1]
|
10 | message = args[2]
|
11 | } else {
|
12 | index = 0
|
13 | message = args[1]
|
14 | }
|
15 |
|
16 | const errorMessage = `Report should contain message with text "${message}" at ${index} pos. ${printReport(
|
17 | report
|
18 | )}`
|
19 | assert.ok(report.messages[index].message.includes(message), errorMessage)
|
20 | }
|
21 |
|
22 | function assertNoErrors(report) {
|
23 | assert.equal(report.errorCount, 0, `Report must not contain errors. ${printReport(report)}`)
|
24 | }
|
25 |
|
26 | function assertNoWarnings(report) {
|
27 | assert.equal(report.warningCount, 0, `Report must not contain warnings. ${printReport(report)}`)
|
28 | }
|
29 |
|
30 | function assertErrorCount(report, count) {
|
31 | assert.equal(
|
32 | report.errorCount,
|
33 | count,
|
34 | `Report must contains ${count} errors. ${printReport(report)}`
|
35 | )
|
36 | }
|
37 |
|
38 | function assertWarnsCount(report, count) {
|
39 | assert.equal(
|
40 | report.warningCount,
|
41 | count,
|
42 | `Report must contains ${count} warnings. ${printReport(report)}`
|
43 | )
|
44 | }
|
45 |
|
46 | function assertLineNumber(report, line) {
|
47 | assert.equal(report.line, line, `Report must be in line ${line}.`)
|
48 | }
|
49 |
|
50 | function printReport(report) {
|
51 | const messages = report.messages.map((i, index) => `${index + 1}. ${i.message}`)
|
52 | return ['Errors / Warnings:', ...messages, ''].join('\n' + ' '.repeat(8))
|
53 | }
|
54 |
|
55 | module.exports = {
|
56 | assertErrorMessage,
|
57 | assertNoWarnings,
|
58 | assertNoErrors,
|
59 | assertErrorCount,
|
60 | assertWarnsCount,
|
61 | assertLineNumber
|
62 | }
|