-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract library to deal with mocha function names
- Loading branch information
Showing
4 changed files
with
340 additions
and
11 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
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,77 @@ | ||
'use strict'; | ||
|
||
const chain = require('ramda/src/chain'); | ||
|
||
const suiteNames = [ | ||
'describe', | ||
'context', | ||
'suite' | ||
]; | ||
|
||
const suiteModifiers = { | ||
skip: [ | ||
'describe.skip', | ||
'context.skip', | ||
'suite.skip', | ||
'xdescribe', | ||
'xcontext', | ||
'xsuite' | ||
], | ||
only: [ | ||
'describe.only', | ||
'context.only', | ||
'suite.only' | ||
] | ||
}; | ||
|
||
const testCaseNames = [ | ||
'it', | ||
'test', | ||
'specify' | ||
]; | ||
|
||
const testCaseModifiers = { | ||
skip: [ | ||
'it.skip', | ||
'test.skip', | ||
'specify.skip', | ||
'xit', | ||
'xspecify' | ||
], | ||
only: [ | ||
'it.only', | ||
'test.only', | ||
'specify.only' | ||
] | ||
}; | ||
|
||
function getTestCaseNames(options = {}) { | ||
const { modifiers = [], baseNames = true } = options; | ||
const names = baseNames ? testCaseNames : []; | ||
|
||
return names.concat(chain((modifierName) => { | ||
if (testCaseModifiers[modifierName]) { | ||
return testCaseModifiers[modifierName]; | ||
} | ||
|
||
return []; | ||
}, modifiers)); | ||
} | ||
|
||
function getSuiteNames(options = {}) { | ||
const { modifiers = [], baseNames = true, additionalSuiteNames = [] } = options; | ||
const names = baseNames ? suiteNames.concat(additionalSuiteNames) : []; | ||
|
||
return names.concat(chain((modifierName) => { | ||
if (suiteModifiers[modifierName]) { | ||
return suiteModifiers[modifierName]; | ||
} | ||
|
||
return []; | ||
}, modifiers)); | ||
} | ||
|
||
module.exports = { | ||
getTestCaseNames, | ||
getSuiteNames | ||
}; |
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,257 @@ | ||
'use strict'; | ||
|
||
const { expect } = require('chai'); | ||
const { getTestCaseNames, getSuiteNames } = require('../../lib/util/names'); | ||
|
||
describe('mocha names', () => { | ||
describe('test case names', () => { | ||
it('returns the list of basic test case names when no options are provided', () => { | ||
const testCaseNames = getTestCaseNames(); | ||
|
||
expect(testCaseNames).to.deep.equal([ | ||
'it', | ||
'test', | ||
'specify' | ||
]); | ||
}); | ||
|
||
it('returns an empty list when no modifiers and no base names are wanted', () => { | ||
const testCaseNames = getTestCaseNames({ baseNames: false }); | ||
|
||
expect(testCaseNames).to.deep.equal([]); | ||
}); | ||
|
||
it('always returns a new array', () => { | ||
const testCaseNames1 = getTestCaseNames({ baseNames: false }); | ||
const testCaseNames2 = getTestCaseNames({ baseNames: false }); | ||
|
||
expect(testCaseNames1).to.deep.equal(testCaseNames2); | ||
expect(testCaseNames1).to.not.equal(testCaseNames2); | ||
}); | ||
|
||
it('ignores invalid modifiers', () => { | ||
const testCaseNames = getTestCaseNames({ modifiers: [ 'foo' ], baseNames: false }); | ||
|
||
expect(testCaseNames).to.deep.equal([]); | ||
}); | ||
|
||
it('returns the list of test case names with and without "skip" modifiers applied', () => { | ||
const testCaseNames = getTestCaseNames({ modifiers: [ 'skip' ] }); | ||
|
||
expect(testCaseNames).to.deep.equal([ | ||
'it', | ||
'test', | ||
'specify', | ||
'it.skip', | ||
'test.skip', | ||
'specify.skip', | ||
'xit', | ||
'xspecify' | ||
]); | ||
}); | ||
|
||
it('returns the list of test case names only with "skip" modifiers applied', () => { | ||
const testCaseNames = getTestCaseNames({ modifiers: [ 'skip' ], baseNames: false }); | ||
|
||
expect(testCaseNames).to.deep.equal([ | ||
'it.skip', | ||
'test.skip', | ||
'specify.skip', | ||
'xit', | ||
'xspecify' | ||
]); | ||
}); | ||
|
||
it('returns the list of test case names with and without "only" modifiers applied', () => { | ||
const testCaseNames = getTestCaseNames({ modifiers: [ 'only' ] }); | ||
|
||
expect(testCaseNames).to.deep.equal([ | ||
'it', | ||
'test', | ||
'specify', | ||
'it.only', | ||
'test.only', | ||
'specify.only' | ||
]); | ||
}); | ||
|
||
it('returns the list of test case names only with "only" modifiers applied', () => { | ||
const testCaseNames = getTestCaseNames({ modifiers: [ 'only' ], baseNames: false }); | ||
|
||
expect(testCaseNames).to.deep.equal([ | ||
'it.only', | ||
'test.only', | ||
'specify.only' | ||
]); | ||
}); | ||
|
||
it('returns the list of all test case names', () => { | ||
const testCaseNames = getTestCaseNames({ modifiers: [ 'skip', 'only' ] }); | ||
|
||
expect(testCaseNames).to.deep.equal([ | ||
'it', | ||
'test', | ||
'specify', | ||
'it.skip', | ||
'test.skip', | ||
'specify.skip', | ||
'xit', | ||
'xspecify', | ||
'it.only', | ||
'test.only', | ||
'specify.only' | ||
]); | ||
}); | ||
|
||
it('returns the list of test case names only with modifiers applied', () => { | ||
const testCaseNames = getTestCaseNames({ modifiers: [ 'skip', 'only' ], baseNames: false }); | ||
|
||
expect(testCaseNames).to.deep.equal([ | ||
'it.skip', | ||
'test.skip', | ||
'specify.skip', | ||
'xit', | ||
'xspecify', | ||
'it.only', | ||
'test.only', | ||
'specify.only' | ||
]); | ||
}); | ||
}); | ||
|
||
describe('suite names', () => { | ||
it('returns the list of basic suite names when no options are provided', () => { | ||
const suiteNames = getSuiteNames(); | ||
|
||
expect(suiteNames).to.deep.equal([ | ||
'describe', | ||
'context', | ||
'suite' | ||
]); | ||
}); | ||
|
||
it('returns an empty list when no modifiers and no base names are wanted', () => { | ||
const suiteNames = getSuiteNames({ baseNames: false }); | ||
|
||
expect(suiteNames).to.deep.equal([]); | ||
}); | ||
|
||
it('always returns a new array', () => { | ||
const suiteNames1 = getSuiteNames({ baseNames: false }); | ||
const suiteNames2 = getSuiteNames({ baseNames: false }); | ||
|
||
expect(suiteNames1).to.deep.equal(suiteNames2); | ||
expect(suiteNames1).to.not.equal(suiteNames2); | ||
}); | ||
|
||
it('ignores invalid modifiers', () => { | ||
const suiteNames = getSuiteNames({ modifiers: [ 'foo' ], baseNames: false }); | ||
|
||
expect(suiteNames).to.deep.equal([]); | ||
}); | ||
|
||
it('returns the list of suite names with and without "skip" modifiers applied', () => { | ||
const suiteNames = getSuiteNames({ modifiers: [ 'skip' ] }); | ||
|
||
expect(suiteNames).to.deep.equal([ | ||
'describe', | ||
'context', | ||
'suite', | ||
'describe.skip', | ||
'context.skip', | ||
'suite.skip', | ||
'xdescribe', | ||
'xcontext', | ||
'xsuite' | ||
]); | ||
}); | ||
|
||
it('returns the list of suite names only with "skip" modifiers applied', () => { | ||
const suiteNames = getSuiteNames({ modifiers: [ 'skip' ], baseNames: false }); | ||
|
||
expect(suiteNames).to.deep.equal([ | ||
'describe.skip', | ||
'context.skip', | ||
'suite.skip', | ||
'xdescribe', | ||
'xcontext', | ||
'xsuite' | ||
]); | ||
}); | ||
|
||
it('returns the list of suite names with and without "only" modifiers applied', () => { | ||
const suiteNames = getSuiteNames({ modifiers: [ 'only' ] }); | ||
|
||
expect(suiteNames).to.deep.equal([ | ||
'describe', | ||
'context', | ||
'suite', | ||
'describe.only', | ||
'context.only', | ||
'suite.only' | ||
]); | ||
}); | ||
|
||
it('returns the list of suite names only with "only" modifiers applied', () => { | ||
const suiteNames = getSuiteNames({ modifiers: [ 'only' ], baseNames: false }); | ||
|
||
expect(suiteNames).to.deep.equal([ | ||
'describe.only', | ||
'context.only', | ||
'suite.only' | ||
]); | ||
}); | ||
|
||
it('returns the list of all suite names', () => { | ||
const suiteNames = getSuiteNames({ modifiers: [ 'skip', 'only' ] }); | ||
|
||
expect(suiteNames).to.deep.equal([ | ||
'describe', | ||
'context', | ||
'suite', | ||
'describe.skip', | ||
'context.skip', | ||
'suite.skip', | ||
'xdescribe', | ||
'xcontext', | ||
'xsuite', | ||
'describe.only', | ||
'context.only', | ||
'suite.only' | ||
]); | ||
}); | ||
|
||
it('returns the list of suite names names only with modifiers applied', () => { | ||
const suiteNames = getSuiteNames({ modifiers: [ 'skip', 'only' ], baseNames: false }); | ||
|
||
expect(suiteNames).to.deep.equal([ | ||
'describe.skip', | ||
'context.skip', | ||
'suite.skip', | ||
'xdescribe', | ||
'xcontext', | ||
'xsuite', | ||
'describe.only', | ||
'context.only', | ||
'suite.only' | ||
]); | ||
}); | ||
|
||
it('returns the additional suite names', () => { | ||
const suiteNames = getSuiteNames({ additionalSuiteNames: [ 'myCustomDescribe' ] }); | ||
|
||
expect(suiteNames).to.deep.equal([ | ||
'describe', | ||
'context', | ||
'suite', | ||
'myCustomDescribe' | ||
]); | ||
}); | ||
|
||
it('doesn’t return the additional suite names when base names shouldn’t be included', () => { | ||
const suiteNames = getSuiteNames({ additionalSuiteNames: [ 'myCustomDescribe' ], baseNames: false }); | ||
|
||
expect(suiteNames).to.deep.equal([]); | ||
}); | ||
}); | ||
}); |