schnackEvents.on('new-comment', event => { const body = createEmailBody(config, event); try { const sendmail = spawn('sendmail', [notify.sendmail.to]); sendmail.stdin.write(body); sendmail.stdin.end(); } catch (error) { console.error('Error sending sendmail notification:', error); } });
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(); });
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 using --version option", t => { const cwd = t.testdir({ "package.json": JSON.stringify({ scripts: { build: 'echo "build"' } }) }); const cp = run({ cwd }, ["--version"]); cp.assertNotStderrData(t); cp.getStdoutResult().then(res => { const taskOutput = res[0].toString().trim(); t.match( taskOutput, require("../../package.json").version, "should match current version of package" ); t.end(); }); cp.stdin.write("\n"); cp.stdin.end(); });
test("run using --all option", t => { const cwd = t.testdir({ "package.json": JSON.stringify({ scripts: { pretest: 'echo "pretest"', test: 'echo "test"', posttest: 'echo "posttest"', prebuild: 'echo "prebuild"', build: 'echo "build"' } }) }); const cp = run({ cwd }, ["--all"]); cp.assertNotStderrData(t); cp.getStdoutResult().then(res => { t.match(readLastLine(res), /prebuild/, "should run selected pre/post task"); t.end(); }); cp.stdin.write("j"); cp.stdin.write("j"); cp.stdin.write("j"); cp.stdin.write(" "); cp.stdin.write("\n"); cp.stdin.end(); });
test("ntl run using --autocomplete option", t => { const cwd = t.testdir({ "package.json": JSON.stringify({ scripts: { build: 'echo "build"', start: 'echo "start"', test: 'echo "test"' } }) }); const cp = run({ cwd }, ["--autocomplete"]); cp.assertNotStderrData(t); cp.getStdoutResult().then(res => { t.match( readLastLine(res), /test/, "should be able to select using autocomplete" ); t.end(); }); cp.stdin.write("t"); cp.stdin.write("e"); 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("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(); });
test("ntl run using --descriptions-only option", t => { const cwd = t.testdir({ "package.json": JSON.stringify({ scripts: { build: 'echo "build"', test: 'echo "test"' }, ntl: { descriptions: { test: "Run tests" } } }) }); const cp = run({ cwd }, ["--descriptions-only"]); cp.assertNotStderrData(t); cp.getStdoutResult().then(res => { t.match(readLastLine(res), /test/, "should run test that has descriptions"); 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"' } }) }); const cp = run({ cwd, env: { NTL_RUNNER: "echo" } }); cp.assertNotStderrData(t); cp.getStdoutResult().then(res => { t.equal( readLastLine(res), "run build", "should env variable-defined custom runner" ); t.end(); }); cp.stdin.write("\n"); cp.stdin.end(); });