Skip to content

Commit c97cfbe

Browse files
benweissmannljharb
authored andcommitted
[Tests] Switch to newer v8 prediction library; enable node 24 testing
1 parent 0e93122 commit c97cfbe

File tree

2 files changed

+32
-10
lines changed

2 files changed

+32
-10
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@
5959
"formidable": "^1.2.6",
6060
"in-publish": "^2.0.1",
6161
"istanbul": "^0.4.5",
62+
"js-randomness-predictor": "^1.5.5",
6263
"obake": "^0.1.2",
6364
"phantomjs-prebuilt": "^2.1.16",
6465
"pkgfiles": "^2.3.2",
6566
"pre-commit": "^1.2.2",
66-
"predict-v8-randomness": "^1.0.35",
6767
"puppeteer": "^1.20.0",
6868
"request": "~2.87.0",
6969
"rimraf": "^2.7.1",

test/integration/test-boundary-prediction.js

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,40 @@ var common = require('../common');
44
var assert = common.assert;
55
var FormData = require(common.dir.lib + '/form_data');
66
var satisfies = require('semver').satisfies;
7-
var predictV8Randomness = satisfies(process.version, '^17 - ^23') && require('predict-v8-randomness'); // eslint-disable-line global-require
7+
var jsrp = satisfies(process.version, '>= 17') && require('js-randomness-predictor'); // eslint-disable-line global-require
88

9-
var initialSequence = [
10-
Math.random(),
11-
Math.random(),
12-
Math.random(),
13-
Math.random(),
14-
];
15-
var predictor = predictV8Randomness && new predictV8Randomness.Predictor(initialSequence);
9+
var predictor = jsrp && jsrp.node();
10+
11+
/**
12+
* Predicts the next random outputs from the V8 engine's random number generator.
13+
*
14+
* @param {JsRandomnessPredictor} predictorInstance - The instance of the randomness predictor.
15+
* @param {number} count - The number of random outputs to predict.
16+
* @returns {Promise<number[]>} A promise that resolves with the predicted random outputs or rejects with an error.
17+
*/
18+
function predictMany(predictorInstance, count) {
19+
return new Promise(function (resolve, reject) {
20+
var outputs = [];
21+
22+
/** Recursive function to predict the next random output */
23+
function predictOne() {
24+
predictorInstance.predictNext().then(function (nextOutput) {
25+
outputs.push(nextOutput);
26+
27+
if (outputs.length < count) {
28+
predictOne();
29+
} else {
30+
resolve(outputs);
31+
}
32+
}).catch(reject);
33+
}
34+
35+
predictOne();
36+
});
37+
}
1638

1739
if (predictor) {
18-
predictor.predictNext(24).then(function (next24RandomOutputs) {
40+
predictMany(predictor, 24).then(function (next24RandomOutputs) {
1941
var predictedBoundary = next24RandomOutputs
2042
.map(function (v) {
2143
return Math.floor(v * 10).toString(16);

0 commit comments

Comments
 (0)