test('clinic flame --collect-only - missing data', function (t) { cli({ relayStderr: false }, [ 'clinic', 'flame', '--visualize-only', 'missing.flamegraph' ], function (err, stdout, stderr) { t.strictDeepEqual(err, new Error('process exited with exit code 1')) t.strictEqual(stdout, '') t.match(stderr, /Unknown argument "missing\.flamegraph"\. Pattern: {pid}\.clinic-{command}/) t.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 and select first item", t => { setup(t); const cwd = t.testdir({ "ntl-rerun-cache": `[{"k": "${t .testdir() .split("\\") .join("/")}", "v": [ "build" ], "e": 0 }]`, "package.json": JSON.stringify({ scripts: { build: 'echo "build"' } }) }); const cp = run({ alias: "rerun.js", cwd }, ["--rerun-cache-dir", cwd]); cp.assertNotStderrData(t); cp.getStdoutResult().then(res => { t.match(readLastLine(res), /build/, "should be able to run task"); t.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(); });
"simple-output": { error: msg => { t.match( msg,
child_process: { execSync: cmd => { t.match(cmd, /npm run (build|test)/, "should run multiple commands");
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(); });
tap.test('command > run handler > rejecting promise affects result', async t => { const result = await Api.get() .command('reject', argv => Promise.reject(new Error('Rejected'))) .parse('reject') t.equal(result.code, 1) t.match(result.output, /Rejected/) t.equal(result.errors.length, 1) })
test('Index exports are correct', async (t) => { t.equal(Object.keys(index).length, 5, 'property count is correct') t.match(index, { cleanUpAll: logger.cleanUpAll , createLogger: logger.createLogger , flushAll: logger.flushAll , Logger: logger.Logger , setupDefaultLogger: Function }, 'Exported properties are correct') })
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 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 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 --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(); });