it('ignored bad json with a flag', function (done) { var DATA = { example: 'pants' }; var input = through.obj(); var out = input.pipe(util.transform({ ignore: true })); ns.wait.obj(out, function (err, data) { if (err) { return done(err); } expect(data).to.be.an('array') .and.to.have.lengthOf(1) .and.to.have.property('0') .and.to.deep.equal(DATA); return done(); }); input.write(JSON.stringify(DATA)); input.write('not json data'); input.end(); });
function run(data, opts, done) { var input = through.obj(); opts = opts || {}; ns.wait.obj(input.pipe(sort(opts)), done); write(input, data); }
function checkExistingModules(next) { ns.wait.json(fs.createReadStream(pkgPath), function (err, body) { if (err && err.code === 'ENOENT') { // package.json doesn't exist, so we can move on return next(); } if (err) { return next(err); } var devDependencies = _.keys(body.devDependencies || {}); modules = _.difference(modules, devDependencies); next(); }); },
it('applies utils to a stream', function (done) { var DATA = 'pants {}'; var input = through.obj(); var out = input.pipe(util.transform({ pretrim: true })); ns.wait.obj(out, function (err, data) { if (err) { return done(err); } expect(data).to.be.an('array') .and.to.have.lengthOf(1) .and.to.have.property('0') .and.to.deep.equal({}); return done(); }); input.end(DATA); });
function addPackageScripts(next) { ns.wait.json(fs.createReadStream(pkgPath), function (err, body) { if (err && err.code === 'ENOENT') { body = {}; } else if (err) { return next(err); } var testScript = _.get(body, 'scripts.test', null); if (testScript && /echo .* \&\& exit 1/.test(testScript)) { delete body.scripts.test; } body.scripts = _.merge({ test: 'mocha', coverage: 'istanbul cover --dir coverage node_modules/mocha/bin/_mocha' }, body.scripts || {}); // We can't just stream the data into an fs.createWriteStream :( fs.writeFile(pkgPath, JSON.stringify(body, null, 2) + '\n', next); }); },