From aae0d3ac3498ece4673ec29277dc040234f9f643 Mon Sep 17 00:00:00 2001 From: Johannes Sjoberg Date: Sat, 1 Oct 2022 01:33:17 +0200 Subject: [PATCH] feat: Enable testResultsProcessor to be async (#13343) --- CHANGELOG.md | 2 ++ e2e/__tests__/testResultsProcessor.test.ts | 12 ++++++++++++ e2e/test-results-processor/processorAsync.js | 11 +++++++++++ packages/jest-core/src/runJest.ts | 2 +- 4 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 e2e/test-results-processor/processorAsync.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 4347af31ddfb..b4cdd3420be1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ### Features +- `[jest-core]` Enable testResultsProcessor to be async ([#13343](https://github.com/facebook/jest/pull/13343)) + ### Fixes ### Chore & Maintenance diff --git a/e2e/__tests__/testResultsProcessor.test.ts b/e2e/__tests__/testResultsProcessor.test.ts index 9c62291ba28a..9ee4b7fbf6b8 100644 --- a/e2e/__tests__/testResultsProcessor.test.ts +++ b/e2e/__tests__/testResultsProcessor.test.ts @@ -20,6 +20,18 @@ test('testResultsProcessor', () => { expect(json.processed).toBe(true); }); +test('testResultsProcessor async', () => { + const processorPath = path.resolve( + __dirname, + '../test-results-processor/processorAsync.js', + ); + const {json} = runWithJson('test-results-processor', [ + '--json', + `--testResultsProcessor=${processorPath}`, + ]); + expect(json.processed).toBe(true); +}); + test('testResultsProcessor written in ESM', () => { const processorPath = path.resolve( __dirname, diff --git a/e2e/test-results-processor/processorAsync.js b/e2e/test-results-processor/processorAsync.js new file mode 100644 index 000000000000..efe73f0b200e --- /dev/null +++ b/e2e/test-results-processor/processorAsync.js @@ -0,0 +1,11 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +module.exports = async function (results) { + results.processed = true; + return results; +}; diff --git a/packages/jest-core/src/runJest.ts b/packages/jest-core/src/runJest.ts index 7061d3d282e7..5f0d74cb25d1 100644 --- a/packages/jest-core/src/runJest.ts +++ b/packages/jest-core/src/runJest.ts @@ -99,7 +99,7 @@ const processResults = async ( const processor = await requireOrImportModule( testResultsProcessor, ); - runResults = processor(runResults); + runResults = await processor(runResults); } if (isJSON) { if (outputFile) {