-
Notifications
You must be signed in to change notification settings - Fork 521
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core): make randomString deterministic and allow larger values (#…
- Loading branch information
1 parent
1c936ad
commit d7109dd
Showing
2 changed files
with
41 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
const { test } = require('tap'); | ||
const { contextFuncs } = require('../../../lib/runner'); | ||
|
||
test('$randomString should return a string of the specified length', async function (t) { | ||
const testStringOfLength = (length) => { | ||
const defaultStringLength = 10; | ||
const errors = []; | ||
for (let i = 0; i < 10000; i++) { | ||
const string = contextFuncs.$randomString(length); | ||
if (string.length != (length || defaultStringLength)) { | ||
errors.push(string); | ||
} | ||
} | ||
|
||
t.ok( | ||
errors.length == 0, | ||
`All strings should be of length ${length || defaultStringLength}. Got ${ | ||
errors.length | ||
} bad strings: ${JSON.stringify(errors)}` | ||
); | ||
}; | ||
|
||
//test with different size strings | ||
testStringOfLength(); | ||
testStringOfLength(1); | ||
testStringOfLength(2); | ||
testStringOfLength(10); | ||
testStringOfLength(100); | ||
testStringOfLength(1000); | ||
}); |