-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathwarnings.test.ts
36 lines (31 loc) · 1.39 KB
/
warnings.test.ts
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
import { DiagnosticCategory } from 'typescript';
import { Code, JsiiDiagnostic } from '../src/jsii-diagnostic';
import { JsiiError } from '../src/utils';
import { enabledWarnings, silenceWarnings } from '../src/warnings';
describe('enabledWarnings', () => {
test('contains all available Jsii warnings', () => {
const definedWarnings = Object.keys(JsiiDiagnostic).reduce((warnings, warningKey) => {
const code = JsiiDiagnostic[warningKey as keyof typeof JsiiDiagnostic];
if (code instanceof Code && code.category === DiagnosticCategory.Warning) {
warnings[code.name] = true;
}
return warnings;
}, {} as { [name: string]: boolean });
expect(enabledWarnings).toStrictEqual(definedWarnings);
});
});
describe('silenceWarnings', () => {
test('sets enabledWarnings key to false', () => {
expect(enabledWarnings['metadata/missing-readme']).toBe(true);
silenceWarnings(['metadata/missing-readme']);
expect(enabledWarnings['metadata/missing-readme']).toBe(false);
});
test('translates legacy key to current Code.name', () => {
expect(enabledWarnings['language-compatibility/reserved-word']).toBe(true);
silenceWarnings(['reserved-word']);
expect(enabledWarnings['language-compatibility/reserved-word']).toBe(false);
});
test('throws when key is not valid', () => {
expect(() => silenceWarnings(['invalid-warning'])).toThrow(JsiiError);
});
});