• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1namespace ts {
2    describe("unittests:: debugDeprecation", () => {
3        beforeEach(() => {
4            const loggingHost = Debug.loggingHost;
5            afterEach(() => {
6                Debug.loggingHost = loggingHost;
7            });
8        });
9        describe("deprecateFunction", () => {
10            it("silent deprecation", () => {
11                const deprecation = Debug.deprecate(noop, {
12                    warnAfter: "3.9",
13                    typeScriptVersion: "3.8"
14                });
15                let logWritten = false;
16                Debug.loggingHost = { log() { logWritten = true; } };
17                deprecation();
18                assert.isFalse(logWritten);
19            });
20            it("warning deprecation with warnAfter", () => {
21                const deprecation = Debug.deprecate(noop, {
22                    warnAfter: "3.9",
23                    typeScriptVersion: "3.9"
24                });
25                let logWritten = false;
26                Debug.loggingHost = { log() { logWritten = true; } };
27                deprecation();
28                assert.isTrue(logWritten);
29            });
30            it("warning deprecation without warnAfter", () => {
31                const deprecation = Debug.deprecate(noop, {
32                    typeScriptVersion: "3.9"
33                });
34                let logWritten = false;
35                Debug.loggingHost = { log() { logWritten = true; } };
36                deprecation();
37                assert.isTrue(logWritten);
38            });
39            it("warning deprecation writes once", () => {
40                const deprecation = Debug.deprecate(noop, {
41                    typeScriptVersion: "3.9"
42                });
43                let logWrites = 0;
44                Debug.loggingHost = { log() { logWrites++; } };
45                deprecation();
46                deprecation();
47                assert.equal(logWrites, 1);
48            });
49            it("error deprecation with errorAfter", () => {
50                const deprecation = Debug.deprecate(noop, {
51                    warnAfter: "3.8",
52                    errorAfter: "3.9",
53                    typeScriptVersion: "3.9"
54                });
55                let logWritten = false;
56                Debug.loggingHost = { log() { logWritten = true; } };
57                expect(deprecation).throws();
58                assert.isFalse(logWritten);
59            });
60            it("error deprecation with error", () => {
61                const deprecation = Debug.deprecate(noop, {
62                    error: true,
63                });
64                let logWritten = false;
65                Debug.loggingHost = { log() { logWritten = true; } };
66                expect(deprecation).throws();
67                assert.isFalse(logWritten);
68            });
69        });
70    });
71}