From 8a2fe0d54038856ee0e85f06e15e97455c88e8b9 Mon Sep 17 00:00:00 2001 From: Luke Childs Date: Thu, 2 Jun 2016 21:40:32 +0100 Subject: [PATCH] Add cli tests --- package.json | 1 + test/unit.js | 22 +++++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 0e82f9f..6b61d98 100644 --- a/package.json +++ b/package.json @@ -54,6 +54,7 @@ "babel-cli": "^6.9.0", "babel-plugin-add-module-exports": "^0.2.1", "babel-preset-es2015": "^6.9.0", + "child-process-promise": "^2.0.2", "coveralls": "^2.11.9", "eslint": "^2.11.1", "eslint-config-lukechilds": "^1.5.1", diff --git a/test/unit.js b/test/unit.js index fb5b9ac..15ac020 100644 --- a/test/unit.js +++ b/test/unit.js @@ -1,9 +1,11 @@ import test from 'ava'; import { readFileSync } from 'fs'; +import { exec } from 'child-process-promise'; import htconvert from '../dist/htconvert'; -const input = readFileSync('./fixtures/input', 'utf-8'); +const inputPath = './fixtures/input'; +const input = readFileSync(inputPath, 'utf-8'); const output = readFileSync('./fixtures/output', 'utf-8'); test('htconvert should export a function', t => { @@ -13,3 +15,21 @@ test('htconvert should export a function', t => { test('htconvert should match input with output', t => { t.is(htconvert(input), output); }); + +test('cli input with -f arg', t => { + return exec(`node ../dist/cli.js -f ${inputPath}`).then(result => { + t.is(result.stdout, output+'\n'); + }); +}); + +test('cli input with --file arg', t => { + return exec(`node ../dist/cli.js --file ${inputPath}`).then(result => { + t.is(result.stdout, output+'\n'); + }); +}); + +test('cli input from stdin', t => { + return exec(`echo "${input}" | node ../dist/cli.js`).then(result => { + t.is(result.stdout, output+'\n\n'); + }); +});