-
Notifications
You must be signed in to change notification settings - Fork 1
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
12 changed files
with
558 additions
and
513 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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
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,20 @@ | ||
import indexr from '../../lib'; | ||
import { assert } from 'chai'; | ||
import { resetLog, setLogLevel, logHistory } from '../../lib/utils/logger'; | ||
export default () => { | ||
it('should throw an error in a nice way', (endTest) => { | ||
resetLog(); | ||
setLogLevel('none'); | ||
indexr(/blow/) | ||
.catch(() => { | ||
const actual = logHistory()[0]; | ||
const expected = { | ||
level: 'error', | ||
message: 'indexr >> ERROR: TypeError: Path must be a string. Received /blow/', | ||
}; | ||
assert.deepEqual(expected, actual); | ||
endTest(); | ||
}); | ||
|
||
}); | ||
}; |
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,124 @@ | ||
import { runCLI } from '../lib/utils'; | ||
import { assert } from 'chai'; | ||
export default () => { | ||
it('should support --out', () => { | ||
const actual = runCLI('indexr', '.', '--out', 'index.js'); | ||
const expected = { | ||
inputFolder: '.', | ||
options: { | ||
outputFilename: 'index.js', | ||
}, | ||
}; | ||
assert.deepEqual(expected, actual, 'Function did not return expected output.'); | ||
}); | ||
|
||
it('should support --es5', () => { | ||
const actual = runCLI('indexr', '.', '--es5'); | ||
const expected = { | ||
inputFolder: '.', | ||
options: { | ||
es5: true, | ||
}, | ||
}; | ||
assert.deepEqual(expected, actual, 'Function did not return expected output.'); | ||
}); | ||
|
||
it('should support --direct-import', () => { | ||
const actual = runCLI('indexr', '.', '--direct-import'); | ||
const expected = { | ||
inputFolder: '.', | ||
options: { | ||
directImport: true, | ||
}, | ||
}; | ||
assert.deepEqual(expected, actual, 'Function did not return expected output.'); | ||
}); | ||
|
||
it('should support --direct-import', () => { | ||
const actual = runCLI('indexr', '.', '--direct-import'); | ||
const expected = { | ||
inputFolder: '.', | ||
options: { | ||
directImport: true, | ||
}, | ||
}; | ||
assert.deepEqual(expected, actual, 'Function did not return expected output.'); | ||
}); | ||
|
||
it('should support --named-exports', () => { | ||
const actual = runCLI('indexr', '.', '--named-exports'); | ||
const expected = { | ||
inputFolder: '.', | ||
options: { | ||
namedExports: true, | ||
}, | ||
}; | ||
assert.deepEqual(expected, actual, 'Function did not return expected output.'); | ||
}); | ||
|
||
it('should support --modules', () => { | ||
const actual = runCLI('indexr', '.', '--modules', '**/fooo/'); | ||
const expected = { | ||
inputFolder: '.', | ||
options: { | ||
modules: ['**/fooo/'], | ||
}, | ||
}; | ||
assert.deepEqual(expected, actual, 'Function did not return expected output.'); | ||
}); | ||
|
||
it('should support --modules-ignore', () => { | ||
const actual = runCLI('indexr', '.', '--modules-ignore', '**/fooo/'); | ||
const expected = { | ||
inputFolder: '.', | ||
options: { | ||
modulesIgnore: ['**/fooo/'], | ||
}, | ||
}; | ||
assert.deepEqual(expected, actual, 'Function did not return expected output.'); | ||
}); | ||
|
||
it('should support --submodules', () => { | ||
const actual = runCLI('indexr', '.', '--submodules', '**/fooo/'); | ||
const expected = { | ||
inputFolder: '.', | ||
options: { | ||
submodules: ['**/fooo/'], | ||
}, | ||
}; | ||
assert.deepEqual(expected, actual, 'Function did not return expected output.'); | ||
}); | ||
|
||
it('should support --submodules-ignore', () => { | ||
const actual = runCLI('indexr', '.', '--submodules-ignore', '**/fooo/'); | ||
const expected = { | ||
inputFolder: '.', | ||
options: { | ||
submodulesIgnore: ['**/fooo/'], | ||
}, | ||
}; | ||
assert.deepEqual(expected, actual, 'Function did not return expected output.'); | ||
}); | ||
|
||
it('should support --watch', () => { | ||
const actual = runCLI('indexr', '.', '--watch', '**/fooo/'); | ||
const expected = { | ||
inputFolder: '.', | ||
options: { | ||
watch: '**/fooo/', | ||
}, | ||
}; | ||
assert.deepEqual(expected, actual, 'Function did not return expected output.'); | ||
}); | ||
|
||
it('should return correct --exts', () => { | ||
const actual = runCLI('indexr', '.', '--ext', 'js', '--ext', 'jsx'); | ||
const expected = { | ||
inputFolder: '.', | ||
options: { | ||
exts: ['js', 'jsx'], | ||
}, | ||
}; | ||
assert.deepEqual(expected, actual); | ||
}); | ||
}; |
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,33 @@ | ||
import extendedHelp from '../../lib/modules/cli/extendedHelp'; | ||
import { assert } from 'chai'; | ||
import sinon from 'sinon'; | ||
|
||
export default () => { | ||
it('extendHelp', () => { | ||
const flags = '-f, --some-flag'; | ||
const description = 'Some flag'; | ||
const long = 'Some long'; | ||
const coercion = undefined; | ||
const defaults = undefined; | ||
const allmessages = []; | ||
|
||
sinon.stub(console, 'log', (msg) => allmessages.push(msg)); | ||
|
||
// const option = sinon.spy(); | ||
const option = () => {}; | ||
const on = (tag, func) => func(); | ||
|
||
extendedHelp({ option, on }, [{ | ||
flags, | ||
description, | ||
coercion, | ||
defaults, | ||
long, | ||
}]); | ||
console.log.restore(); | ||
assert.deepEqual( | ||
allmessages, | ||
['\n Some flag\n ----------\n -f, --some-flag\n\n Some long\n\n'] | ||
); | ||
}); | ||
}; |
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,14 @@ | ||
import { assert } from 'chai'; | ||
import getFileList from '../../lib/utils/getFileList'; | ||
export default () => { | ||
it('should blow up if it is given a non string path', (endTest) => { | ||
getFileList(/1234/, ['one']) | ||
.then(() => { | ||
endTest('No error was thrown but it should have.'); | ||
}) | ||
.catch((e) => { | ||
assert(e); | ||
endTest(); | ||
}); | ||
}); | ||
}; |
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,44 @@ | ||
import handleDeprecation from '../../lib/modules/args/handleDeprecation'; | ||
import { assert } from 'chai'; | ||
import sinon from 'sinon'; | ||
|
||
export default () => { | ||
const deprecated = { | ||
include: { | ||
sub: 'submodules', | ||
message: 'This is a message', | ||
}, | ||
}; | ||
|
||
const warnFunc = sinon.spy(); | ||
|
||
it('should handle a deprecated object', () => { | ||
const actual = handleDeprecation(deprecated, { | ||
include: 'foo', | ||
warnFunc, | ||
}); | ||
|
||
const expected = { | ||
submodules: 'foo', | ||
}; | ||
|
||
assert(warnFunc.called); | ||
assert.deepEqual(actual, expected, 'handleDeprecation'); | ||
}); | ||
|
||
it('should not allow a deprecated prop through but instead copy its value to the new prop', () => { | ||
const actual = handleDeprecation(deprecated, { | ||
include: 'foo', | ||
other: 'prop', | ||
submodules: 'bar', | ||
warnFunc, | ||
}); | ||
|
||
const expected = { | ||
other: 'prop', | ||
submodules: 'foo', | ||
}; | ||
assert(warnFunc.called); | ||
assert.deepEqual(actual, expected, 'handleDeprecation'); | ||
}); | ||
}; |
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,21 @@ | ||
import indexr from '../../lib'; | ||
import { fileExists, paths } from '../lib/utils'; | ||
import path from 'path'; | ||
import { assert } from 'chai'; | ||
const { | ||
inputFolder, | ||
} = paths; | ||
|
||
export default () => { | ||
it('should ignore node_modules', (endTest) => { | ||
indexr(inputFolder) | ||
.then(() => { | ||
const actual = fileExists(path.resolve(inputFolder, 'module-3/node_modules/modules/index.r.js')); | ||
const expected = false; | ||
assert.equal(expected, actual); | ||
endTest(); | ||
}) | ||
.catch(endTest); | ||
|
||
}); | ||
}; |
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,14 @@ | ||
import { assert } from 'chai'; | ||
import { resetLog, setLogLevel, logHistory, info } from '../../lib/utils/logger'; | ||
|
||
export default () => { | ||
it('should actually log stuff and print to console', () => { | ||
resetLog(); | ||
setLogLevel('none'); | ||
info('foo'); | ||
const actual = logHistory('info')[0]; | ||
const expected = { level: 'info', message: 'indexr >> foo' }; | ||
assert.deepEqual(expected, actual); | ||
setLogLevel('none'); | ||
}); | ||
}; |
Oops, something went wrong.