Skip to content

Commit c6d7d90

Browse files
committed
Add tests
1 parent e5308d1 commit c6d7d90

9 files changed

Lines changed: 104 additions & 27 deletions

File tree

test/BinTestCases.test.js

Lines changed: 65 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -61,46 +61,84 @@ describe("BinTestCases", function() {
6161
cwd: path.resolve("./", testDirectory)
6262
};
6363

64+
const async = fs.existsSync(path.join(testDirectory, "async"));
65+
6466
const env = {
6567
stdout: [],
6668
stderr: [],
6769
error: []
6870
};
6971

70-
describe(testName, function() {
71-
before(function(done) {
72-
this.timeout(20000);
73-
74-
const child = spawn(process.execPath, [cmd].concat(args), opts);
75-
76-
child.on("close", function(code) {
77-
env.code = code;
78-
done();
72+
if (async) {
73+
describe(testName, function() {
74+
it("should run successfully", function(done) {
75+
this.timeout(10000);
76+
const child = spawn(process.execPath, [cmd].concat(args), opts);
77+
78+
child.on("close", function(code) {
79+
env.code = code;
80+
});
81+
82+
child.on("error", function(error) {
83+
env.error.push(error);
84+
});
85+
86+
child.stdout.on("data", (data) => {
87+
env.stdout.push(data);
88+
});
89+
90+
child.stderr.on("data", (data) => {
91+
env.stderr.push(data);
92+
});
93+
94+
setTimeout(() => {
95+
if (env.code) {
96+
done(env.error)
97+
}
98+
99+
const stdout = convertToArrayOfLines(env.stdout);
100+
const stderr = convertToArrayOfLines(env.stderr);
101+
testAssertions(stdout, stderr, done);
102+
child.kill()
103+
}, 3000); // wait a little to get an output
79104
});
80-
81-
child.on("error", function(error) {
82-
env.error.push(error);
105+
})
106+
} else {
107+
describe(testName, function() {
108+
before(function(done) {
109+
this.timeout(20000);
110+
111+
const child = spawn(process.execPath, [cmd].concat(args), opts);
112+
113+
child.on("close", function(code) {
114+
env.code = code;
115+
done();
116+
});
117+
118+
child.on("error", function(error) {
119+
env.error.push(error);
120+
});
121+
122+
child.stdout.on("data", (data) => {
123+
env.stdout.push(data);
124+
});
125+
126+
child.stderr.on("data", (data) => {
127+
env.stderr.push(data);
128+
});
83129
});
84130

85-
child.stdout.on("data", (data) => {
86-
env.stdout.push(data);
131+
it("should not cause any errors", function() {
132+
should(env.error).be.empty();
87133
});
88134

89-
child.stderr.on("data", (data) => {
90-
env.stderr.push(data);
135+
it("should run successfully", function() {
136+
const stdout = convertToArrayOfLines(env.stdout);
137+
const stderr = convertToArrayOfLines(env.stderr);
138+
testAssertions(env.code, stdout, stderr);
91139
});
92140
});
93-
94-
it("should not cause any errors", function() {
95-
should(env.error).be.empty();
96-
});
97-
98-
it("should run successfully", function() {
99-
const stdout = convertToArrayOfLines(env.stdout);
100-
const stderr = convertToArrayOfLines(env.stderr);
101-
testAssertions(env.code, stdout, stderr);
102-
});
103-
});
141+
}
104142
});
105143
});
106144
});

test/binCases/watch/multi-config/async

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = "foo";
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = "bar";
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
"use strict";
2+
3+
module.exports = function testAssertions(stdout, stderr, done) {
4+
stdout.should.be.ok();
5+
stdout[0].should.containEql("");
6+
stdout[1].should.containEql("Webpack is watching the files…");
7+
8+
stderr.should.be.empty();
9+
done();
10+
};
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
var path = require("path");
2+
3+
module.exports = [
4+
{
5+
entry: path.resolve(__dirname, "./index"),
6+
watch: true
7+
},
8+
{
9+
entry: path.resolve(__dirname, "./index2")
10+
}
11+
];

test/binCases/watch/single-config/async

Whitespace-only changes.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
"use strict";
2+
3+
module.exports = function testAssertions(stdout, stderr, done) {
4+
stdout.should.be.ok();
5+
stdout[0].should.containEql("");
6+
stdout[1].should.containEql("Webpack is watching the files…");
7+
8+
stderr.should.be.empty();
9+
done();
10+
};
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
var path = require("path");
2+
3+
module.exports = {
4+
entry: path.resolve(__dirname, "./index"),
5+
watch: true
6+
};

0 commit comments

Comments
 (0)