"Maximum call stack size exceeded" for assert.fixture()
See original GitHub issueOne of my fixture tests fails because of a Maximum call stack size exceeded
error.
OS: MacOS 11.4 Node: v14.15.3 uvu: 0.5.1
// json => readFileSync()
assert.fixture(JSON.stringify(analyze(css), null, 2), json)
This JSON is a 15.000+ lines file.
Workaround
To avoid adding the arr.map() callback to the call stack for every line (15.000+) I’m using a for-loop.
+ // https://github.com/lukeed/uvu/blob/1d753576ffab2dd28b309bb5c296a43d0800321c/src/assert.js#L4-L8
-function dedent(str) {
- let arr = str.match(/^[ \t]*(?=\S)/gm);
- let min = !!arr && Math.min(...arr.map(x => x.length));
- return (!arr || !min) ? str : str.replace(new RegExp(`^[ \\t]{${min}}`, 'gm'), '');
-}
+function dedent(str) {
+ let arr = str.match(/^[ \t]*(?=\S)/gm);
+ if (!Array.isArray(arr) || arr.length === 0) {
+ return str
+ }
+ let min = -1
+ // Workaround for arr.map() to avoid add each map(fn) to call stack
+ for (let index = 0; index < arr.length; index++) {
+ const el = arr[index].length
+ if (el > min) {
+ min = el
+ }
+ }
+ return (!min) ? str : str.replace(new RegExp(`^[ \\t]{${min}}`, 'gm'), '');
+}
Happy to submit a PR if you think this is a suitable solution and worth fixing.
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
Got "RangeError: Maximum call stack size exceeded" for many ...
The setup is the following: I have models called web, space and spaceview. Spaces and spaceviews are many-to-many and a web entity has...
Read more >javascript - Maximum call stack size exceeded error
It means that somewhere in your code, you are calling a function which in turn calls another function and so forth, until you...
Read more >JavaScript RangeError: Maximum Call Stack Size Exceeded
The RangeError: Maximum call stack size exceeded is thrown when a function call is made that exceeds the call stack size. This can...
Read more >Changelog - Cypress Documentation
The error Maximum call stack size exceeded will no longer throw when calling scrollIntoView on an element in the shadow dom. Fixes #7986....
Read more >Avoid Maximum call stack size exceeded in JavaScript
Overview · Error Maximum call stack size exceeded is raised when calling a recursive function in a loop · This is expected –...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Ha, literally the one time I use newer syntax instead of a for-loop 🤦
PR would be great! How about this instead, which is only slightly modified & should still work:
Thanks!
Ah ok cool, thanks! 😃