From 6ce15941c69f3ebb16275455e66ac0ee30f05eb0 Mon Sep 17 00:00:00 2001 From: Phil Phillips Date: Tue, 20 Sep 2022 23:18:04 -0500 Subject: [PATCH 1/2] feat: add option to only post failures --- jest/reporter.js | 1 + 1 file changed, 1 insertion(+) diff --git a/jest/reporter.js b/jest/reporter.js index b931fde..fde9a54 100644 --- a/jest/reporter.js +++ b/jest/reporter.js @@ -34,6 +34,7 @@ class JestBuildkiteAnalyticsReporter { const prefixedTestPath = this._paths.prefixTestPath(testResult.testFilePath); testResult.testResults.forEach((result) => { + if (this._options.failuresOnly && result.status !== 'failed') return let id = uuidv4() this._testResults.push({ 'id': id, From 4f932214c8aff28eda0bd82e161442381ca6b6d4 Mon Sep 17 00:00:00 2001 From: Phil Phillips Date: Fri, 11 Nov 2022 23:29:04 -0600 Subject: [PATCH 2/2] test: add test case for jest collector failuresOnly option --- e2e/jest.test.js | 19 +++++++++++++++++++ examples/jest/failuresOnly.config.js | 12 ++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 examples/jest/failuresOnly.config.js diff --git a/e2e/jest.test.js b/e2e/jest.test.js index ff8c728..b5b7095 100644 --- a/e2e/jest.test.js +++ b/e2e/jest.test.js @@ -112,4 +112,23 @@ describe('examples/jest', () => { done() }) }, 10000) // 10s timeout + + describe('when failuresOnly is true in reporter options', () => { + test('skips uploads for successful tests', (done) => { + exec('jest --config failuresOnly.config.js', { cwd, env }, (error, stdout, stderr) => { + expect(stdout).toMatch(/.*Test Analytics Sending: ({.*})/m); + + const jsonMatch = stdout.match(/.*Test Analytics Sending: ({.*})/m) + const json = JSON.parse(jsonMatch[1])["data"] + + // Uncomment to view the JSON + // console.log(json) + + expect(json.data.length).toBe(1) + expect(json.data[0].result).toBe("failed") + + done() + }) + }, 10000) // 10s timeout + }) }) diff --git a/examples/jest/failuresOnly.config.js b/examples/jest/failuresOnly.config.js new file mode 100644 index 0000000..99fdbb5 --- /dev/null +++ b/examples/jest/failuresOnly.config.js @@ -0,0 +1,12 @@ +const config = { + // Send results to Test Analytics + reporters: [ + 'default', + ['buildkite-test-collector/jest/reporter', { failuresOnly: true }] + ], + + // Enable column + line capture for Test Analytics + testLocationInResults: true +}; + +module.exports = config;