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; 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,