Skip to content

Commit

Permalink
Merge 572d50a into d5056d7
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisakakay committed Feb 10, 2017
2 parents d5056d7 + 572d50a commit 9c97a24
Show file tree
Hide file tree
Showing 39 changed files with 500 additions and 966 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
sudo: false
language: node_js
node_js:
- "4"
- "5"
- "6"
cache:
directories:
- node_modules
after_success:
- npm run coveralls
- bash <(curl -s https://codecov.io/bash)
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Linden
[![Build Status](https://travis-ci.org/chrisakakay/linden.svg?branch=master)](https://travis-ci.org/chrisakakay/linden)
[![Coverage Status](https://coveralls.io/repos/github/chrisakakay/linden/badge.svg?branch=master)](https://coveralls.io/github/chrisakakay/linden?branch=master)
[![codecov](https://codecov.io/gh/chrisakakay/linden/branch/master/graph/badge.svg)](https://codecov.io/gh/chrisakakay/linden)
[![NPM version](https://img.shields.io/npm/v/linden.svg)](https://www.npmjs.com/package/linden)
[![Gitter chat](https://badges.gitter.im/chrisakakay/linden.svg)](https://gitter.im/chrisakakay/linden)

Expand All @@ -17,7 +16,7 @@ It is easy to use, easy to configure and it will be easy to integrate to any bui

- Install it globally ```npm install -g linden```
- Create a configuration in the desired folder ```linden init``` or manually ```linden.json``` (you can name it to anything)
- Add your stuff to the configuration file (ex.) ([configuration guide](/CONFIGURING.md)):
- Add your stuff to the configuration file (ex.) ([configuration guide](/CONFIGURING.md)):
```
{
"dir": "./linden",
Expand All @@ -30,7 +29,7 @@ It is easy to use, easy to configure and it will be easy to integrate to any bui
]
}
```
- Run linden with ```linden run``` or just simple ```linden``` or ```linden --config="my_config.json"```
- Run linden with ```linden run my_config.json``` or just simply run the default config with ```linden```
- Report will be generated with screenshots **[COMING SOON]**

## How to contribute
Expand Down
5 changes: 5 additions & 0 deletions __mocks__/command-init.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/* eslint-env jest */

const cmdInit = jest.genMockFromModule('../lib/command-init');

module.exports = cmdInit;
5 changes: 5 additions & 0 deletions __mocks__/command-run.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/* eslint-env jest */

const cmdRun = jest.genMockFromModule('../lib/command-run');

module.exports = cmdRun;
50 changes: 50 additions & 0 deletions __mocks__/fs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
'use strict';

/* eslint-env jest */

const fs = jest.genMockFromModule('fs');
const statData = {
'existing-file': true,
'existing-config': true,
'existing-folder': true
};
const fileData = {
'linden.json': {
dir: './linden',
cases: []
},
'existing-config': '{}'
};

function isTrue() {
return true;
}

function isFalse() {
return false;
}

function statSync(name) {
if (statData[name]) {
return {
isFile: statData[name] ? isTrue : isFalse,
isDirectory: statData[name] ? isTrue : isFalse
};
} else {
throw new Error('');
}
}

function readFileSync(name) {
return fileData[name];
}

function writeFileSync(name) {
if (name === 'file-with-error') throw new Error('File error');
}

fs.statSync = statSync;
fs.readFileSync = readFileSync;
fs.writeFileSync = writeFileSync;

module.exports = fs;
5 changes: 5 additions & 0 deletions __mocks__/helper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/* eslint-env jest */

const helper = jest.genMockFromModule('../lib/helper');

module.exports = helper;
19 changes: 19 additions & 0 deletions __mocks__/path.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/* eslint-env jest */

const path = jest.genMockFromModule('path');
const mockPaths = {
'../config/linden.json': 'linden.json'
};

function dirname(name) {
return name;
}

function join(...args) {
return mockPaths[args[1]] || args[1];
}

path.dirname = dirname;
path.join = join;

module.exports = path;
5 changes: 5 additions & 0 deletions __mocks__/test-runner.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/* eslint-env jest */

const runner = jest.genMockFromModule('../lib/test-runner');

module.exports = runner;
99 changes: 99 additions & 0 deletions __tests__/cli-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
'use strict';

/* eslint-env jest */
jest.mock('../lib/command-init');
jest.mock('../lib/test-runner');
jest.mock('../lib/command-run');

const cli = require('../lib/cli');
const cmdInit = require.requireMock('../lib/command-init');
const cmdRun = require.requireMock('../lib/command-run');
const version = '0.2.0';

global.console.log = jest.fn();

describe('CLI', () => {
beforeEach(() => {
console.log.mock.calls = [];
cmdInit.mock.calls = [];
cmdRun.mock.calls = [];
});

it('should print help on -h', () => {
cli(['-h']);

expect(console.log.mock.calls.length).toBe(1);
expect(console.log).toHaveBeenCalledWith([
'Usage: linden [command] [options]',
'',
'Commands:',
' init initializes configuration file',
' run runs the regression',
'',
'Options:',
' -h, --help prints this text',
' -v, --version prints the version',
''
].join('\n'));
});

it('should print help on --help', () => {
cli(['--help']);

expect(console.log.mock.calls.length).toBe(1);
expect(console.log).toHaveBeenCalledWith([
'Usage: linden [command] [options]',
'',
'Commands:',
' init initializes configuration file',
' run runs the regression',
'',
'Options:',
' -h, --help prints this text',
' -v, --version prints the version',
''
].join('\n'));
});

it('should print version on -v', () => {
cli(['-v']);

expect(console.log.mock.calls.length).toBe(1);
expect(console.log).toHaveBeenCalledWith('CLI version', version);
});

it('should print version on --version', () => {
cli(['--version']);

expect(console.log.mock.calls.length).toBe(1);
expect(console.log).toHaveBeenCalledWith('CLI version', version);
});

it('should run without parameters', function() {
cli([]);

expect(cmdRun.mock.calls.length).toBe(1);
expect(cmdRun).toHaveBeenCalledWith('linden.json');
});

it('should run with parameters', function() {
cli(['run', 'custom.json']);

expect(cmdRun.mock.calls.length).toBe(1);
expect(cmdRun).toHaveBeenCalledWith('custom.json');
});

it('should init', function() {
cli(['init']);

expect(cmdInit.mock.calls.length).toBe(1);
expect(cmdInit).toHaveBeenCalledWith('linden.json');
});

it('should behave...', function() {
cli(['please-no']);

expect(console.log.mock.calls.length).toBe(1);
expect(console.log).toHaveBeenCalledWith('Unknown command');
});
});
39 changes: 39 additions & 0 deletions __tests__/command-init-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
'use strict';

/* eslint-env jest */

jest.mock('fs');
jest.mock('path');
jest.mock('../lib/test-runner');

const cmdInit = require('../lib/command-init');

global.console.log = jest.fn();

describe('CMD: init', () => {
beforeEach(() => {
console.log.mock.calls = [];
});

it('should create config', () => {
let result = cmdInit('not-existing-file');

expect(result).toBe(true);
expect(console.log).not.toHaveBeenCalled();
});

it('should not create config', () => {
let result = cmdInit('existing-file');

expect(result).toBe(false);
expect(console.log).not.toHaveBeenCalled();
});

it('should handle fs error', function() {
let result = cmdInit('file-with-error');

expect(result).toBe(false);
expect(console.log).toHaveBeenCalledWith('File error');
});
});

39 changes: 39 additions & 0 deletions __tests__/command-run-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
'use strict';

/* eslint-env jest */

jest.mock('fs');
jest.mock('path');
jest.mock('../lib/test-runner');

const cmdRun = require('../lib/command-run');
const testRunner = require.requireMock('../lib/test-runner');

global.console.log = jest.fn();

describe('CMD: run', () => {
beforeEach(() => {
console.log.mock.calls = [];
testRunner.init.mock.calls = [];
});

it('should not run without a filename', () => {
expect(cmdRun()).toBe(false);
});

it('should not run without existing config', () => {
cmdRun('not-existing-config');

expect(console.log).toHaveBeenCalledWith('Configuration not found:', 'not-existing-config');
expect(testRunner.init).not.toHaveBeenCalled();
});

it('should run with existing config', () => {
cmdRun('existing-config');

expect(console.log).not.toHaveBeenCalledWith('Configuration not found:', 'existing-config');
expect(testRunner.init).toHaveBeenCalledWith({ cases: [] });
});

// add more run tests
});
37 changes: 37 additions & 0 deletions __tests__/helper-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
'use strict';

/* eslint-env jest */

jest.mock('fs');
jest.mock('path');

const helper = require('../lib/helper');

describe('helper', () => {
it('fileExists()', () => {
expect(helper.fileExists()).toBe(false);
expect(helper.fileExists('')).toBe(false);
expect(helper.fileExists('not-existing-file')).toBe(false);
expect(helper.fileExists('existing-file')).toBe(true);
expect(helper.fileExists('existing-config')).toBe(true);
});

it('folderExists()', () => {
expect(helper.folderExists()).toBe(false);
expect(helper.folderExists('')).toBe(false);
expect(helper.folderExists('not-existing-folder')).toBe(false);
expect(helper.folderExists('existing-folder')).toBe(true);
});

it('getCWD()', () => {
expect(helper.getCWD()).toBe(process.cwd());
});

it('getBasePath()', () => {
expect(helper.getBasePath()).toBe(process.argv[1]);
});

it('getDefaultConfig()', () => {
expect(helper.getDefaultConfig()).toEqual({ dir: './linden', cases: [] });
});
});
14 changes: 1 addition & 13 deletions bin/linden.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@
#!/usr/bin/env node
'use strict';

var argv = require('minimist')(process.argv.slice(2), { alias: {
c: 'config',
h: 'help',
v: 'version',
s: 'silent'
}});
var paths = {
cwd: process.cwd(),
basePath: process.argv[1]
};
var g = require('../lib/globals')(argv, paths);

require('../lib/linden')(g);
require('../lib/cli.js')(process.argv.slice(2));
20 changes: 0 additions & 20 deletions codecov.yml

This file was deleted.

2 changes: 1 addition & 1 deletion config/linden.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"dir": "./linden",
"verbose": false
"cases": []
}

0 comments on commit 9c97a24

Please sign in to comment.