Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d0bb380

Browse files
committed
More work to fix errors
1 parent e4fdb3d commit d0bb380

5 files changed

Lines changed: 266 additions & 257 deletions

File tree

.eslintrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module.exports = {
55
node: true,
66
},
77
globals: {
8-
jest: true
8+
jest: true,
99
},
1010
extends: ["plugin:prettier/recommended"],
1111
};

tests/_helpers.js

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
1-
2-
function jestFakeTimersAreEnabled() {
3-
/* istanbul ignore else */
4-
if (typeof jest !== 'undefined' && jest !== null) {
5-
return (
6-
// legacy timers
7-
setTimeout._isMockFunction === true ||
8-
// modern timers
9-
Object.prototype.hasOwnProperty.call(setTimeout, 'clock')
10-
)
11-
}
12-
// istanbul ignore next
13-
return false
14-
}
15-
16-
17-
module.exports = {
18-
jestFakeTimersAreEnabled
19-
}
1+
function jestFakeTimersAreEnabled() {
2+
/* istanbul ignore else */
3+
if (typeof jest !== "undefined" && jest !== null) {
4+
return (
5+
// legacy timers
6+
setTimeout._isMockFunction === true ||
7+
// modern timers
8+
Object.prototype.hasOwnProperty.call(setTimeout, "clock")
9+
);
10+
}
11+
// istanbul ignore next
12+
return false;
13+
}
14+
15+
module.exports = {
16+
jestFakeTimersAreEnabled,
17+
};

tests/_test-utils.js

Lines changed: 49 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,29 @@
11
const execa = require("execa");
22
const { resolve } = require("path");
33

4+
// Used for `MutationObserver`. Unsure if it's really needed, but it's worth mentioning that these are not tied to
5+
// specific CLI instances of `render`. This means that if there are e2e CLI tests that run in parallel, they will
6+
// execute far more frequently than needed.
7+
const _observers = new Map();
8+
9+
// Not perfect as a way to make "MutationObserver" unique IDs, but it should work
10+
let mutId = 0;
11+
12+
class MutationObserver {
13+
constructor(cb) {
14+
this._id = ++mutId;
15+
this._cb = cb;
16+
}
17+
18+
observe() {
19+
_observers.set(this._id, this._cb);
20+
}
21+
22+
disconnect() {
23+
_observers.delete(this._id);
24+
}
25+
}
26+
427
module.exports = {
528
/**
629
* @param {Array} args
@@ -25,61 +48,52 @@ module.exports = {
2548
}
2649
);
2750

28-
const stdoutArr = [];
29-
30-
let localResolve = null;
31-
const isReady = new Promise(resolve => localResolve = resolve);
32-
/**
33-
* Made an array so if, for some reason, we have more than a single
34-
* awaited promise on data waiting, this will call all of them, rather
35-
* than accidentally hanging
36-
*
37-
* @type {{promise: Promise, resolve: () => void}[]}
38-
*/
51+
let _readyPromiseInternals = null;
52+
const isReady = new Promise((resolve, reject) => (_readyPromiseInternals = {resolve, reject}));
53+
3954
const additionalExecProps = {
4055
// Clear buffer of stdout to do more accurate `t.regex` checks
4156
cleanup() {
4257
this.stdoutArr = [];
4358
},
4459
// An array of strings gathered from stdout when unable to do
4560
// `await stdout` because of inquirer interactive prompts
46-
stdoutArr,
47-
_observers: new Map(),
61+
stdoutArr: [],
4862
_runObservers() {
49-
[...this._observers.values()].forEach(cb => cb());
63+
[..._observers.values()].forEach((cb) => cb());
5064
}
5165
};
5266

53-
// Not perfect as a way to make "MutationObserver" unique IDs, but it should work
54-
let mutId = 0;
55-
56-
class MutationObserver {
57-
constructor(cb) {
58-
this._id = ++mutId;
59-
this._cb = cb;
60-
}
61-
62-
observe() {
63-
additionalExecProps._observers.set(this._id, this._cb);
64-
}
65-
66-
disconnect () {
67-
additionalExecProps._observers.delete(this._id);
68-
}
69-
}
70-
7167
exec.stdout.on("data", (result) => {
72-
stdoutArr.push(result.toString());
68+
const resStr = result.toString();
69+
additionalExecProps.stdoutArr.push(resStr);
7370
additionalExecProps._runObservers();
74-
if (!isReady.pending) localResolve();
71+
// if (isReady.pending) {
72+
console.log("IS READY IS READY NOW");
73+
_readyPromiseInternals.resolve(resStr);
74+
// }
7575
});
7676

77-
Object.assign(exec, additionalExecProps, {MutationObserver});
77+
exec.stdout.on("error", (result) => {
78+
const resStr = result.toString();
79+
if (isReady.pending) _readyPromiseInternals.reject(resStr);
80+
});
81+
82+
exec.stderr.on('data', result => {
83+
if (isReady.pending) _readyPromiseInternals.reject(result.toString());
84+
})
85+
86+
Object.assign(exec, additionalExecProps);
87+
88+
console.log("BEFORE AWAIT")
7889

7990
await isReady;
8091

92+
console.log("AFTER AWAIT")
93+
8194
return exec;
8295
},
96+
MutationObserver,
8397
DOWN: "\x1B\x5B\x42",
8498
UP: "\x1B\x5B\x41",
8599
ENTER: "\x0D",

0 commit comments

Comments
 (0)