diff --git a/CHANGELOG.md b/CHANGELOG.md index 1901bfbd2..432f7f0b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). Please see [CONTRIBUTING.md](./CONTRIBUTING.md) on how to contribute to Cucumber. ## [Unreleased] +- Perform dynamic imports in parallel using Promise.all instead of sequentially by awaiting in a loop ([#2263](https://github.com/cucumber/cucumber-js/pull/2263)) ## [9.0.1] - 2023-03-15 ### Fixed diff --git a/src/api/support.ts b/src/api/support.ts index 87358260a..0c8fb4f84 100644 --- a/src/api/support.ts +++ b/src/api/support.ts @@ -19,15 +19,19 @@ export async function getSupportCodeLibrary({ requirePaths: string[] importPaths: string[] }): Promise { + const importPromises: Array> = [] + supportCodeLibraryBuilder.reset(cwd, newId, { requireModules, requirePaths, importPaths, }) + requireModules.map((module) => require(module)) requirePaths.map((path) => require(path)) - for (const path of importPaths) { - await importer(pathToFileURL(path)) - } + importPaths.map((path) => importPromises.push(importer(pathToFileURL(path)))) + + await Promise.all(importPromises) + return supportCodeLibraryBuilder.finalize() }