Skip to content

Commit 142f2a2

Browse files
authored
Merge pull request #111 from fobos/elm-app-test-tests
test(elm-app test): Add tests for 'elm-app test' command
2 parents ac0fcf7 + ff3bc7f commit 142f2a2

File tree

3 files changed

+49
-7
lines changed

3 files changed

+49
-7
lines changed

tests/cliAccessibility.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,19 @@ describe('Test command line interface functionality', function () {
1111

1212
describe('CLI accessibility', function () {
1313
it('`create-elm-app` command should be available', function () {
14-
var output = spawn.sync('create-elm-app').output;
14+
const output = spawn.sync('create-elm-app').output;
1515
expect(output.toString()).to.have.string('Usage: create-elm-app <project-directory>');
1616
});
1717

1818
it('`elm-app` command should be available', function () {
19-
var result = spawn.sync('elm-app');
20-
var output = result.output;
19+
const result = spawn.sync('elm-app');
20+
const output = result.output;
2121
expect(output.toString()).to.have.string('Usage: elm-app <command>');
2222
});
2323

2424
it('`elm-app package` command should be available', function () {
25-
var result = spawn.sync('elm-app', [ 'package' ]);
26-
var output = concatsStringBuffers(result.output);
25+
const result = spawn.sync('elm-app', [ 'package' ]);
26+
const output = concatsStringBuffers(result.output);
2727
expect(output).to.have.string('install and publish elm packages');
2828
});
2929
});

tests/elm-app.build.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ describe('Building Elm application with `elm-app build`', function () {
2929
});
3030

3131
it('`elm-app build` should succeed in `' + testAppName + '`', function () {
32-
var result = spawn.sync('node', [ elmAppCmd, 'build' ]);
33-
var outputString = result.output.map(function (out) {
32+
const result = spawn.sync('node', [ elmAppCmd, 'build' ]);
33+
const outputString = result.output.map(function (out) {
3434
return (out !== null) ? out.toString() : '';
3535
}).join('');
3636
expect(result.status).to.be.equal(0, 'Incorrect exit status code');

tests/elm-app.test.spec.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
const path = require('path');
2+
const spawn = require('cross-spawn');
3+
const rimraf = require('rimraf');
4+
const expect = require('chai').expect;
5+
6+
7+
const testAppName = 'test-app';
8+
const rootDir = path.resolve(__dirname, '..');
9+
const testAppDir = path.join(rootDir, testAppName);
10+
const createElmAppCmd = path.join(rootDir, 'bin/create-elm-app-cli.js');
11+
const elmAppCmd = path.join(rootDir, 'bin/elm-app-cli.js');
12+
13+
describe('Testing Elm application with `elm-app test` (Please wait...)', function () {
14+
before(function (done) {
15+
const cmd = spawn.sync('node', [ createElmAppCmd, testAppName ]);
16+
17+
if (cmd.status === 0) {
18+
process.chdir(testAppDir);
19+
done();
20+
} else {
21+
done(false);
22+
}
23+
});
24+
25+
after(function () {
26+
process.chdir(rootDir);
27+
rimraf.sync(testAppDir);
28+
});
29+
30+
it('`elm-app test` should succeed in `' + testAppName + '`', function () {
31+
const result = spawn.sync('node', [ elmAppCmd, 'test' ]);
32+
const outputString = result.output.map(function (out) {
33+
return (out !== null) ? out.toString() : '';
34+
}).join('');
35+
36+
expect(result.status).to.be.at.least(1);
37+
expect(outputString).to.have.string('This test should fail');
38+
expect(outputString).to.have.string('failed as expected!');
39+
}).timeout(2 * 60 * 1000);
40+
});
41+
42+

0 commit comments

Comments
 (0)