Skip to content

Commit

Permalink
improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
deepu105 committed Jul 16, 2017
1 parent 45f36d0 commit a0ba95d
Show file tree
Hide file tree
Showing 20 changed files with 208 additions and 368 deletions.
File renamed without changes.
28 changes: 14 additions & 14 deletions test/test-cli-utils.js → test/cli-utils.spec.js
Original file line number Diff line number Diff line change
@@ -1,76 +1,76 @@
/* global describe, it */

const assert = require('assert');
const expect = require('chai').expect;
const cliUtil = require('../cli/utils');
const packageJson = require('../package.json');

describe('jhipster cli utils test', () => {
describe('getArgs', () => {
describe('when called without argument', () => {
it('returns an empty string', () => {
assert.equal(cliUtil.getArgs({}), '');
expect(cliUtil.getArgs({})).to.equal('');
});
});
describe('when called with argument array', () => {
const argument = ['test', 'foo'];
it('returns a joined string', () => {
assert.equal(cliUtil.getArgs({ argument }), '[test foo]');
expect(cliUtil.getArgs({ argument })).to.equal('[test foo]');
});
});
});
describe('getOptionsFromArgs', () => {
describe('when called with empty args', () => {
it('returns an empty array', () => {
assert.deepEqual(cliUtil.getOptionsFromArgs([]), []);
expect(cliUtil.getOptionsFromArgs([])).to.eql([]);
});
});
describe('when called with string arguments', () => {
const argument = ['test', 'foo'];
it('returns an array with strings', () => {
assert.deepEqual(cliUtil.getOptionsFromArgs(argument), ['test', 'foo']);
expect(cliUtil.getOptionsFromArgs(argument)).to.eql(['test', 'foo']);
});
});
describe('when called with array & string argument', () => {
const argument = [['bar', 'test'], 'foo'];
it('returns an array with strings', () => {
assert.deepEqual(cliUtil.getOptionsFromArgs(argument), ['bar', 'test', 'foo']);
expect(cliUtil.getOptionsFromArgs(argument)).to.eql(['bar', 'test', 'foo']);
});
});
describe('when called with array & object argument', () => {
const argument = [['bar'], { foo: 'foo' }];
it('returns an array with valid strings', () => {
assert.deepEqual(cliUtil.getOptionsFromArgs(argument), ['bar']);
expect(cliUtil.getOptionsFromArgs(argument)).to.eql(['bar']);
});
});
});
describe('getCommand', () => {
describe('when called with only cmd', () => {
it('returns a default command', () => {
assert.deepEqual(cliUtil.getCommand('app'), 'jhipster:app');
expect(cliUtil.getCommand('app')).to.eql('jhipster:app');
});
});
describe('when called with cmd & invalid opts', () => {
it('returns a default command', () => {
assert.deepEqual(cliUtil.getCommand('app', {}, {}), 'jhipster:app');
expect(cliUtil.getCommand('app', {}, {})).to.eql('jhipster:app');
});
});
describe('when called with cmd, args & valid opts', () => {
const argument = [['bar', 'foo']];
it('returns a command with argument', () => {
assert.deepEqual(cliUtil.getCommand('app', argument, { argument }), 'jhipster:app bar foo');
expect(cliUtil.getCommand('app', argument, { argument })).to.eql('jhipster:app bar foo');
});
});
});
describe('getCommandOptions', () => {
describe('when called with empty argv', () => {
it('returns an empty object', () => {
assert.deepEqual(cliUtil.getCommandOptions(packageJson, []), {});
expect(cliUtil.getCommandOptions(packageJson, [])).to.eql({});
});
});
describe('when called with argv flags', () => {
const argv = ['--force', '--skip-install'];
it('returns an object with camelcase and dashcase keys', () => {
assert.deepEqual(cliUtil.getCommandOptions(packageJson, argv), {
expect(cliUtil.getCommandOptions(packageJson, argv)).to.eql({
force: true,
'skip-install': true,
skipInstall: true
Expand All @@ -80,7 +80,7 @@ describe('jhipster cli utils test', () => {
describe('when called with argv flags with value', () => {
const argv = ['--force', '--skip-install', '--foo', 'bar'];
it('returns an object with camelcase and dashcase keys', () => {
assert.deepEqual(cliUtil.getCommandOptions(packageJson, argv), {
expect(cliUtil.getCommandOptions(packageJson, argv)).to.eql({
force: true,
'skip-install': true,
skipInstall: true,
Expand All @@ -91,7 +91,7 @@ describe('jhipster cli utils test', () => {
describe('when called with argv flags with value array', () => {
const argv = ['--force', '--skip-install', '--foo', 'bar,who'];
it('returns an object with camelcase and dashcase keys', () => {
assert.deepEqual(cliUtil.getCommandOptions(packageJson, argv), {
expect(cliUtil.getCommandOptions(packageJson, argv)).to.eql({
force: true,
'skip-install': true,
skipInstall: true,
Expand Down
13 changes: 7 additions & 6 deletions test/test-cli.js → test/cli.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* global describe, it */
/* eslint-disable no-unused-expressions */

const assert = require('assert');
const expect = require('chai').expect;
const exec = require('child_process').exec;
const path = require('path');

Expand All @@ -10,14 +11,14 @@ describe('jhipster cli test', () => {

it('--help should run without errors', (done) => {
exec(`${cmd} --help`, (error, stdout, stderr) => {
assert(!error);
expect(error).to.be.null;
done();
});
});

it('--version should run without errors', (done) => {
exec(`${cmd} --version`, (error, stdout, stderr) => {
assert(!error);
expect(error).to.be.null;
done();
});
});
Expand All @@ -26,9 +27,9 @@ describe('jhipster cli test', () => {
this.timeout(4000);

exec(`${cmd} junkcmd`, (error, stdout, stderr) => {
assert(error);
assert.equal(error.code, 1);
assert.equal(stderr.includes('is not a known command'), true);
expect(error).to.not.be.null;
expect(error.code).to.equal(1);
expect(stderr.includes('is not a known command')).to.be.true;
done();
});
});
Expand Down
6 changes: 3 additions & 3 deletions test/test-creation.js → test/creation.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ const path = require('path');
const assert = require('yeoman-assert');
const helpers = require('yeoman-test');
const fse = require('fs-extra');
const getFilesForOptions = require('./utils').getFilesForOptions;
const expectedFiles = require('./test-expected-files');
const shouldBeV3DockerfileCompatible = require('./utils').shouldBeV3DockerfileCompatible;
const getFilesForOptions = require('./utils/utils').getFilesForOptions;
const expectedFiles = require('./utils/expected-files');
const shouldBeV3DockerfileCompatible = require('./utils/utils').shouldBeV3DockerfileCompatible;
const constants = require('../generators/generator-constants');
const angularJsfiles = require('../generators/client/files-angularjs').files;
const angularfiles = require('../generators/client/files-angular').files;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const assert = require('assert');
const jhiCore = require('jhipster-core');
const expectedFiles = require('./test-expected-files');
const expectedFiles = require('./utils/expected-files');
const BaseGenerator = require('../generators/generator-base').prototype;

BaseGenerator.log = (msg) => { console.log(msg); }; // eslint-disable-line no-console
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const constants = require('../generators/generator-constants');
const constants = require('../../generators/generator-constants');

const TEST_DIR = constants.TEST_DIR;
const CLIENT_MAIN_SRC_DIR = constants.CLIENT_MAIN_SRC_DIR;
Expand Down
4 changes: 2 additions & 2 deletions test/utils.js → test/utils/utils.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* global describe, beforeEach, it*/
const assert = require('yeoman-assert');
const Generator = require('../generators/generator-base');
const constants = require('../generators/generator-constants');
const Generator = require('../../generators/generator-base');
const constants = require('../../generators/generator-constants');

const DOCKER_DIR = constants.DOCKER_DIR;

Expand Down
Loading

0 comments on commit a0ba95d

Please sign in to comment.