Skip to content

Commit

Permalink
Add basic tests. (#208)
Browse files Browse the repository at this point in the history
* Fixes #205 
* Add the most minimal skeleton tests to import most files and check for rudimentary breakage.
* Make `bin/webpack-dashboard.js` exportable in addition to being a script.
* Follow-on real test ticket at #207 
* Update eslintrc to use `arrow-parens: [error, as-needed]`
  • Loading branch information
ryan-roemer authored Oct 10, 2017
1 parent 7f02ea9 commit c9be427
Show file tree
Hide file tree
Showing 15 changed files with 2,711 additions and 260 deletions.
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ extends:
- formidable/configurations/es6-node
rules:
func-style: off
arrow-parens: off
arrow-parens: [error, as-needed]
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ node_modules

# misc
.DS_Store
npm-debug.log
npm-debug.log
.nyc_output
.coverage
8 changes: 8 additions & 0 deletions .nycrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"reporter": [
"html",
"lcov",
"text-summary"
],
"report-dir": "./.coverage"
}
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ branches:

script:
- yarn --version
- yarn run check
- yarn run check-ci
142 changes: 76 additions & 66 deletions bin/webpack-dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,83 +9,93 @@ const SocketIO = require("socket.io");
const DEFAULT_PORT = 9838;

const program = new commander.Command("webpack-dashboard");

const pkg = require("../package.json");
program.version(pkg.version);
program.option("-c, --color [color]", "Dashboard color");
program.option("-m, --minimal", "Minimal mode");
program.option("-t, --title [title]", "Terminal window title");
program.option("-p, --port [port]", "Socket listener port");
program.usage("[options] -- [script] [arguments]");
program.parse(process.argv);

let logFromChild = true;
let child;

if (!program.args.length) {
logFromChild = false;
}

if (logFromChild) {
const command = program.args[0];
const args = program.args.slice(1);
const env = process.env;

env.FORCE_COLOR = true;
// Wrap up side effects in a script.
const main = module.exports = opts => { // eslint-disable-line max-statements
opts = opts || {};
const argv = typeof opts.argv === "undefined" ? process.argv : opts.argv;

program.version(pkg.version);
program.option("-c, --color [color]", "Dashboard color");
program.option("-m, --minimal", "Minimal mode");
program.option("-t, --title [title]", "Terminal window title");
program.option("-p, --port [port]", "Socket listener port");
program.usage("[options] -- [script] [arguments]");
program.parse(argv);

let logFromChild = true;
let child;

if (!program.args.length) {
logFromChild = false;
}

if (logFromChild) {
const command = program.args[0];
const args = program.args.slice(1);
const env = process.env;

env.FORCE_COLOR = true;

child = spawn(command, args, {
env,
stdio: [null, null, null, null],
detached: true
});
}

child = spawn(command, args, {
env,
stdio: [null, null, null, null],
detached: true
const dashboard = new Dashboard({
color: program.color || "green",
minimal: program.minimal || false,
title: program.title || null
});
}

const dashboard = new Dashboard({
color: program.color || "green",
minimal: program.minimal || false,
title: program.title || null
});
const port = program.port || DEFAULT_PORT;
const server = opts.server || new SocketIO(port);

const port = program.port || DEFAULT_PORT;
const server = new SocketIO(port);

server.on("error", (err) => {
// eslint-disable-next-line no-console
console.log(err);
});
server.on("error", err => {
// eslint-disable-next-line no-console
console.log(err);
});

if (logFromChild) {
server.on("connection", (socket) => {
socket.emit("mode", { minimal: program.minimal || false });
if (logFromChild) {
server.on("connection", socket => {
socket.emit("mode", { minimal: program.minimal || false });

socket.on("message", (message) => {
if (message.type !== "log") {
dashboard.setData(message);
}
socket.on("message", message => {
if (message.type !== "log") {
dashboard.setData(message);
}
});
});
});

child.stdout.on("data", (data) => {
dashboard.setData([{
type: "log",
value: data.toString("utf8")
}]);
});
child.stdout.on("data", data => {
dashboard.setData([{
type: "log",
value: data.toString("utf8")
}]);
});

child.stderr.on("data", (data) => {
dashboard.setData([{
type: "log",
value: data.toString("utf8")
}]);
});
child.stderr.on("data", data => {
dashboard.setData([{
type: "log",
value: data.toString("utf8")
}]);
});

process.on("exit", () => {
process.kill(process.platform === "win32" ? child.pid : -child.pid);
});
} else {
server.on("connection", (socket) => {
socket.on("message", (message) => {
dashboard.setData(message);
process.on("exit", () => {
process.kill(process.platform === "win32" ? child.pid : -child.pid);
});
});
} else {
server.on("connection", socket => {
socket.on("message", message => {
dashboard.setData(message);
});
});
}
};

if (require.main === module) {
main();
}
Loading

0 comments on commit c9be427

Please sign in to comment.