Skip to content

Commit b19564b

Browse files
JakobJingleheimerruyadorno
authored andcommittedAug 22, 2022
test: refactor ESM tests to improve performance
PR-URL: #43784 Reviewed-By: Geoffrey Booth <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]>
1 parent 728e18e commit b19564b

File tree

56 files changed

+1390
-1442
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+1390
-1442
lines changed
 

‎lib/internal/modules/esm/loader.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ class ESMLoader {
336336
* A list of exports from user-defined loaders (as returned by
337337
* ESMLoader.import()).
338338
*/
339-
async addCustomLoaders(
339+
addCustomLoaders(
340340
customLoaders = [],
341341
) {
342342
for (let i = 0; i < customLoaders.length; i++) {

‎test/common/index.js

+32-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
const process = global.process; // Some tests tamper with the process global.
2525

2626
const assert = require('assert');
27-
const { exec, execSync, spawnSync } = require('child_process');
27+
const { exec, execSync, spawn, spawnSync } = require('child_process');
2828
const fs = require('fs');
2929
// Do not require 'os' until needed so that test-os-checked-function can
3030
// monkey patch it. If 'os' is required here, that test will fail.
@@ -842,6 +842,36 @@ function requireNoPackageJSONAbove(dir = __dirname) {
842842
}
843843
}
844844

845+
function spawnPromisified(...args) {
846+
let stderr = '';
847+
let stdout = '';
848+
849+
const child = spawn(...args);
850+
child.stderr.setEncoding('utf8');
851+
child.stderr.on('data', (data) => { stderr += data; });
852+
child.stdout.setEncoding('utf8');
853+
child.stdout.on('data', (data) => { stdout += data; });
854+
855+
return new Promise((resolve, reject) => {
856+
child.on('close', (code, signal) => {
857+
resolve({
858+
code,
859+
signal,
860+
stderr,
861+
stdout,
862+
});
863+
});
864+
child.on('error', (code, signal) => {
865+
reject({
866+
code,
867+
signal,
868+
stderr,
869+
stdout,
870+
});
871+
});
872+
});
873+
}
874+
845875
const common = {
846876
allowGlobals,
847877
buildType,
@@ -891,6 +921,7 @@ const common = {
891921
skipIfEslintMissing,
892922
skipIfInspectorDisabled,
893923
skipIfWorker,
924+
spawnPromisified,
894925

895926
get enoughTestMem() {
896927
return require('os').totalmem() > 0x70000000; /* 1.75 Gb */

0 commit comments

Comments
 (0)
Please sign in to comment.