Skip to content

Commit

Permalink
starting on unit tests for setup
Browse files Browse the repository at this point in the history
  • Loading branch information
machellerogden committed Mar 9, 2017
1 parent 879a885 commit 6682f38
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 12 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
},
"scripts": {
"lint": "./node_modules/.bin/eslint .",
"test": "./node_modules/.bin/mocha \"test/**/*.js\"",
"test": "./node_modules/.bin/mocha \"test/**/*.spec.js\"",
"watch": "npm run test -- --watch",
"changelog": "./node_modules/.bin/github-changes -o carsdotcom -r bitcar",
"generate-and-stage-changelog": "npm run changelog && git add -A",
"coverage": "rm -rf coverage && node node_modules/.bin/istanbul --include-all-sources cover -x \"test/**/*.js\" --dir=\"coverage\" --root=\"./\" node_modules/.bin/_mocha -- \"test/**/*.js\"",
"check-coverage": "npm run coverage && ./node_modules/.bin/istanbul check-coverage --root=\"./coverage\" --statement 50 --function 50 --branch 45"
"coverage": "rm -rf coverage && node node_modules/.bin/istanbul --include-all-sources cover -x \"test/**/*.spec.js\" --dir=\"coverage\" --root=\"./\" node_modules/.bin/_mocha -- \"test/**/*.spec.js\"",
"check-coverage": "npm run coverage && ./node_modules/.bin/istanbul check-coverage --root=\"./coverage\" --statement 65 --function 68 --branch 50"
},
"contributors": [
{
Expand Down
17 changes: 9 additions & 8 deletions setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const path = require('path');
const inquirer = require('inquirer');
const os = require('os');
const chalk = require('chalk');
const output = require('./lib/output');

module.exports = setup;

Expand Down Expand Up @@ -123,19 +124,19 @@ source $HOME/.bitcar/completions.sh
let updatedProfile = cleanProfile(profile) + profileContent;
fs.write(path.normalize(process.env.HOME + '/.zshrc'), updatedProfile);
} else {
console.log('unsupported shell');
output.log('unsupported shell');
process.exit(1);
}

return fs.commit(function (err) {
if (err) return reject(err);
console.log('');
console.log('Bitcar setup was successful!');
console.log('');
console.log(chalk.bold.inverse('Enter `. ~/.bash_profile` and hit enter, or start a new terminal for changes to take effect.'));
console.log('');
console.log(chalk.underline('Please note you MUST use the command name you chose during setup (`' + answers.alias + '`) for the tool to work.'));
console.log(chalk.underline('Except for the setup command, DO NOT use the `bitcar` command directly'));
output.log('');
output.log('Bitcar setup was successful!');
output.log('');
output.log(chalk.bold.inverse('Enter `. ~/.bash_profile` and hit enter, or start a new terminal for changes to take effect.'));
output.log('');
output.log(chalk.underline('Please note you MUST use the command name you chose during setup (`' + answers.alias + '`) for the tool to work.'));
output.log(chalk.underline('Except for the setup command, DO NOT use the `bitcar` command directly'));
return resolve();
});
});
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion test/mocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ exports.setupAnswers = {
alias: 'bitcar',
workspaceDir: path.normalize('./.bitcar-test'),
drivers: [ 'github', 'bitbucket-server' ],
githubUsernames: [ 'carsdotcom' ],
githubUsernames: 'carsdotcom',
bitbucketServerHost: 'git.cars.com'
};

Expand Down
82 changes: 82 additions & 0 deletions test/setup.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
'use strict';
const chai = require('chai');
const expect = chai.expect;
const sinon = require('sinon');
const sinonChai = require('sinon-chai');
chai.use(sinonChai);
const chaiAsPromised = require('chai-as-promised');
chai.use(chaiAsPromised);

const setup = require('../setup');
const fs = require('../lib/fs');
const inquirer = require('inquirer');
const path = require('path');
const _ = require('lodash');
const output = require('../lib/output');

const CONFIG_PATH = path.normalize(process.env.HOME + '/.bitcar/config');

describe('the bitcar setup script', () => {
let sandbox;

beforeEach(() => {
sandbox = sinon.sandbox.create();
sandbox.stub(fs, 'commit', (cb) => cb());
sandbox.stub(output, 'log');
});

afterEach(function () {
sandbox.restore();
});

describe('when only github is selected', () => {
beforeEach(() => {
sandbox.stub(inquirer, 'prompt', (options) => {
let answers = {
alias: 'bitcar',
workspaceDir: path.normalize('./.bitcar-test'),
drivers: [ 'github' ],
githubUsernames: 'carsdotcom'
};
return Promise.resolve(answers);
});
});

it('should add github to config', () => {
return setup().then(() => {
let config = fs.readJSON(CONFIG_PATH);
expect(config.drivers.length).to.equal(1);
let githubDriver = _.find(config.drivers, { type: 'github' });
expect(githubDriver).to.be.an('object');
expect(githubDriver.type).to.equal('github');
expect(githubDriver.host).to.equal('github.com');
});
});
});

describe('when only bitbucket server is selected', () => {
beforeEach(() => {
sandbox.stub(inquirer, 'prompt', (options) => {
let answers = {
alias: 'bitcar',
workspaceDir: path.normalize('./.bitcar-test'),
drivers: [ 'bitbucket-server' ],
bitbucketServerHost: 'git.cars.com'
};
return Promise.resolve(answers);
});
});

it('should add bitbucket server to config', () => {
return setup().then(() => {
let config = fs.readJSON(CONFIG_PATH);
expect(config.drivers.length).to.equal(1);
let githubDriver = _.find(config.drivers, { type: 'bitbucket-server' });
expect(githubDriver).to.be.an('object');
expect(githubDriver.type).to.equal('bitbucket-server');
expect(githubDriver.host).to.equal('git.cars.com');
});
});
});

});

0 comments on commit 6682f38

Please sign in to comment.