From 7a808f981e7d7a7ff0441dd87f56fc739a6b973a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Lukas=20Spie=C3=9F?= <lumaxis@github.com>
Date: Tue, 16 Feb 2021 19:06:39 +0100
Subject: [PATCH] Add tests for tsc problem matcher

---
 __tests__/problem-matcher.test.ts | 43 +++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)
 create mode 100644 __tests__/problem-matcher.test.ts

diff --git a/__tests__/problem-matcher.test.ts b/__tests__/problem-matcher.test.ts
new file mode 100644
index 00000000..4bcfdd1b
--- /dev/null
+++ b/__tests__/problem-matcher.test.ts
@@ -0,0 +1,43 @@
+describe('problem matcher tests', () => {
+  it('tsc: matches TypeScript "pretty" error message', () => {
+    const [
+      {
+        pattern: [{regexp}]
+      }
+    ] = require('../.github/tsc.json').problemMatcher;
+    const exampleErrorMessage =
+      "lib/index.js:23:42 - error TS2345: Argument of type 'A' is not assignable to parameter of type 'B'.";
+
+    const match = exampleErrorMessage.match(new RegExp(regexp));
+    expect(match).not.toBeNull();
+    expect(match![1]).toEqual('lib/index.js');
+    expect(match![2]).toEqual('23');
+    expect(match![3]).toEqual('42');
+    expect(match![4]).toEqual('error');
+    expect(match![5]).toEqual('2345');
+    expect(match![6]).toEqual(
+      "Argument of type 'A' is not assignable to parameter of type 'B'."
+    );
+  });
+
+  it('tsc: matches TypeScript error message from log file', () => {
+    const [
+      {
+        pattern: [{regexp}]
+      }
+    ] = require('../.github/tsc.json').problemMatcher;
+    const exampleErrorMessage =
+      "lib/index.js(23,42): error TS2345: Argument of type 'A' is not assignable to parameter of type 'B'.";
+
+    const match = exampleErrorMessage.match(new RegExp(regexp));
+    expect(match).not.toBeNull();
+    expect(match![1]).toEqual('lib/index.js');
+    expect(match![2]).toEqual('23');
+    expect(match![3]).toEqual('42');
+    expect(match![4]).toEqual('error');
+    expect(match![5]).toEqual('2345');
+    expect(match![6]).toEqual(
+      "Argument of type 'A' is not assignable to parameter of type 'B'."
+    );
+  });
+});