|
| 1 | +import { getTestStdout, mockActionsCoreLogging } from './helpers' |
| 2 | +import { parseTestEvents } from '../src/events' |
| 3 | + |
| 4 | +describe('events', () => { |
| 5 | + beforeEach(() => { |
| 6 | + mockActionsCoreLogging() |
| 7 | + }) |
| 8 | + |
| 9 | + it('correctly parses test2json output', async () => { |
| 10 | + const stdout = await getTestStdout() |
| 11 | + |
| 12 | + const testsEvents = parseTestEvents(stdout) |
| 13 | + |
| 14 | + expect(testsEvents).toHaveLength(59) |
| 15 | + expect(testsEvents[58]).toEqual({ |
| 16 | + time: new Date('2022-07-11T02:42:12.111Z'), |
| 17 | + action: 'fail', |
| 18 | + package: 'github.com/robherley/go-test-example/boom', |
| 19 | + test: undefined, |
| 20 | + elapsed: 0.103, |
| 21 | + output: undefined, |
| 22 | + isCached: false, |
| 23 | + isSubtest: false, |
| 24 | + isPackageLevel: true, |
| 25 | + isConclusive: true, |
| 26 | + }) |
| 27 | + }) |
| 28 | + |
| 29 | + it('correctly indicates a package level test', () => { |
| 30 | + const packageLevelStdout = |
| 31 | + '{"Time":"2022-07-10T22:42:11.92576-04:00","Action":"output","Package":"github.com/robherley/go-test-example","Output":"? \\tgithub.com/robherley/go-test-example\\t[no test files]\\n"}' |
| 32 | + |
| 33 | + const packageLevelTestEvents = parseTestEvents(packageLevelStdout) |
| 34 | + expect(packageLevelTestEvents[0]).toHaveProperty('isPackageLevel', true) |
| 35 | + |
| 36 | + const otherStdout = |
| 37 | + '{"Time":"2022-07-10T22:42:12.108346-04:00","Action":"output","Package":"github.com/robherley/go-test-example/boom","Test":"TestFatal","Output":"=== RUN TestFatal\\n"}' |
| 38 | + |
| 39 | + const otherTestEvents = parseTestEvents(otherStdout) |
| 40 | + expect(otherTestEvents[0]).toHaveProperty('isPackageLevel', false) |
| 41 | + }) |
| 42 | + |
| 43 | + it('correctly indicates a subtest', () => { |
| 44 | + const subTestStdout = |
| 45 | + '{"Time":"2022-07-10T22:42:11.9313-04:00","Action":"output","Package":"github.com/robherley/go-test-example/success","Test":"TestSuccess/Subtest(2)","Output":" success_test.go:19: hello from subtest #2\\n"}' |
| 46 | + |
| 47 | + const subTestEvents = parseTestEvents(subTestStdout) |
| 48 | + expect(subTestEvents[0]).toHaveProperty('isSubtest', true) |
| 49 | + |
| 50 | + const topLevelTestStdout = |
| 51 | + '{"Time":"2022-07-10T22:42:11.931141-04:00","Action":"output","Package":"github.com/robherley/go-test-example/success","Test":"TestSuccess","Output":"=== RUN TestSuccess\\n"}' |
| 52 | + |
| 53 | + const topLevelTestEvents = parseTestEvents(topLevelTestStdout) |
| 54 | + expect(topLevelTestEvents[0]).toHaveProperty('isSubtest', false) |
| 55 | + }) |
| 56 | + |
| 57 | + it('correctly indicates conclusive tests', () => { |
| 58 | + const getStdout = (action: string) => |
| 59 | + `{"Time":"2022-07-10T22:42:12.108414-04:00","Action":"${action}","Package":"github.com/robherley/go-test-example/boom","Test":"TestFatal","Elapsed":0}` |
| 60 | + |
| 61 | + const testCases: [string, boolean][] = [ |
| 62 | + ['run', false], |
| 63 | + ['pause', false], |
| 64 | + ['cont', false], |
| 65 | + ['bench', false], |
| 66 | + ['output', false], |
| 67 | + ['pass', true], |
| 68 | + ['fail', true], |
| 69 | + ['skip', true], |
| 70 | + ] |
| 71 | + |
| 72 | + for (let [action, isConclusive] of testCases) { |
| 73 | + const stdout = getStdout(action) |
| 74 | + const testEvents = parseTestEvents(stdout) |
| 75 | + expect(testEvents[0]).toHaveProperty('isConclusive', isConclusive) |
| 76 | + } |
| 77 | + }) |
| 78 | + |
| 79 | + it('correctly indicates a cached test', () => { |
| 80 | + const cachedStdout = |
| 81 | + '{"Time":"2022-07-10T22:42:11.931552-04:00","Action":"output","Package":"github.com/robherley/go-test-example/success","Output":"ok \\tgithub.com/robherley/go-test-example/success\\t(cached)\\n"}' |
| 82 | + |
| 83 | + const cachedTestEvents = parseTestEvents(cachedStdout) |
| 84 | + expect(cachedTestEvents[0]).toHaveProperty('isCached', true) |
| 85 | + |
| 86 | + const otherStdout = |
| 87 | + '{"Time":"2022-07-10T22:42:11.931552-04:00","Action":"output","Package":"github.com/robherley/go-test-example/success","Output":"ok \\tgithub.com/robherley/go-test-example/success"}' |
| 88 | + |
| 89 | + const otherTestEvents = parseTestEvents(otherStdout) |
| 90 | + expect(otherTestEvents[0]).toHaveProperty('isCached', false) |
| 91 | + }) |
| 92 | +}) |
0 commit comments