test.serial('Running `carbon-now` fails without file or stdin', async t => { try { // https://github.com/sindresorhus/get-stdin/issues/13#issuecomment-279234249 const command = exec(`node ${SCRIPT}`); command.childProcess.stdin.end(); await command; t.fail(); } catch (error) { t.pass(); } });
function capture () { const ws = writer((chunk, enc, cb) => { ws.data += chunk.toString() cb() }) ws.data = '' return ws }
test('pino uses LF by default', async ({ ok }) => { const stream = capture() const logger = pino(stream) logger.info('foo') logger.error('bar') ok(/foo[^\r\n]+\n[^\r\n]+bar[^\r\n]+\n/.test(stream.data)) })
test("ntl run using --exclude option", t => { const cwd = t.testdir({ "package.json": JSON.stringify({ scripts: { build: 'echo "build"', test: 'echo "test"' } }) }); const cp = run({ cwd }, ["--exclude", "build"]); cp.assertNotStderrData(t); cp.getStdoutResult().then(res => { t.match(readLastLine(res), /test/, "should not list excluded tasks"); t.end(); }); cp.stdin.write("\n"); cp.stdin.end(); });
through.obj(function (file, encoding, callback) { ctx.ready(function () { ssh.sftp(function (err, sftp) { if (err) return callback(new gutil.PluginError(packageName, err)) options.autoClose = true var write = sftp.createWriteStream(filePath, options) write .on('error', function (error) { err = error }) .on('finish', function () { sftp.end() if (err) callback(err) else callback(null, file) }) if (file.isStream()) file.pipe(write) else if (file.isBuffer()) write.end(file.contents); else { err = new gutil.PluginError(packageName, 'file error!') write.end() } }) }) })
test("ntl run using an absolute path argument", t => { const cwd = path.relative( __dirname, t.testdir({ "package.json": JSON.stringify({ scripts: { build: 'echo "build"' } }) }) ); const cp = run({ cwd: __dirname }, [cwd]); cp.assertNotStderrData(t); cp.getStdoutResult().then(res => { t.match(readLastLine(res), /build/, "should be able to run task"); t.end(); }); cp.stdin.write("\n"); cp.stdin.end(); });
test("ntl found malformed package.json on current dir", t => { const cwd = t.testdir({ "package.json": '{"name": "foo" "version": "1.0.0"}' }); t.plan(2); const cp = run({ cwd }); cp.assertExitCode(t, 1, "should exit with error code"); cp.getStderrResult().then(res => { const taskOutput = res.toString().trim(); t.ok( taskOutput.endsWith("package.json contains malformed JSON"), "should print malformed package.json msg to stderr" ); }); cp.stdin.write("\n"); cp.stdin.end(); });
test("ntl run using --descriptions option but no description avail", t => { const cwd = t.testdir({ "package.json": JSON.stringify({ scripts: { build: 'echo "build"' } }) }); const cp = run({ cwd }, ["--descriptions"]); cp.assertNotStderrData(t); cp.getStdoutResult().then(res => { const taskOutput = res[0].toString().trim(); t.ok( taskOutput.endsWith("No descriptions for your npm scripts found"), "should print warn message" ); t.end(); }); cp.stdin.write("\n"); cp.stdin.end(); });
test("ntl run and select first item", t => { const cwd = t.testdir({ "package.json": JSON.stringify({ scripts: { build: 'echo "build"' }, ntl: { runner: "echo" } }) }); const cp = run({ cwd }); cp.assertNotStderrData(t); cp.getStdoutResult().then(res => { t.equal( readLastLine(res), "run build", "should config-defined custom runner" ); t.end(); }); cp.stdin.write("\n"); cp.stdin.end(); });
test('pino can log CRLF', async ({ ok }) => { const stream = capture() const logger = pino({ crlf: true }, stream) logger.info('foo') logger.error('bar') ok(/foo[^\n]+\r\n[^\n]+bar[^\n]+\r\n/.test(stream.data)) })
test("ntl run and select first item", t => { const cwd = t.testdir({ "package.json": JSON.stringify({ scripts: { build: 'echo "build"' } }) }); const cp = run({ cwd }); cp.assertNotStderrData(t); cp.getStdoutResult().then(res => { t.match(readLastLine(res), /build/, "should be able to run task"); t.end(); }); cp.stdin.write("\n"); cp.stdin.end(); });
test("ntl run using an absolute path argument", t => { const cwd = t.testdir({ "package.json": JSON.stringify({ scripts: { build: 'echo "build"' } }) }); const cp = run({ cwd: __dirname }, [cwd]); cp.assertNotStderrData(t); cp.getStdoutResult().then(res => { t.match(readLastLine(res), /build/, "should be able to run task"); t.end(); }); cp.stdin.write("\n"); cp.stdin.end(); });
test("ntl run but not package.json in current dir", t => { const cwd = t.testdir({ "README.md": "# empty folder" }); t.plan(2); const cp = run({ cwd }); cp.assertExitCode(t, 1, "should exit with error code"); cp.getStderrResult().then(res => { const taskOutput = res.toString().trim(); t.ok( taskOutput.endsWith("No package.json found"), "should print no package.json found msg to stderr" ); }); cp.stdin.write("\n"); cp.stdin.end(); });
test("ntl forward trailing options", t => { const cwd = t.testdir({ "package.json": JSON.stringify({ scripts: { test: "node test.js" } }), "test.js": "console.log(process.argv.slice(2).join(''))" }); const cp = run({ cwd }, ["--all", "--", "--one-more-thing"]); cp.assertNotStderrData(t); cp.getStdoutResult().then(res => { t.equal( readLastLine(res), "--one-more-thing", "should forward trailing options" ); t.end(); }); cp.stdin.write("\n"); cp.stdin.end(); });