1namespace ts { 2 describe("unittests:: debugDeprecation", () => { 3 let loggingHost: LoggingHost | undefined; 4 beforeEach(() => { 5 loggingHost = Debug.loggingHost; 6 }); 7 afterEach(() => { 8 Debug.loggingHost = loggingHost; 9 loggingHost = undefined; 10 }); 11 describe("deprecateFunction", () => { 12 it("silent deprecation", () => { 13 const deprecation = Debug.deprecate(noop, { 14 warnAfter: "3.9", 15 typeScriptVersion: "3.8" 16 }); 17 let logWritten = false; 18 Debug.loggingHost = { 19 log() { 20 logWritten = true; 21 } 22 }; 23 deprecation(); 24 assert.isFalse(logWritten); 25 }); 26 it("warning deprecation with warnAfter", () => { 27 const deprecation = Debug.deprecate(noop, { 28 warnAfter: "3.9", 29 typeScriptVersion: "3.9" 30 }); 31 let logWritten = false; 32 Debug.loggingHost = { 33 log() { 34 logWritten = true; 35 } 36 }; 37 deprecation(); 38 assert.isTrue(logWritten); 39 }); 40 it("warning deprecation without warnAfter", () => { 41 const deprecation = Debug.deprecate(noop, { 42 typeScriptVersion: "3.9" 43 }); 44 let logWritten = false; 45 Debug.loggingHost = { 46 log() { 47 logWritten = true; 48 } 49 }; 50 deprecation(); 51 assert.isTrue(logWritten); 52 }); 53 it("warning deprecation writes once", () => { 54 const deprecation = Debug.deprecate(noop, { 55 typeScriptVersion: "3.9" 56 }); 57 let logWrites = 0; 58 Debug.loggingHost = { 59 log() { 60 logWrites++; 61 } 62 }; 63 deprecation(); 64 deprecation(); 65 assert.equal(logWrites, 1); 66 }); 67 it("error deprecation with errorAfter", () => { 68 const deprecation = Debug.deprecate(noop, { 69 warnAfter: "3.8", 70 errorAfter: "3.9", 71 typeScriptVersion: "3.9" 72 }); 73 let logWritten = false; 74 Debug.loggingHost = { 75 log() { 76 logWritten = true; 77 } 78 }; 79 expect(deprecation).throws(); 80 assert.isFalse(logWritten); 81 }); 82 it("error deprecation with error", () => { 83 const deprecation = Debug.deprecate(noop, { 84 error: true, 85 }); 86 let logWritten = false; 87 Debug.loggingHost = { 88 log() { 89 logWritten = true; 90 } 91 }; 92 expect(deprecation).throws(); 93 assert.isFalse(logWritten); 94 }); 95 }); 96 }); 97}