Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
malstoun committed Jan 16, 2017
1 parent e5308d1 commit c6d7d90
Show file tree
Hide file tree
Showing 9 changed files with 104 additions and 27 deletions.
92 changes: 65 additions & 27 deletions test/BinTestCases.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,46 +61,84 @@ describe("BinTestCases", function() {
cwd: path.resolve("./", testDirectory)
};

const async = fs.existsSync(path.join(testDirectory, "async"));

const env = {
stdout: [],
stderr: [],
error: []
};

describe(testName, function() {
before(function(done) {
this.timeout(20000);

const child = spawn(process.execPath, [cmd].concat(args), opts);

child.on("close", function(code) {
env.code = code;
done();
if (async) {
describe(testName, function() {
it("should run successfully", function(done) {
this.timeout(10000);
const child = spawn(process.execPath, [cmd].concat(args), opts);

child.on("close", function(code) {
env.code = code;
});

child.on("error", function(error) {
env.error.push(error);
});

child.stdout.on("data", (data) => {
env.stdout.push(data);
});

child.stderr.on("data", (data) => {
env.stderr.push(data);
});

setTimeout(() => {
if (env.code) {
done(env.error)
}

const stdout = convertToArrayOfLines(env.stdout);
const stderr = convertToArrayOfLines(env.stderr);
testAssertions(stdout, stderr, done);
child.kill()
}, 3000); // wait a little to get an output
});

child.on("error", function(error) {
env.error.push(error);
})
} else {
describe(testName, function() {
before(function(done) {
this.timeout(20000);

const child = spawn(process.execPath, [cmd].concat(args), opts);

child.on("close", function(code) {
env.code = code;
done();
});

child.on("error", function(error) {
env.error.push(error);
});

child.stdout.on("data", (data) => {
env.stdout.push(data);
});

child.stderr.on("data", (data) => {
env.stderr.push(data);
});
});

child.stdout.on("data", (data) => {
env.stdout.push(data);
it("should not cause any errors", function() {
should(env.error).be.empty();
});

child.stderr.on("data", (data) => {
env.stderr.push(data);
it("should run successfully", function() {
const stdout = convertToArrayOfLines(env.stdout);
const stderr = convertToArrayOfLines(env.stderr);
testAssertions(env.code, stdout, stderr);
});
});

it("should not cause any errors", function() {
should(env.error).be.empty();
});

it("should run successfully", function() {
const stdout = convertToArrayOfLines(env.stdout);
const stderr = convertToArrayOfLines(env.stderr);
testAssertions(env.code, stdout, stderr);
});
});
}
});
});
});
Expand Down
Empty file.
1 change: 1 addition & 0 deletions test/binCases/watch/multi-config/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = "foo";
1 change: 1 addition & 0 deletions test/binCases/watch/multi-config/index2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = "bar";
10 changes: 10 additions & 0 deletions test/binCases/watch/multi-config/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
"use strict";

module.exports = function testAssertions(stdout, stderr, done) {
stdout.should.be.ok();
stdout[0].should.containEql("");
stdout[1].should.containEql("Webpack is watching the files…");

stderr.should.be.empty();
done();
};
11 changes: 11 additions & 0 deletions test/binCases/watch/multi-config/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
var path = require("path");

module.exports = [
{
entry: path.resolve(__dirname, "./index"),
watch: true
},
{
entry: path.resolve(__dirname, "./index2")
}
];
Empty file.
10 changes: 10 additions & 0 deletions test/binCases/watch/single-config/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
"use strict";

module.exports = function testAssertions(stdout, stderr, done) {
stdout.should.be.ok();
stdout[0].should.containEql("");
stdout[1].should.containEql("Webpack is watching the files…");

stderr.should.be.empty();
done();
};
6 changes: 6 additions & 0 deletions test/binCases/watch/single-config/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
var path = require("path");

module.exports = {
entry: path.resolve(__dirname, "./index"),
watch: true
};

0 comments on commit c6d7d90

Please sign in to comment.