Skip to content

Commit 67c31b2

Browse files
Ensuring individual tests are actually ran serially too, as otherwise multiple tests can operate on the same files
All credits to @43081j who figure out the problem and the solution.
1 parent 2cdb5d5 commit 67c31b2

1 file changed

Lines changed: 12 additions & 9 deletions

File tree

test/utils.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,11 @@ async function runCommand(dir, args, options) {
9494
return { status, stdout, stderr, write };
9595
}
9696

97-
async function runTest(name, expected, result, options) {
97+
async function runTest(name, expected, getResult, options) {
9898
const title = options.title || "";
9999
test(`${title}(${name})`, async () => {
100-
const value = (await result)[name];
100+
const result = await getResult();
101+
const value = result[name];
101102
if (expected !== undefined) {
102103
if (name === "status" && expected === "non-zero") {
103104
expect(value).not.toBe(0);
@@ -113,29 +114,31 @@ async function runTest(name, expected, result, options) {
113114
}
114115

115116
function runCli(dir, args = [], options = {}) {
116-
const promise = runCommand(dir, args, options);
117+
const getResult = once(() => {
118+
return runCommand(dir, args, options);
119+
});
117120
const result = {
118121
get status() {
119-
return promise.then((result) => result.status);
122+
return getResult().then((result) => result.status);
120123
},
121124
get stdout() {
122-
return promise.then((result) => result.stdout);
125+
return getResult().then((result) => result.stdout);
123126
},
124127
get stderr() {
125-
return promise.then((result) => result.stderr);
128+
return getResult().then((result) => result.stderr);
126129
},
127130
get write() {
128-
return promise.then((result) => result.write);
131+
return getResult().then((result) => result.write);
129132
},
130133
test: (tests) => {
131134
for (const name of ["status", "stdout", "stderr", "write"]) {
132135
const expected = tests[name];
133-
runTest(name, expected, promise, options);
136+
runTest(name, expected, getResult, options);
134137
}
135138
return result;
136139
},
137140
then: (onFulfilled, onRejected) => {
138-
return promise.then(onFulfilled, onRejected);
141+
return getResult().then(onFulfilled, onRejected);
139142
},
140143
};
141144
return result;

0 commit comments

Comments
 (0)