-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
39 changed files
with
500 additions
and
966 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: [] }); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
{ | ||
"dir": "./linden", | ||
"verbose": false | ||
"cases": [] | ||
} |
Oops, something went wrong.