-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathInvalidJsdocError.test.mjs
174 lines (153 loc) · 4.59 KB
/
InvalidJsdocError.test.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
import { strictEqual, throws } from "assert";
import kleur from "kleur";
import revertableGlobals from "revertable-globals";
import snapshot from "snapshot-assertion";
import CliError from "./CliError.mjs";
import CodeLocation from "./CodeLocation.mjs";
import CodePosition from "./CodePosition.mjs";
import InvalidJsdocError from "./InvalidJsdocError.mjs";
export default (tests) => {
tests.add(
"`InvalidJsdocError` with argument 1 `message` not a string.",
() => {
throws(() => {
new InvalidJsdocError(true);
}, new TypeError("Argument 1 `message` must be a string."));
}
);
tests.add(
"`InvalidJsdocError` with argument 2 `codeFileLocation` not an object.",
() => {
throws(() => {
new InvalidJsdocError("a", true);
}, new TypeError("Argument 2 `codeFileLocation` must be an object."));
}
);
tests.add(
"`InvalidJsdocError` with argument 2 `codeFileLocation` property `filePath` not a string.",
() => {
throws(() => {
new InvalidJsdocError("a", {});
}, new TypeError("Argument 2 `codeFileLocation` property `filePath` must be a string."));
}
);
tests.add(
"`InvalidJsdocError` with argument 2 `codeFileLocation` property `codeLocation` not a `CodeLocation` instance.",
() => {
throws(() => {
new InvalidJsdocError("a", {
filePath: "/a.js",
codeLocation: true,
});
}, new TypeError("Argument 2 `codeFileLocation` property `codeLocation` must be a `CodeLocation` instance."));
}
);
tests.add("`InvalidJsdocError` with argument 3 `code` not a string.", () => {
throws(() => {
new InvalidJsdocError(
"a",
{
filePath: "/a.js",
codeLocation: new CodeLocation(new CodePosition(1, 4)),
},
true
);
}, new TypeError("Argument 3 `code` must be a string."));
});
tests.add(
"`InvalidJsdocError` with code location end position, none.",
async () => {
const revertEnv = revertableGlobals({ FORCE_COLOR: "1" }, process.env);
const revertKleur = revertableGlobals({ enabled: true }, kleur);
let error;
try {
error = new InvalidJsdocError(
"Message.",
{
filePath: "/a.js",
codeLocation: new CodeLocation(new CodePosition(1, 4)),
},
"/**@abc*/"
);
} finally {
revertEnv();
revertKleur();
}
strictEqual(error instanceof CliError, true);
strictEqual(error.name, "InvalidJsdocError");
await snapshot(
error.message,
new URL(
"./test/snapshots/InvalidJsdocError/code-location-end-position-none.ans",
import.meta.url
)
);
}
);
tests.add(
"`InvalidJsdocError` with code location end position, matching start.",
async () => {
const revertEnv = revertableGlobals({ FORCE_COLOR: "1" }, process.env);
const revertKleur = revertableGlobals({ enabled: true }, kleur);
let error;
try {
error = new InvalidJsdocError(
"Message.",
{
filePath: "/a.js",
codeLocation: new CodeLocation(
new CodePosition(1, 4),
new CodePosition(1, 4)
),
},
"/**@abc*/"
);
} finally {
revertEnv();
revertKleur();
}
strictEqual(error instanceof CliError, true);
strictEqual(error.name, "InvalidJsdocError");
await snapshot(
error.message,
new URL(
"./test/snapshots/InvalidJsdocError/code-location-end-position-matching-start.ans",
import.meta.url
)
);
}
);
tests.add(
"`InvalidJsdocError` with code location end position, beyond start.",
async () => {
const revertEnv = revertableGlobals({ FORCE_COLOR: "1" }, process.env);
const revertKleur = revertableGlobals({ enabled: true }, kleur);
let error;
try {
error = new InvalidJsdocError(
"Message.",
{
filePath: "/a.js",
codeLocation: new CodeLocation(
new CodePosition(1, 4),
new CodePosition(1, 7)
),
},
"/**@abc*/"
);
} finally {
revertEnv();
revertKleur();
}
strictEqual(error instanceof CliError, true);
strictEqual(error.name, "InvalidJsdocError");
await snapshot(
error.message,
new URL(
"./test/snapshots/InvalidJsdocError/code-location-end-position-beyond-start.ans",
import.meta.url
)
);
}
);
};