You've already forked FullScreenPokemon
mirror of
https://github.com/FullScreenShenanigans/FullScreenPokemon.git
synced 2026-04-28 12:58:40 -07:00
0b6d495899
* Bumped gulp-shenanigans to 0.5.16 Added a "Usage" section in the readme. * Started gulp-shenanigans 0.5.20 update * Continued through part of Cutscenes.ts * Finished the rest of Cutscenes * Finished rest of compiler errors Now to fix test failures... later! * Added dependencies code for index.html * Added a couple of missing dependencies to index * Fixed some this scoping issues with Things Now that they don't receive .EightBitter or .GameStarter, triggered member functions of Things must correctly manage context. * Clarified instantiation in docs * Bumped dependencies in json files
125 lines
3.1 KiB
TypeScript
125 lines
3.1 KiB
TypeScript
/* This file was auto-generated by gulp-shenanigans */
|
|
/// <reference path="../../node_modules/@types/chai/index.d.ts" />
|
|
/// <reference path="../../node_modules/@types/mocha/index.d.ts" />
|
|
|
|
/**
|
|
* Grouping of mocha describe() tests.
|
|
*/
|
|
interface ITestHierarchy {
|
|
/**
|
|
* Hierarchical children within this describe() group.
|
|
*/
|
|
children: {
|
|
[i: string]: ITestHierarchy;
|
|
};
|
|
|
|
/**
|
|
* Tests run in this describe().
|
|
*/
|
|
tests: {
|
|
[i: string]: (done: Function) => void;
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Combines mocha tests into their describe() groups.
|
|
*/
|
|
export class MochaLoader {
|
|
/**
|
|
* The underlying mocha instance.
|
|
*/
|
|
private mocha: Mocha;
|
|
|
|
/**
|
|
* Root grouping of test hierarchies.
|
|
*/
|
|
private testHierarchy: ITestHierarchy = {
|
|
children: {},
|
|
tests: {}
|
|
};
|
|
|
|
/**
|
|
* Mocha describe() path for the next test to be added.
|
|
*/
|
|
private currentTestPath: string[];
|
|
|
|
/**
|
|
* Initializes a new instance of the MochaLoader class.
|
|
*
|
|
* @param mocha The underlying mocha instance.
|
|
*/
|
|
public constructor(mocha: Mocha) {
|
|
this.mocha = mocha;
|
|
this.mocha.setup("bdd");
|
|
}
|
|
|
|
/**
|
|
* Sets the current test path.
|
|
*
|
|
* @param rawPath A new current test path.
|
|
*/
|
|
public setTestPath(rawPath: string): void {
|
|
this.currentTestPath = rawPath.split("/");
|
|
}
|
|
|
|
/**
|
|
* Adds a new test under the current test path.
|
|
*
|
|
* @param testName The name of the test.
|
|
* @param test A new test.
|
|
*/
|
|
public it(testName: string, test: (done: Function) => void): void {
|
|
if (!this.currentTestPath) {
|
|
throw new Error(`No test path defined before adding test '${testName}'.`);
|
|
}
|
|
|
|
let testHierarchy: ITestHierarchy = this.testHierarchy;
|
|
|
|
for (const part of this.currentTestPath) {
|
|
if (!testHierarchy.children[part]) {
|
|
testHierarchy = testHierarchy.children[part] = {
|
|
children: {},
|
|
tests: {}
|
|
};
|
|
} else {
|
|
testHierarchy = testHierarchy.children[part];
|
|
}
|
|
}
|
|
|
|
testHierarchy.tests[testName] = test;
|
|
}
|
|
|
|
/**
|
|
* Finalizes the tests' describe() hierarchy.
|
|
*/
|
|
public describeTests(): void {
|
|
this.describeTestHierarchy(this.testHierarchy);
|
|
}
|
|
|
|
/**
|
|
* Runs tests using mocha.
|
|
*/
|
|
public run(): void {
|
|
this.mocha.run();
|
|
}
|
|
|
|
/**
|
|
* Recursively describes a test hierarchy and its children hierarchies.
|
|
*
|
|
* @param testHierarchy A test hierarchy to describe.
|
|
*/
|
|
private describeTestHierarchy(testHierarchy: ITestHierarchy): void {
|
|
for (const testName in testHierarchy.tests) {
|
|
if (testName in testHierarchy.tests) {
|
|
it(testName, testHierarchy.tests[testName]);
|
|
}
|
|
}
|
|
|
|
for (const childName in testHierarchy.children) {
|
|
if (childName in testHierarchy.children) {
|
|
describe(childName, (): void => this.describeTestHierarchy(testHierarchy.children[childName]));
|
|
}
|
|
}
|
|
}
|
|
}
|