-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
T/16938 Extract common PFW tests loop. #333
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* global createTestCase */ | ||
/* exported createTestSuite */ | ||
|
||
// Creates a test suite based on the options provided. The test suite then should be passed to `bender.test` to run tests. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not standard JSDoc comments, similar to our existing tests? Comments from tests don't leak into documentation, so it's safe to use JSDoc in a normal way. |
||
// | ||
// @param {Object} options | ||
// @param {Array} options.browsers Array of browser names. | ||
// @param {Array} options.wordVersions Array of word version names. | ||
// @param {Object} options.tests Object containing tests to be generated. It contains key - value pairs, where key is name of the test file and value | ||
// is an array of wordVersions name for which tests should be generated or a boolean indicating: true - generate for all versions, false - for none. | ||
// @param {Object} [options.ticketTests] Object containing tests to be generated. It has same structure as `options.tests`. | ||
// @param {Array} [options.testData] Test data object (may contain e.g. information about ignored tests). All created tests will be added into testData object. | ||
// @param {Array} [options.customFilters] Array of custom filters (like [ pfwTools.filters.font ]) which will be used during assertions. | ||
// @param {Boolean} [options.compareRawData=false] If `true` test case will assert against raw paste's `data.dataValue` rather than | ||
// what will appear in the editor after all transformations and filtering. | ||
// @param {Boolean} [options.ignoreAll=false] Whenever to ignore all tests. | ||
// @returns {Object} Test data object which should be passed to `bender.test` function. | ||
function createTestSuite( options ) { | ||
|
||
var browsers = options.browsers || [], | ||
wordVersions = options.wordVersions || [], | ||
tests = options.tests || [], | ||
ticketTests = options.ticketTests || [], | ||
testData = options.testData || { _should: { ignore: {} } }, | ||
ignoreAll = options.ignoreAll === true, | ||
compareRawData = options.compareRawData === true, | ||
customFilters = options.customFilters ? options.customFilters : null; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMO it can be much simplified by using |
||
|
||
_prepareTests( testData, tests, browsers, wordVersions, compareRawData, customFilters, false, ignoreAll ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And if we're going with simplified handling of |
||
|
||
_prepareTests( testData, ticketTests, browsers, wordVersions, compareRawData, customFilters, true, ignoreAll ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I'm seeing correctly, the only place that uses the information if the tests are ticket ones or not is inside I'm not seeing any sense in a special treatment of |
||
|
||
return testData; | ||
} | ||
|
||
// Iterates over given tests, browsers and wordVersions creating tests based on all possible combinations. | ||
// | ||
// @private | ||
// @param {Object} testData | ||
// @param {Array} tests | ||
// @param {Array} browsers | ||
// @param {Array} wordVersions | ||
// @param {Boolean} compareRawData | ||
// @param {Array} customFilters | ||
// @param {Boolean} areTicketsTests Whenever tests should be generated using `tickets/` directory. | ||
// @param {Boolean} ignoreAll | ||
function _prepareTests( testData, tests, browsers, wordVersions, compareRawData, customFilters, areTicketsTests, ignoreAll ) { | ||
var testsKeys = CKEDITOR.tools.objectKeys( tests ), | ||
wordVersion, testKey, testName, i, k, j; | ||
|
||
if ( testsKeys.length ) { | ||
for ( i = 0; i < testsKeys.length; i++ ) { | ||
for ( k = 0; k < browsers.length; k++ ) { | ||
for ( j = 0; j < wordVersions.length; j++ ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't it be before |
||
|
||
wordVersion = wordVersions[ j ]; | ||
testKey = testsKeys[ i ]; | ||
|
||
if ( tests[ testKey ] === true || CKEDITOR.tools.indexOf( tests[ testKey ], wordVersion ) !== -1 ) { | ||
|
||
testName = [ 'test', testKey, wordVersion, browsers[ k ] ].join( ' ' ); | ||
|
||
if ( ignoreAll ) { | ||
testData._should.ignore[ testName ] = true; | ||
} | ||
|
||
testData[ testName ] = createTestCase( testKey, wordVersion, browsers[ k ], areTicketsTests, compareRawData, customFilters ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm a big fan of |
||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we're adding docs in other places, then we can also add missing docs for
createTestCase
as only one parameter is described.