source: trip-planner-front/node_modules/jsonparse/test/big-token.js@ 59329aa

Last change on this file since 59329aa was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 708 bytes
Line 
1var stream = require('stream');
2var JsonParse = require('../jsonparse');
3var test = require('tape');
4
5test('can handle large tokens without running out of memory', function (t) {
6 var parser = new JsonParse();
7 var chunkSize = 1024;
8 var chunks = 1024 * 200; // 200mb
9 var quote = Buffer.from ? Buffer.from('"') : new Buffer('"');
10 t.plan(1);
11
12 parser.onToken = function (type, value) {
13 t.equal(value.length, chunkSize * chunks, 'token should be size of input json');
14 t.end();
15 };
16
17 parser.write(quote);
18 for (var i = 0; i < chunks; ++i) {
19 var buf = Buffer.alloc ? Buffer.alloc(chunkSize) : new Buffer(chunkSize);
20 buf.fill('a');
21 parser.write(buf);
22 }
23 parser.write(quote);
24});
Note: See TracBrowser for help on using the repository browser.