mirror of
https://github.com/google/blockly.git
synced 2026-01-12 11:27:14 +01:00
* Revert "fix: lint" This reverts commit050956d105. * Revert "fix: run mocha as a module" This reverts commit4dac25ae99. * Revert "move to modules, but break mocha" This reverts commit220d7bbd1d.
113 lines
2.9 KiB
JavaScript
113 lines
2.9 KiB
JavaScript
/**
|
|
* @license
|
|
* Copyright 2020 Google LLC
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
goog.module('Blockly.test.helpers.common');
|
|
|
|
/**
|
|
* Test case configuration.
|
|
* @record
|
|
*/
|
|
class TestCase {
|
|
/**
|
|
* Class for a test case configuration.
|
|
*/
|
|
constructor() {
|
|
/**
|
|
* @type {string} The title for the test case.
|
|
*/
|
|
this.title;
|
|
/**
|
|
* @type {boolean|undefined} Whether this test case should be skipped.
|
|
* Used to skip buggy test case and should have an associated bug.
|
|
*/
|
|
this.skip;
|
|
/**
|
|
* @type {boolean|undefined} Whether this test case should be called as
|
|
* only. Used for debugging.
|
|
*/
|
|
this.only;
|
|
}
|
|
}
|
|
exports.TestCase = TestCase;
|
|
|
|
/**
|
|
* Test suite configuration.
|
|
* @record
|
|
* @template {TestCase} T
|
|
* @template {TestSuite} U
|
|
*/
|
|
class TestSuite {
|
|
/**
|
|
* Class for a test suite configuration.
|
|
*/
|
|
constructor() {
|
|
/**
|
|
* @type {string} The title for the test case.
|
|
*/
|
|
this.title;
|
|
/**
|
|
* @type {?Array<T>} The associated test cases.
|
|
*/
|
|
this.testCases;
|
|
/**
|
|
* @type {?Array<U>} List of nested inner test suites.
|
|
*/
|
|
this.testSuites;
|
|
/**
|
|
* @type {boolean|undefined} Whether this test suite should be skipped.
|
|
* Used to skip buggy test case and should have an associated bug.
|
|
*/
|
|
this.skip;
|
|
/**
|
|
* @type {boolean|undefined} Whether this test suite should be called as
|
|
* only. Used for debugging.
|
|
*/
|
|
this.only;
|
|
}
|
|
}
|
|
exports.TestSuite = TestSuite;
|
|
|
|
/**
|
|
* Runs provided test cases.
|
|
* @template {TestCase} T
|
|
* @param {!Array<T>} testCases The test cases to run.
|
|
* @param {function(T):Function} createTestCallback Creates test
|
|
* callback using given test case.
|
|
*/
|
|
function runTestCases(testCases, createTestCallback) {
|
|
testCases.forEach((testCase) => {
|
|
let testCall = (testCase.skip ? test.skip : test);
|
|
testCall = (testCase.only ? test.only : testCall);
|
|
testCall(testCase.title, createTestCallback(testCase));
|
|
});
|
|
}
|
|
exports.runTestCases = runTestCases;
|
|
|
|
/**
|
|
* Runs provided test suite.
|
|
* @template {TestCase} T
|
|
* @template {TestSuite<T, U>} U
|
|
* @param {Array<!U>} testSuites The test suites to run.
|
|
* @param {function(!U):(function(T):!Function)
|
|
* } createTestCaseCallback Creates test case callback using given test
|
|
* suite.
|
|
*/
|
|
function runTestSuites(testSuites, createTestCaseCallback) {
|
|
testSuites.forEach((testSuite) => {
|
|
let suiteCall = (testSuite.skip ? suite.skip : suite);
|
|
suiteCall = (testSuite.only ? suite.only : suiteCall);
|
|
suiteCall(testSuite.title, function() {
|
|
if (testSuite.testSuites && testSuite.testSuites.length) {
|
|
runTestSuites(testSuite.testSuites, createTestCaseCallback);
|
|
}
|
|
if (testSuite.testCases && testSuite.testCases.length) {
|
|
runTestCases(testSuite.testCases, createTestCaseCallback(testSuite));
|
|
}
|
|
});
|
|
});
|
|
}
|
|
exports.runTestSuites = runTestSuites;
|