Skip to content

Commit

Permalink
Improve stdio tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mysticatea committed Nov 21, 2015
1 parent 611a956 commit 0ab60fc
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 45 deletions.
4 changes: 3 additions & 1 deletion test-workspace/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
"test-task:append:b": "node tasks/append.js b",
"test-task:append2": "node tasks/append2.js",
"test-task:error": "node tasks/error.js",
"test-task:stdio": "node tasks/stdio.js"
"test-task:stdout": "node tasks/stdout.js > test.txt",
"test-task:stderr": "node tasks/stderr.js 2> test.txt",
"test-task:stdin": "echo STDIN | node tasks/stdin.js"
},
"repository": {
"type": "git",
Expand Down
3 changes: 3 additions & 0 deletions test-workspace/tasks/stderr.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"use strict";

process.stderr.write("STDERR");
9 changes: 9 additions & 0 deletions test-workspace/tasks/stdin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"use strict";

var appendResult = require("../../test/lib/util").appendResult;

process.stdin.on("data", function(chunk) {
appendResult(chunk.toString());
process.exit(0);
});
setTimeout(function() { process.exit(1); }, 5000);
14 changes: 0 additions & 14 deletions test-workspace/tasks/stdio.js

This file was deleted.

3 changes: 3 additions & 0 deletions test-workspace/tasks/stdout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"use strict";

process.stdout.write("STDOUT");
59 changes: 29 additions & 30 deletions test/common.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import {PassThrough} from "stream";
import assert from "power-assert";
import {result, removeResult} from "./lib/util";
import BufferStream from "./lib/buffer-stream";
Expand Down Expand Up @@ -47,40 +46,40 @@ describe("[common] npm-run-all", () => {
);
});

it("stdin option should pipe to task.", () => {
const stream = new PassThrough();
const promise = runAll("test-task:stdio -- --wait-input", {stdin: stream})
.then(() => {
assert(result() === "STDIN");
});

stream.write("STDIN");
describe("stdin should be used in tasks:", () => {
it("lib version", () =>
runAll("test-task:stdin")
.then(() => assert(result().trim() === "STDIN"))
);

return promise;
it("command version", () =>
command(["test-task:stdin"])
.then(() => assert(result().trim() === "STDIN"))
);
});

it("stdout option should pipe from task.", (done) => {
const stream = new PassThrough();
stream.setEncoding("utf8");
runAll("test-task:stdio", {stdout: stream})
.then(() => {
stream.on("readable", () => {
assert(stream.read().indexOf("STDOUT") >= 0);
done();
});
});
describe("stdout should be used in tasks:", () => {
it("lib version", () =>
runAll("test-task:stdout")
.then(() => assert(result() === "STDOUT"))
);

it("command version", () =>
command(["test-task:stdout"])
.then(() => assert(result() === "STDOUT"))
);
});

it("stderr option should pipe from task.", (done) => {
const stream = new PassThrough();
stream.setEncoding("utf8");
runAll("test-task:stdio", {stderr: stream})
.then(() => {
stream.on("readable", () => {
assert(stream.read() === "STDERR");
done();
});
});
describe("stderr should be used in tasks:", () => {
it("lib version", () =>
runAll("test-task:stderr")
.then(() => assert(result() === "STDERR"))
);

it("command version", () =>
command(["test-task:stderr"])
.then(() => assert(result() === "STDERR"))
);
});

describe("should be able to use `restart` built-in task:", () => {
Expand Down

0 comments on commit 0ab60fc

Please sign in to comment.