-
Notifications
You must be signed in to change notification settings - Fork 781
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Core: Refactor internal core.js to declare QUnit as a single literal
- Loading branch information
Showing
5 changed files
with
62 additions
and
69 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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import config from './core/config.js'; | ||
import Promise from './promise.js'; | ||
|
||
export function createRegisterCallbackFunction (key) { | ||
// Initialize key collection of callback | ||
if (typeof config.callbacks[key] === 'undefined') { | ||
config.callbacks[key] = []; | ||
} | ||
|
||
return function registerCallback (callback) { | ||
if (typeof callback !== 'function') { | ||
throw new TypeError('Callback parameter must be a function'); | ||
} | ||
config.callbacks[key].push(callback); | ||
}; | ||
} | ||
|
||
export function runLoggingCallbacks (key, arg) { | ||
const callbacks = config.callbacks[key]; | ||
|
||
// Handling 'log' callbacks separately. Unlike the other callbacks, | ||
// the log callback is not controlled by the processing queue, | ||
// but rather used by asserts. Hence to promisfy the 'log' callback | ||
// would mean promisfying each step of a test | ||
if (key === 'log') { | ||
callbacks.map(callback => callback(arg)); | ||
return; | ||
} | ||
|
||
// ensure that each callback is executed serially | ||
let promiseChain = Promise.resolve(); | ||
callbacks.forEach(callback => { | ||
promiseChain = promiseChain.then(() => { | ||
return Promise.resolve(callback(arg)); | ||
}); | ||
}); | ||
return promiseChain; | ||
} |
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 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
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