Add tests for github actions problem matchers (#64)

bae9638 · Blake Kostner · 2021-07-27 16:50

3 files +64 -1

Files changed

added __tests__/problem-matchers.test.js
+63 −0
@@ -0,0 +1,63 @@
1 +const assert = require('assert')
2 +const { problemMatcher } = require('../.github/elixir-matchers.json')
3 +
4 +async function all() {
5 + await testElixirMixCompileError()
6 + await testElixirMixCompileWarning()
7 + await testElixirMixTestFailure()
8 +}
9 +
10 +async function testElixirMixCompileError() {
11 + const [matcher] = problemMatcher.find(
12 + ({ owner }) => owner === 'elixir-mixCompileError',
13 + ).pattern
14 +
15 + const output = '** (CompileError) lib/test.ex:16: undefined function err/0'
16 + const [message, , file, line] = output.match(matcher.regexp)
17 + assert.equal(file, 'lib/test.ex')
18 + assert.equal(line, '16')
19 + assert.equal(message, output)
20 +}
21 +
22 +async function testElixirMixCompileWarning() {
23 + const [messagePattern, filePattern] = problemMatcher.find(
24 + ({ owner }) => owner === 'elixir-mixCompileWarning',
25 + ).pattern
26 +
27 + const firstOutput =
28 + 'warning: variable "err" does not exist and is being expanded to "err()"'
29 + const secondOutput = ' lib/test.ex:16: Test.hello/0'
30 +
31 + const [, message] = firstOutput.match(messagePattern.regexp)
32 + assert.equal(
33 + message,
34 + 'variable "err" does not exist and is being expanded to "err()"',
35 + )
36 +
37 + const [, file, line] = secondOutput.match(filePattern.regexp)
38 + assert.equal(file, 'lib/test.ex')
39 + assert.equal(line, '16')
40 +}
41 +
42 +async function testElixirMixTestFailure() {
43 + const [messagePattern, filePattern] = problemMatcher.find(
44 + ({ owner }) => owner === 'elixir-mixTestFailure',
45 + ).pattern
46 +
47 + const firstOutput = '1) test throws (TestTest)'
48 + const secondOutput = ' test/test_test.exs:9'
49 +
50 + const [, message] = firstOutput.match(messagePattern.regexp)
51 + assert.equal(message, 'test throws (TestTest)')
52 +
53 + const [, file, line] = secondOutput.match(filePattern.regexp)
54 + assert.equal(file, 'test/test_test.exs')
55 + assert.equal(line, '9')
56 +}
57 +
58 +all()
59 + .then(() => process.exit(0))
60 + .catch((err) => {
61 + console.error(err)
62 + process.exit(1)
63 + })
modified package.json
+1 −1
@@ -9,7 +9,7 @@
9 9 "licenses": "yarn licenses generate-disclaimer > 3RD_PARTY_LICENSES",
10 10 "markdownlint": "markdownlint *.md",
11 11 "shellcheck": "shellcheck src/install-*.sh",
12 "test": "node __tests__/setup-beam.test.js",
12 + "test": "node __tests__/setup-beam.test.js && node ./__tests__/problem-matchers.test.js",
13 13 "yamllint": "yamllint .github/workflows/**.yml && yamllint .*.yml && yamllint *.yml"
14 14 },
15 15 "husky": {

Parents: 14d4bc3