How to use JSONStream method in Mocha

Best JavaScript code snippet using mocha

JSONStream_vx.x.x.js

Source:JSONStream_vx.x.x.js Github

copy

Full Screen

1// flow-typed signature: 2e82c8be2483588f05be3476cd2af9002// flow-typed version: <<STUB>>/JSONStream_v^1.3.1/flow_v0.59.03/**4 * This is an autogenerated libdef stub for:5 *6 * 'JSONStream'7 *8 * Fill this stub out by replacing all the `any` types.9 *10 * Once filled out, we encourage you to share your work with the11 * community by sending a pull request to:12 * https://github.com/flowtype/flow-typed13 */14declare module 'JSONStream' {15 declare module.exports: any;16}17/**18 * We include stubs for each file inside this npm package in case you need to19 * require those files directly. Feel free to delete any files that aren't20 * needed.21 */22declare module 'JSONStream/examples/all_docs' {23 declare module.exports: any;24}25declare module 'JSONStream/test/bool' {26 declare module.exports: any;27}28declare module 'JSONStream/test/browser' {29 declare module.exports: any;30}31declare module 'JSONStream/test/destroy_missing' {32 declare module.exports: any;33}34declare module 'JSONStream/test/disabled/doubledot1' {35 declare module.exports: any;36}37declare module 'JSONStream/test/disabled/doubledot2' {38 declare module.exports: any;39}40declare module 'JSONStream/test/empty' {41 declare module.exports: any;42}43declare module 'JSONStream/test/error_contents' {44 declare module.exports: any;45}46declare module 'JSONStream/test/fn' {47 declare module.exports: any;48}49declare module 'JSONStream/test/gen' {50 declare module.exports: any;51}52declare module 'JSONStream/test/header_footer' {53 declare module.exports: any;54}55declare module 'JSONStream/test/issues' {56 declare module.exports: any;57}58declare module 'JSONStream/test/keys' {59 declare module.exports: any;60}61declare module 'JSONStream/test/map' {62 declare module.exports: any;63}64declare module 'JSONStream/test/multiple_objects_error' {65 declare module.exports: any;66}67declare module 'JSONStream/test/multiple_objects' {68 declare module.exports: any;69}70declare module 'JSONStream/test/null' {71 declare module.exports: any;72}73declare module 'JSONStream/test/parsejson' {74 declare module.exports: any;75}76declare module 'JSONStream/test/stringify_object' {77 declare module.exports: any;78}79declare module 'JSONStream/test/stringify' {80 declare module.exports: any;81}82declare module 'JSONStream/test/test' {83 declare module.exports: any;84}85declare module 'JSONStream/test/test2' {86 declare module.exports: any;87}88declare module 'JSONStream/test/two-ways' {89 declare module.exports: any;90}91// Filename aliases92declare module 'JSONStream/examples/all_docs.js' {93 declare module.exports: $Exports<'JSONStream/examples/all_docs'>;94}95declare module 'JSONStream/index' {96 declare module.exports: $Exports<'JSONStream'>;97}98declare module 'JSONStream/index.js' {99 declare module.exports: $Exports<'JSONStream'>;100}101declare module 'JSONStream/test/bool.js' {102 declare module.exports: $Exports<'JSONStream/test/bool'>;103}104declare module 'JSONStream/test/browser.js' {105 declare module.exports: $Exports<'JSONStream/test/browser'>;106}107declare module 'JSONStream/test/destroy_missing.js' {108 declare module.exports: $Exports<'JSONStream/test/destroy_missing'>;109}110declare module 'JSONStream/test/disabled/doubledot1.js' {111 declare module.exports: $Exports<'JSONStream/test/disabled/doubledot1'>;112}113declare module 'JSONStream/test/disabled/doubledot2.js' {114 declare module.exports: $Exports<'JSONStream/test/disabled/doubledot2'>;115}116declare module 'JSONStream/test/empty.js' {117 declare module.exports: $Exports<'JSONStream/test/empty'>;118}119declare module 'JSONStream/test/error_contents.js' {120 declare module.exports: $Exports<'JSONStream/test/error_contents'>;121}122declare module 'JSONStream/test/fn.js' {123 declare module.exports: $Exports<'JSONStream/test/fn'>;124}125declare module 'JSONStream/test/gen.js' {126 declare module.exports: $Exports<'JSONStream/test/gen'>;127}128declare module 'JSONStream/test/header_footer.js' {129 declare module.exports: $Exports<'JSONStream/test/header_footer'>;130}131declare module 'JSONStream/test/issues.js' {132 declare module.exports: $Exports<'JSONStream/test/issues'>;133}134declare module 'JSONStream/test/keys.js' {135 declare module.exports: $Exports<'JSONStream/test/keys'>;136}137declare module 'JSONStream/test/map.js' {138 declare module.exports: $Exports<'JSONStream/test/map'>;139}140declare module 'JSONStream/test/multiple_objects_error.js' {141 declare module.exports: $Exports<'JSONStream/test/multiple_objects_error'>;142}143declare module 'JSONStream/test/multiple_objects.js' {144 declare module.exports: $Exports<'JSONStream/test/multiple_objects'>;145}146declare module 'JSONStream/test/null.js' {147 declare module.exports: $Exports<'JSONStream/test/null'>;148}149declare module 'JSONStream/test/parsejson.js' {150 declare module.exports: $Exports<'JSONStream/test/parsejson'>;151}152declare module 'JSONStream/test/stringify_object.js' {153 declare module.exports: $Exports<'JSONStream/test/stringify_object'>;154}155declare module 'JSONStream/test/stringify.js' {156 declare module.exports: $Exports<'JSONStream/test/stringify'>;157}158declare module 'JSONStream/test/test.js' {159 declare module.exports: $Exports<'JSONStream/test/test'>;160}161declare module 'JSONStream/test/test2.js' {162 declare module.exports: $Exports<'JSONStream/test/test2'>;163}164declare module 'JSONStream/test/two-ways.js' {165 declare module.exports: $Exports<'JSONStream/test/two-ways'>;...

Full Screen

Full Screen

test_json-stream-stringify.js

Source:test_json-stream-stringify.js Github

copy

Full Screen

1import JsonStreamStringify from 'json-stream-stringify';2import { Readable } from 'stream';3function ReadableStream(...args: any[]) {4 const stream = new Readable({5 objectMode: args.some(v => typeof v !== 'string'),6 });7 stream._read = () => {8 if (!args.length) return stream.push(null);9 const v = args.shift();10 if (v instanceof Error) return stream.emit('error', v);11 return stream.push(v);12 };13 return stream;14}15let jsonStream: JsonStreamStringify;16jsonStream = new JsonStreamStringify(null);17jsonStream = new JsonStreamStringify(Infinity);18jsonStream = new JsonStreamStringify(new Date());19jsonStream = new JsonStreamStringify(true);20jsonStream = new JsonStreamStringify(Symbol('test'));21jsonStream = new JsonStreamStringify(1);22jsonStream = new JsonStreamStringify(1, () => 2);23jsonStream = new JsonStreamStringify('\n');24jsonStream = new JsonStreamStringify('漢字');25jsonStream = new JsonStreamStringify('\u009f');26jsonStream = new JsonStreamStringify({});27jsonStream = new JsonStreamStringify(/regex/gi);28jsonStream = new JsonStreamStringify({ a: undefined });29jsonStream = new JsonStreamStringify({ a: null });30jsonStream = new JsonStreamStringify({ a: undefined }, (k, v) => {31 if (k) {32 k === 'a';33 v === undefined;34 return 1;35 }36 return v;37});38jsonStream = new JsonStreamStringify({ a: 1, b: 2 }, (k, v) => {39 if (k === 'a') {40 v === 1;41 return v;42 }43 if (k === 'b') {44 v === 2;45 return undefined;46 }47 if (k === undefined) return v;48 throw new Error();49});50jsonStream = new JsonStreamStringify({ a: 1, b: 2 }, ['b']);51jsonStream = new JsonStreamStringify({ a: 1 });52jsonStream = new JsonStreamStringify({53 a: 1,54 b: undefined,55});56jsonStream = new JsonStreamStringify({57 a: 1,58 b: Promise.resolve(undefined)59});60jsonStream = new JsonStreamStringify({61 a() { },62 b: 'b'63});64jsonStream = new JsonStreamStringify([function a() { }]);65jsonStream = new JsonStreamStringify([function a() { }, undefined]);66jsonStream = new JsonStreamStringify({ a: new Date() });67jsonStream = new JsonStreamStringify({68 a: 1,69 b: {70 c: 2,71 },72});73jsonStream = new JsonStreamStringify({74 a: [1],75 b: 2,76});77jsonStream = new JsonStreamStringify([]);78jsonStream = new JsonStreamStringify([79 [80 [],81 ],82 [83 [],84 ],85]);86jsonStream = new JsonStreamStringify([1, undefined, 2]);87// tslint:disable-next-line no-sparse-arrays88jsonStream = new JsonStreamStringify([1, , 2]);89jsonStream = new JsonStreamStringify([1, 'a']);90jsonStream = new JsonStreamStringify(Promise.resolve(1));91jsonStream = new JsonStreamStringify(Promise.resolve(Promise.resolve(1)));92jsonStream = new JsonStreamStringify(({93 then(fn: (promise: any) => any) {94 return fn(Promise.resolve(1));95 },96}));97jsonStream = new JsonStreamStringify({98 a: Promise.resolve(1),99});100jsonStream = new JsonStreamStringify(ReadableStream(1));101jsonStream = new JsonStreamStringify(Promise.resolve(ReadableStream(1)));102jsonStream = new JsonStreamStringify({103 a: ReadableStream(1, 2, 3),104});105jsonStream = new JsonStreamStringify(ReadableStream('a', 'b', 'c'));106{107 const stream = new Readable();108 const args = ['a', 'b', 'c'];109 Object.assign(stream, {110 firstRead: true,111 _read() {112 setTimeout(() => {113 if (!args.length) return stream.push(null);114 const v = args.shift();115 return stream.push(v);116 }, 1);117 },118 });119 jsonStream = new JsonStreamStringify(stream);120}121jsonStream = new JsonStreamStringify(ReadableStream({}, 'a', undefined, 'c'));122jsonStream = new JsonStreamStringify({123 a: ReadableStream({124 name: 'name',125 date: new Date(),126 }),127});128jsonStream = new JsonStreamStringify({129 name: 'name',130 arr: [],131 date: new Date(),132});133jsonStream = new JsonStreamStringify({ a: 1 }, undefined, 2);134jsonStream = new JsonStreamStringify([1], undefined, 2);135jsonStream = new JsonStreamStringify([1], undefined, 'a');136// tslint:disable-next-line no-object-literal-type-assertion137jsonStream = new JsonStreamStringify({}, undefined, undefined, true);138{139 const cyclicData1: Record<string, any> = {};140 cyclicData1.a = cyclicData1;141 cyclicData1.b = [cyclicData1, {142 a: cyclicData1,143 }];144 cyclicData1.b[3] = ReadableStream(cyclicData1.b[1]);145 // tslint:disable-next-line no-object-literal-type-assertion146 jsonStream = new JsonStreamStringify(cyclicData1, undefined, undefined, true);147}148{149 const cyclicData2: Record<string, any> = {};150 const data2 = {151 a: 'deep',152 };153 cyclicData2.a = Promise.resolve({154 b: data2,155 });156 cyclicData2.b = data2;157 jsonStream = new JsonStreamStringify(cyclicData2, undefined, undefined, true);158}159{160 const a = { foo: 'bar' };161 const arr = [a, a];162 jsonStream = new JsonStreamStringify(arr);...

Full Screen

Full Screen

script.js

Source:script.js Github

copy

Full Screen

1const StreamArray = require('stream-json/streamers/StreamArray');2const fs = require('fs');3const series = require('async/series');4const { query } = require('../api/database/db_hepler');5const { getHashPassword } = require('../api/shared/helper');6series([7 createTables,8 insertPublishers,9 insertGenres,10 insertBooks,11 insertAuthors,12 insertWrittens,13 createAdmin14], (err, result) => {15 if (err) console.log(err);16 else console.log('Data has been inserted into database.');17});18async function createTables(callback) {19 const tables = require('./tables.json');20 for (const id in tables) {21 await query(`drop table if exists ${id}`);22 await query(tables[id]);23 }24}25function insertPublishers(callback) {26 const jsonStream = StreamArray.withParser();27 const sql = `INSERT INTO publishers(publisher_id, name, email) VALUES (?,?,null);`28 jsonStream.on('data', async ({ key, value: publisher }) => {29 await query(sql, [publisher['publisher_id'], publisher['name']]);30 });31 jsonStream.on('error', (err) => console.log(err));32 fs.createReadStream('publishers.json', { encoding: 'utf-8' })33 .pipe(jsonStream.input)34 .on('end', () => callback(null, 'done'));35}36function insertGenres(callback) {37 const jsonStream = StreamArray.withParser();38 const sql = `INSERT INTO genres(genre_id, name) VALUES (?,?);`;39 jsonStream.on('data', async ({ key, value: genre }) => {40 await query(sql, [genre['genre_id'], genre['name']]);41 });42 jsonStream.on('error', (err) => console.log(err));43 fs.createReadStream('genres.json', { encoding: 'utf-8' }).pipe(jsonStream.input).on('end', () => callback(null, 'done'));;44}45function insertBooks(callback) {46 const jsonStream = StreamArray.withParser();47 const sql = `INSERT INTO books (isbn, name, image_url, summary, quantity, price, genre_id, publisher_id) 48 VALUES (?, ?, ?, null, 50, ?, ?, ?);`;49 jsonStream.on('data', async ({ key, value: book }) => {50 try {51 await query(sql,52 [book['isbn'], book['name'], book['imageurl'], 9, book['genre_id'], book['publisher_id']]);53 } catch (error) {54 console.log(error.sqlMessage);55 }56 });57 jsonStream.on('error', (err) => console.log(err));58 fs.createReadStream('books.json', { encoding: 'utf-8' }).pipe(jsonStream.input).on('end', () => callback(null, 'done'));59}60function insertAuthors(callback) {61 const jsonStream = StreamArray.withParser();62 const sql = `INSERT INTO authors(author_id, fullname) VALUES (?,?);`;63 jsonStream.on('data', async ({ key, value: author }) => {64 try {65 await query(sql, [author['author_id'], author['fullname']]);66 } catch (error) {67 console.log(`${error.sqlMessage}`);68 }69 });70 jsonStream.on('error', (err) => console.log(err));71 fs.createReadStream('authors.json', { encoding: 'utf-8' }).pipe(jsonStream.input).on('end', () => callback(null, 'done'));72}73function insertWrittens(callback) {74 const jsonStream = StreamArray.withParser();75 const sql = `INSERT INTO writtens(isbn, author_id) VALUES (?,?);`;76 jsonStream.on('data', async ({ key, value: written }) => {77 try {78 await query(sql, [written['isbn'], written['author_id']]);79 } catch (error) {80 console.log(error.sqlMessage);81 }82 });83 jsonStream.on('error', (err) => console.log(err));84 fs.createReadStream('writtens.json', { encoding: 'utf-8' }).pipe(jsonStream.input).on('end', () => callback(null, 'done'));85}86async function createAdmin(callback) {87 const insertAdmin =88 `insert into89 employees (90 emp_id,91 fullname,92 email,93 identify_number,94 phone_number,95 salary,96 hash_password,97 role98 )99 values100 (101 1,102 'Admin',103 'admin@gmail.com',104 '123456789',105 '0987654321',106 900,107 ?,108 'ADMIN'109 );`;110 const hashPassword = await getHashPassword('admin');111 await query(insertAdmin, [hashPassword]);...

Full Screen

Full Screen

kubemoteWrapper.js

Source:kubemoteWrapper.js Github

copy

Full Screen

...24 }25 //const stream = this.client.api.group(manifest).ns.kind(manifest).getStream({ qs: { follow: true } });26 const stream = this.client.core.ns.pods(name,labelSelector).getStream({ qs: { follow: true } });27 const JSONStream = require('json-stream');28 const jsonStream = new JSONStream();29 let pods = [];30 stream.pipe(jsonStream);31 jsonStream.on('data', chunk => {32 pods.push(chunk);33 });34 jsonStream.on('end', ()=>{35 resolve(pods[0]);36 });37 })38 }39 getDeployments({name , selector=""}={}){40 return new Promise((resolve, reject)=>{41 const manifest = {42 kind: 'Deployment',43 apiVersion: 'extensions/v1beta1'44 }45 const stream = this.client.api.group(manifest).ns.kind(manifest).getStream({ qs: { follow: true } });46 const JSONStream = require('json-stream');47 const deployments = new JSONStream();48 let deploy = [];49 stream.pipe(deployments);50 deployments.on('data', chunk => {51 deploy.push(chunk);52 });53 deployments.on('end', ()=>{54 resolve(deploy[0].items);55 });56 })57 }58 patchDeployment({ name, spec }){59 }60 deleteDeployment({ name }){61 }62 getPodLogs({ podName }){63 let logs = [];64 const JSONStream = require('json-stream');65 const jsonStream = new JSONStream();66 const stream = this.client.core.ns.po(podName).log.getStream({ qs: { follow: true } });67 return new Promise((resolve, reject)=>{68 stream.pipe(jsonStream);69 jsonStream.on('data', chunk => logs.push(chunk));70 jsonStream.on('error', chunk => reject(logs));71 jsonStream.on('end', chunk => resolve(logs));72 });73 }74 createDeployment(deploymentSpecJson){75 }76 createJob(jobSpecJson){77 return new Promise((resolve, reject)=>{78 this.client.batch.jobs.post({"body": jobSpecJson}, (err, data)=>{79 return (err) ? reject(err) : resolve(data);80 });81 })82 }83 watchDeploymentList(selector){84 }85 watchPodList(selector){86 }87 watchServiceList(selector){88 }89 watchJobList(selector){90 }91 watchJob({ jobName, selector }){92 }93 deleteJob({ jobName }){94 }95 getNodes(){96 return new Promise((resolve, reject)=>{97 const manifest = {98 kind: 'nodes',99 apiVersion: 'v1'100 }101 const stream = this.client.core.nodes.getStream({ qs: { follow: true } });102 const JSONStream = require('json-stream');103 const jsonStream = new JSONStream();104 let nodes = [];105 stream.pipe(jsonStream);106 jsonStream.on('data', chunk => {107 nodes.push(chunk);108 });109 jsonStream.on('error', err => {110 reject(err);111 });112 jsonStream.on('end', ()=>{113 resolve(nodes[0].items);114 });115 })116 }117 }...

Full Screen

Full Screen

json.spec.js

Source:json.spec.js Github

copy

Full Screen

1var JsonStream = helper.requireSource('json');2describe('JsonStream', function() {3 var json;4 describe('write empty object', function() {5 beforeEach(function(done) {6 var jsonStream = new JsonStream();7 helper.readStream(jsonStream, function(err, result) {8 json = result;9 done(err);10 });11 jsonStream.end();12 });13 it('should write an empty object on no input', function() {14 chai.expect(json).to.deep.equal({});15 });16 });17 describe('calling end on object stream should not end json stream', function() {18 var onEnd = sinon.spy();19 beforeEach(function(done) {20 var jsonStream = new JsonStream();21 var objectStream = jsonStream.createObjectStream('key');22 jsonStream.on('end', onEnd);23 objectStream.on('finish', function() {24 done();25 });26 objectStream.write('null');27 objectStream.end();28 });29 it('should not call end on json stream', function() {30 chai.expect(onEnd.called).to.be.false;31 });32 });33 describe('closing json stream should close object stream', function() {34 var onClose = sinon.spy();35 beforeEach(function() {36 var jsonStream = new JsonStream();37 var objectStream = jsonStream.createObjectStream('key');38 objectStream.on('close', onClose);39 jsonStream.destroy();40 });41 it('should close object stream', function() {42 chai.expect(onClose.calledOnce).to.be.true;43 });44 });45 describe('stream single json object', function() {46 beforeEach(function(done) {47 var jsonStream = new JsonStream();48 var objectStream = jsonStream.createObjectStream('key');49 helper.readStream(jsonStream, function(err, result) {50 json = result;51 done(err);52 });53 objectStream.on('finish', function() {54 jsonStream.end();55 });56 objectStream.write('{');57 objectStream.write('"id"');58 objectStream.write(':');59 objectStream.write('1');60 objectStream.write('}');61 objectStream.end();62 });63 it('should contain valid json entry', function() {64 chai.expect(json).to.deep.equal({ key: { id: 1 } });65 });66 });67 describe('stream multiple json values', function() {68 beforeEach(function(done) {69 var jsonStream = new JsonStream();70 helper.readStream(jsonStream, function(err, result) {71 json = result;72 done(err);73 });74 var objectStream1 = jsonStream.createObjectStream('key_1');75 objectStream1.on('finish', function() {76 var objectStream2 = jsonStream.createObjectStream('key_2');77 objectStream2.on('finish', function() {78 jsonStream.end();79 });80 objectStream2.write('[');81 objectStream2.write('2');82 objectStream2.write(']');83 objectStream2.end();84 });85 objectStream1.write('n');86 objectStream1.write('u');87 objectStream1.write('l');88 objectStream1.write('l');89 objectStream1.end();90 });91 it('should contain valid json', function() {92 chai.expect(json).to.deep.equal({ key_1: null, key_2: [2] });93 });94 });95 describe('write json object', function() {96 beforeEach(function(done) {97 var jsonStream = new JsonStream();98 helper.readStream(jsonStream, function(err, result) {99 json = result;100 done(err);101 });102 jsonStream.writeObject('key', { id: 1 });103 jsonStream.end();104 });105 it('should contain valid json', function() {106 chai.expect(json).to.deep.equal({ key: { id: 1 } });107 });108 });...

Full Screen

Full Screen

test-api-json-stream.js

Source:test-api-json-stream.js Github

copy

Full Screen

1// Copyright 2015 The Vanadium Authors. All rights reserved.2// Use of this source code is governed by a BSD-style3// license that can be found in the LICENSE file.4var test = require('tape');5var jsonStream = require('../browser/api/json-stream');6var Buffer = require('buffer').Buffer;7test('jsonStream() - single entity per write', function(t) {8 t.plan(4);9 var stream = jsonStream();10 stream11 .on('data', function(data) {12 t.same(data, { foo: 'bar' });13 });14 iterate(4, function() {15 stream.write(new Buffer('{ "foo": "bar" }\n'));16 });17 stream.end();18});19test('jsonStream() - empty strings', function(t) {20 t.plan(1);21 var stream = jsonStream();22 stream23 .on('data', function(data) {24 t.same(data, { foo: 'bar' });25 });26 stream.write(new Buffer('{ "foo": "bar" }\n'));27 stream.write(new Buffer(''));28 stream.end();29});30test('jsonStream() - single entry, multiple writes', function(t) {31 t.plan(1);32 var stream = jsonStream();33 stream34 .on('data', function(data) {35 t.same(data, { foo: 'bar', baz: 'qux' });36 });37 stream.write(new Buffer('{ "foo":'));38 stream.write(new Buffer('"ba'));39 stream.write(new Buffer('r", "ba'));40 stream.write(new Buffer('z":'));41 stream.write(new Buffer('"qux" }\n'));42 stream.end();43});44test('jsonStream() - chunk with several entries, then pieces', function(t) {45 t.plan(11);46 var stream = jsonStream();47 var chunk = '';48 stream49 .on('data', function(data) {50 t.same(data, { a: 'b' });51 });52 iterate(10, function() {53 chunk += '{ "a": "b" }\n';54 });55 chunk += '{ "a":';56 stream.write(new Buffer(chunk));57 stream.write(new Buffer(' "b" }\n'));58 stream.end();59});60test('jsonStream() - end with a partial entry', function(t) {61 t.plan(2);62 var stream = jsonStream();63 stream64 .on('end', t.end)65 .on('error', function(err) {66 t.fail('should not error');67 })68 .on('data', function(data) {69 t.same(data, { a: 'b' });70 });71 stream.write('{ "a": "b" }\n');72 stream.write('{ "a": "b" }\n');73 stream.write('{ "a": ');74 stream.end();75});76test('jsonStream() - blank line entries', function(t) {77 t.plan(1);78 var stream = jsonStream();79 stream80 .on('end', t.end)81 .on('error', function(err) {82 t.fail('should not error');83 })84 .on('data', function(data) {85 t.same(data, { a: 'b' });86 });87 stream.write('{ "a": "b" }\n');88 stream.write('');89 stream.end();90});91test('jsonStream() - bad json entry', function(t) {92 var stream = jsonStream();93 var chunk = '{ bad: "json"';94 stream.on('error', function(err) {95 t.ok(err instanceof Error, 'should error');96 t.ok(err instanceof SyntaxError, 'should be a SyntaxError');97 t.end();98 });99 stream.write(new Buffer(chunk + '\n'));100});101function iterate(times, iterator) {102 for (var i = 0; i < times; i++) {103 iterator(i);104 }...

Full Screen

Full Screen

jsonstream.js

Source:jsonstream.js Github

copy

Full Screen

1'use strict'2const assert = require('chai').assert3const spooks = require('spooks')4const modulePath = '../../src/jsonstream'5suite('jsonstream:', () => {6 let log7 setup(() => {8 log = {}9 })10 test('require does not throw', () => {11 assert.doesNotThrow(() => {12 require(modulePath)13 })14 })15 test('require returns function', () => {16 assert.isFunction(require(modulePath))17 })18 suite('require:', () => {19 let Stream20 setup(() => {21 Stream = require(modulePath)22 })23 test('Stream expects two arguments', () => {24 assert.lengthOf(Stream, 2)25 })26 test('calling Stream with function argument doesNotThrow', () => {27 assert.doesNotThrow(() => {28 Stream(() => {})29 })30 })31 test('calling Stream with object argument throws', () => {32 assert.throws(() => {33 Stream({ read: () => {} })34 })35 })36 test('calling Stream with new returns Stream instance', () => {37 assert.instanceOf(new Stream(() => {}), Stream)38 })39 test('calling Stream with new returns Readable instance', () => {40 assert.instanceOf(new Stream(() => {}), require('stream').Readable)41 })42 test('calling Stream without new returns Stream instance', () => {43 assert.instanceOf(Stream(() => {}), Stream)44 })45 suite('instantiate:', () => {46 let jsonstream47 setup(() => {48 jsonstream = new Stream(spooks.fn({ name: 'read', log: log }))49 })50 test('jsonstream has _read method', () => {51 assert.isFunction(jsonstream._read)52 })53 test('_read expects no arguments', () => {54 assert.lengthOf(jsonstream._read, 0)55 })56 test('read was not called', () => {57 assert.strictEqual(log.counts.read, 0)58 })59 suite('jsonstream._read:', () => {60 setup(() => {61 jsonstream._read()62 })63 test('read was called once', () => {64 assert.strictEqual(log.counts.read, 1)65 assert.isUndefined(log.these.read[0])66 })67 test('read was called correctly', () => {68 assert.lengthOf(log.args.read[0], 0)69 })70 })71 })72 })...

Full Screen

Full Screen

index.js

Source:index.js Github

copy

Full Screen

1var JSONStream = require('JSONStream');2var open = '{"type":"FeatureCollection","features":[',3 close = ']}';4module.exports.parse = function() {5 var jsonstream = JSONStream.parse('features.*');6 return jsonstream;7};8module.exports.stringify = function() {9 var jsonstream = JSONStream.stringify(open, '\n,\n', close);10 return jsonstream;...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var fs = require('fs');2var JSONStream = require('JSONStream');3var es = require('event-stream');4var stream = fs.createReadStream('test.json', {encoding: 'utf8'});5var parser = JSONStream.parse('*');6var count = 0;7stream.pipe(parser).pipe(es.map(function (data, callback) {8 count++;9 callback();10})).on('end', function () {11 console.log(count);12});

Full Screen

Using AI Code Generation

copy

Full Screen

1var JSONStream = require('JSONStream');2var fs = require('fs');3var es = require('event-stream');4var assert = require('assert');5var mocha = require('mocha');6var describe = mocha.describe;7var it = mocha.it;8var parser = JSONStream.parse('*');9var input = fs.createReadStream('input.json');10var output = fs.createWriteStream('output.json');11input.pipe(parser).pipe(output);12describe('JSONStream', function() {13 it('should parse JSON', function(done) {14 assert.equal('JSONStream', parser.name);15 done();16 });17});18{19}20{21}22# JSONStream.parse(pattern, [options])23var JSONStream = require('JSONStream');24var parser = JSONStream.parse('foo');25parser.on('data', function (obj) {26 console.log(obj);27});28parser.write('{"foo":"bar"}\n');29parser.write('{"foo":"baz"}\n');30parser.write('{"foo":42}\n');31parser.write('{"bar":"foo"}\n');32parser.write('{"baz":"foo"}

Full Screen

Using AI Code Generation

copy

Full Screen

1var JSONStream = require('JSONStream');2var fs = require('fs');3var es = require('event-stream');4var stream = fs.createReadStream('test.json', {encoding: 'utf8'});5 .pipe(JSONStream.parse('*'))6 .pipe(es.mapSync(function (data) {7 console.log(data);8 })9);10 { "name": "John", "age": 30, "car": null },11 { "name": "John", "age": 30, "car": null },12 { "name": "John", "age": 30, "car": null },13 { "name": "John", "age": 30, "car": null },14 { "name": "John", "age": 30, "car": null },15 { "name": "John", "age": 30, "car": null }16 { "name": "John", "age": 30, "car": null },17 { "name": "John", "age": 30, "car": null },18 { "name": "John", "age": 30, "car": null },19 { "name": "John", "age": 30, "car": null },20 { "name": "John", "age": 30, "car": null },21 { "name": "John", "age": 30, "car": null }22 { "name": "John", "age": 30, "car": null },23 { "name": "John", "age": 30, "car": null },24 { "name": "John", "age": 30, "car": null },25 { "name": "John", "age": 30, "car": null },26 { "name": "John", "age": 30, "car": null },27 { "name": "John", "age": 30, "car": null }28 {

Full Screen

Using AI Code Generation

copy

Full Screen

1var Mocha = require('mocha');2var mocha = new Mocha();3mocha.addFile('./test.js');4mocha.reporter('mocha-json-stream-reporter');5mocha.run(function(failures){6 process.on('exit', function () {7 });8});

Full Screen

Using AI Code Generation

copy

Full Screen

1var JSONStream = require('JSONStream');2var fs = require('fs');3var assert = require('assert');4var stream = fs.createReadStream('test.json');5var parser = JSONStream.parse('*');6stream.pipe(parser);7parser.on('data', function (obj) {8 assert.equal(typeof obj, 'object');9 console.log('object!');10});11parser.on('end', function () {12 console.log('end!');13});14[{"name":"John Doe","age":25},{"name":"Jane Doe","age":23}]15### JSONStream.parse([path])16### JSONStream.stringify()

Full Screen

Using AI Code Generation

copy

Full Screen

1var JSONStream = require('JSONStream');2var fs = require('fs');3var parser = JSONStream.parse();4fs.createReadStream('test.json').pipe(parser);5parser.on('data', function(obj) {6 console.log(obj);7});8{9 "address": {10 }11}12JSONStream.parse(path) parses the JSON stream and emits the objects found at path. path is a JSON path expression that can be used to extract sub-objects from the stream. For example, if you have a stream of objects that look like:13{ "a" : "b", "c" : "d" }14{ "a" : "b", "c" : "d" }15{ "a" : "b", "c" : "d" }16JSONStream.parse([path1, path2, ...]) emits an array of the objects found at each path. For example, if you have a stream of objects that look like:17{ "a" : "b", "c" : "d" }18{ "a" : "b", "c" : "d" }19{ "a" : "b", "c" : "d" }

Full Screen

Using AI Code Generation

copy

Full Screen

1var JSONStream = require('JSONStream');2var fs = require('fs');3var assert = require('assert');4var stream = fs.createReadStream('test.json');5stream.pipe(JSONStream.parse('*')).on('data', function(data) {6assert.equal(data, 'test data');7});

Full Screen

Using AI Code Generation

copy

Full Screen

1var JSONStream = require('JSONStream');2var fs = require('fs');3var parser = JSONStream.parse('*');4var file = fs.createReadStream('data.json');5file.pipe(parser);6parser.on('data', function (data) {7 console.log(data);8});9parser.on('end', function () {10 console.log('done');11});12{13 "scripts": {14 },15 "repository": {

Full Screen

Using AI Code Generation

copy

Full Screen

1var JSONStream = require('JSONStream');2var expect = require('chai').expect;3var fs = require('fs');4describe('JSONStream', function(){5 it('should parse json', function(done){6 var parser = JSONStream.parse('rows.*.value');7 var count = 0;8 fs.createReadStream('test.json')9 .pipe(parser)10 .on('data', function(data){11 count++;12 })13 .on('end', function(){14 expect(count).to.equal(2);15 done();16 });17 });18});19{20 {21 },22 {23 }24}25var JSONStream = require('JSONStream');26var es = require('event-stream');27var fs = require('fs');28var parser = JSONStream.parse('rows.*.value');29fs.createReadStream('test.json')30 .pipe(parser)31 .pipe(es.mapSync(function (data) {32 console.log(data);33 })34);35{36 {37 },38 {39 }40}41{42 {43 },44 {

Full Screen

Using AI Code Generation

copy

Full Screen

1var assert = require('assert');2var JSONStream = require('JSONStream');3var fs = require('fs');4var parser = JSONStream.parse('rows.*');5var counter = 0;6var expected = [ 'A', 'B', 'C', 'D', 'E' ];7parser.on('data', function (row) {8 assert.equal(row.id, expected[counter++]);9});10parser.on('end', function () {11 assert.equal(counter, 5);12});13fs.createReadStream('test.json').pipe(parser);14{15 { "id": "A", "key": "A", "value": {} },16 { "id": "B", "key": "B", "value": {} },17 { "id": "C", "key": "C", "value": {} },18 { "id": "D", "key": "D", "value": {} },19 { "id": "E", "key": "E", "value": {} }20}21Your name to display (optional):22Your name to display (optional):23Your name to display (optional):

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Mocha automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful