From e4b8201acb9c8dbb58b3edd29d266d7056758d9c Mon Sep 17 00:00:00 2001 From: Edward Bebbington Date: Thu, 24 Sep 2020 00:26:36 +0100 Subject: [PATCH] issue-#5-only add skip support --- mod.ts | 75 +++++++++++++++++++++++++++++++---------------- src/interfaces.ts | 3 ++ src/test_case.ts | 6 ++-- 3 files changed, 57 insertions(+), 27 deletions(-) diff --git a/mod.ts b/mod.ts index a26a758d..ec2116f2 100644 --- a/mod.ts +++ b/mod.ts @@ -76,7 +76,7 @@ export class RhumRunner { protected test_suite_in_progress = ""; - protected plan: ITestPlan = { suites: {}, only: false }; + protected plan: ITestPlan = { suites: {}, only: false, skip: false }; // FILE MARKER - METHODS - CONSTRUCTOR /////////////////////////////////////// @@ -238,11 +238,12 @@ export class RhumRunner { name, new_name: this.formatTestCaseName(name), testFn: cb, - only: true + only: true, + skip: false }); } else if (this.passed_in_test_plan) { // is a test suite being skipped, so do the same thing we could do in `testSuite` this.passed_in_test_suite = name; - this.plan.suites![name] = {cases: [], only: true}; + this.plan.suites![name] = {cases: [], only: true, skip: false}; cb(); this.passed_in_test_suite = "" // At the end of the suite, remove the name ready for a new suite. The reason for this is mainly when using `only`, so say when a 2nd suite uses `only`, it can flow through the logic properly } @@ -269,9 +270,20 @@ export class RhumRunner { * }); */ public skip(name: string, cb: () => void): void { - // TODO(ebebbington|crookse) Maybe we could still call run, but pass in { - // ignore: true } which the Deno.Test will use? just so it displays ignored - // in the console + if (this.passed_in_test_plan && this.passed_in_test_suite) { // is a test case being skipped, so do the same thing we would do in `testCase` + this.plan.suites[this.passed_in_test_suite].cases!.push({ + name, + new_name: this.formatTestCaseName(name), + testFn: cb, + only: false, + skip: true + }); + } else if (this.passed_in_test_plan) { // is a test suite being skipped, so do the same thing we could do in `testSuite` + this.passed_in_test_suite = name; + this.plan.suites![name] = {cases: [], only: false, skip: true}; + cb(); + this.passed_in_test_suite = "" // At the end of the suite, remove the name ready for a new suite. The reason for this is mainly when using `only`, so say when a 2nd suite uses `only`, it can flow through the logic properly + } } /** @@ -357,7 +369,8 @@ export class RhumRunner { name, new_name: this.formatTestCaseName(name), testFn, - only: false + only: false, + skip: false }); } @@ -398,7 +411,7 @@ export class RhumRunner { */ public testSuite(name: string, testCases: () => void): void { this.passed_in_test_suite = name; - this.plan.suites![name] = { cases: [], only: false }; + this.plan.suites![name] = { cases: [], only: false, skip: false }; testCases(); this.passed_in_test_suite = "" // At the end of the suite, remove the name ready for a new suite. The reason for this is mainly when using `only`, so say when a 2nd suite uses `only`, it can flow through the logic properly } @@ -457,27 +470,39 @@ export class RhumRunner { * Returns the new test name for outputting purposes. */ protected formatTestCaseName(name: string): string { + return `${this.passed_in_test_plan}` + "\n" + + ` ${this.passed_in_test_suite}` + "\n" + // spaces are to keep it directly below plan name plus indentation + ` ${name}`; // spaces are to keep it directly below plan name plus indentation + + // + // Description of below code + // + // Another way to display the output. It displays just how + // it usually would, but wee include Deno's `test ` text, but + // separate into it's own column to be 'out of the way'. This method + // would be desirable if Deno removed the "test " part + // First test case for a new plan and suite - if (this.test_plan_in_progress != this.passed_in_test_plan) { - this.test_plan_in_progress = this.passed_in_test_plan; - this.test_suite_in_progress = this.passed_in_test_suite; - const newName = `| ${this.passed_in_test_plan}` + - `\n | ${this.passed_in_test_suite}` + - `\n | ${name}`; - return newName; - } + // if (this.test_plan_in_progress != this.passed_in_test_plan) { + // this.test_plan_in_progress = this.passed_in_test_plan; + // this.test_suite_in_progress = this.passed_in_test_suite; + // const newName = `| ${this.passed_in_test_plan}` + + // `\n | ${this.passed_in_test_suite}` + + // `\n | ${name}`; + // return newName; + // } // Case for existing plan but new suite - if (this.test_suite_in_progress != this.passed_in_test_suite) { - this.test_suite_in_progress = this.passed_in_test_suite; - const newName = `| ${this.passed_in_test_suite}` + - `\n | ${name}`; - return newName; - } + // if (this.test_suite_in_progress != this.passed_in_test_suite) { + // this.test_suite_in_progress = this.passed_in_test_suite; + // const newName = `| ${this.passed_in_test_suite}` + + // `\n | ${name}`; + // return newName; + // } // Case for existing plan and suite - const newName = `| ${name}`; - return newName; + // const newName = `| ${name}`; + // return newName; } /** @@ -489,7 +514,7 @@ export class RhumRunner { this.passed_in_test_plan = ""; this.test_plan_in_progress = ""; this.test_suite_in_progress = ""; - this.plan = { suites: {}, only: false }; + this.plan = { suites: {}, only: false, skip: false}; } } diff --git a/src/interfaces.ts b/src/interfaces.ts index 4690e47b..f283fecd 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -73,6 +73,7 @@ export interface ITestPlan { [key: string]: ITestSuite; // "key" is the suite name }; only: boolean; + skip: boolean; after_all_suite_hook?: () => void; after_each_suite_hook?: () => void; before_all_suite_hook?: () => void; @@ -98,6 +99,7 @@ export interface ITestPlan { export interface ITestSuite { cases?: ITestCase[]; only: boolean; + skip: boolean; after_all_case_hook?: () => void; after_each_case_hook?: () => void; before_all_case_hook?: () => void; @@ -120,6 +122,7 @@ export interface ITestSuite { */ export interface ITestCase { only: boolean; + skip: boolean; name: string; new_name: string; testFn: () => void; diff --git a/src/test_case.ts b/src/test_case.ts index febcff33..dff9e1c3 100644 --- a/src/test_case.ts +++ b/src/test_case.ts @@ -84,10 +84,12 @@ export class TestCase { } const numberOfExtraSpaces = longestCaseNameLen - c.name.length; // for example, it would be 0 for when it's the test with the longest case name. It's just the character difference between the current case name and longest, telling us how many spaces to add - const isOnly = this.plan.only || this.plan.suites[suiteName].only || c.only + const only = this.plan.only || this.plan.suites[suiteName].only || c.only + const skip = this.plan.skip || this.plan.suites[suiteName].skip || c.skip + const ignore = skip === true || only === true await Deno.test({ name: c.new_name + " ".repeat(numberOfExtraSpaces), - ignore: isOnly === false, + ignore: ignore, async fn(): Promise { await hookAttachedTestFn(); }