hyperflow
Version:
A javascript state flow and mutation management toolkit & library for developing universal app.
83 lines (72 loc) • 2.7 kB
JavaScript
/**
* Copyright 2015-present Tuan Le.
*
* Licensed under the MIT License.
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://opensource.org/licenses/mit-license.html
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*------------------------------------------------------------------------
*
* @module TapeTestRunnerComposite
* @description - A tape test runner composite.
*
* @author Tuan Le (tuan.t.lei@gmail.com)
*
* @flow
*/
; // eslint-disable-line
import CommonElement from '../../core/elements/common-element';
import CompositeElement from '../../core/elements/composite-element';
/* factory Ids */
import { FIXTURE_FACTORY_CODE } from '../factory-code';
const Hf = CommonElement();
export default CompositeElement({
template: {
/**
* @description - Initialized and check that factory is valid for this composite.
*
* @method $initTapeTestRunnerComposite
* @return void
*/
$initTapeTestRunnerComposite () {
const fixture = this;
if (Hf.DEVELOPMENT) {
if (!Hf.isSchema({
fId: `string`,
getTestRunner: `function`
}).of(fixture) || fixture.fId.substr(0, FIXTURE_FACTORY_CODE.length) !== FIXTURE_FACTORY_CODE) {
Hf.log(`error`, `TapeTestRunnerComposite.$init - Fixture is invalid. Cannot apply composite.`);
}
}
},
/**
* @description - Perform unit testing...
*
* @method test
* @param {function} tester
* @param {string} description
* @return void
*/
test (tester, description = ``) {
const fixture = this;
description = Hf.isString(description) ? description : ``;
const tapeTestRunner = fixture.getTestRunner();
if (Hf.DEVELOPMENT) {
if (!Hf.isFunction(tester)) {
Hf.log(`error`, `TapeTestRunnerComposite.test - Input test function is invalid.`);
} else if (!Hf.isFunction(tapeTestRunner)) {
Hf.log(`error`, `TapeTestRunnerComposite.test - Fixture tape test runner function is invalid.`);
}
}
tapeTestRunner(description, tester);
}
}
});