Skip to content

Commit 3115408

Browse files
authored
fmt
1 parent 6d85466 commit 3115408

File tree

1 file changed

+73
-62
lines changed

1 file changed

+73
-62
lines changed

src/test_case.ts

+73-62
Original file line numberDiff line numberDiff line change
@@ -38,71 +38,82 @@ export class TestCase {
3838
let executedAfterAllCaseHook = false;
3939

4040
// Run cases
41-
this.plan!.suites[suiteName].cases!.forEach(async (c: ITestCase, caseIndex) => {
42-
// Run the case - required to run like this because the
43-
// hooks need to be ran inside the Deno.test call. Deno.test seems to queue
44-
// the tests, meaning all hooks are ran, and **then** the tests are ran
45-
const hookAttachedTestFn = async () => {
46-
if (this.plan.before_all_suite_hook && !executedBeforeAllSuiteHook) {
47-
await this.plan.before_all_suite_hook();
48-
executedBeforeAllSuiteHook = true;
49-
}
50-
if (
51-
this.plan.before_each_suite_hook && !executedBeforeEachSuiteHook
52-
) {
53-
await this.plan.before_each_suite_hook();
54-
executedBeforeEachSuiteHook = true;
55-
}
56-
if (
57-
this.plan.suites[suiteName].before_all_case_hook &&
58-
!executedBeforeAllCaseHook
59-
) {
60-
await this.plan.suites[suiteName].before_all_case_hook!();
61-
executedBeforeAllCaseHook = true;
62-
}
63-
if (this.plan.suites[suiteName].before_each_case_hook) {
64-
await this.plan.suites[suiteName].before_each_case_hook!();
65-
}
41+
this.plan!.suites[suiteName].cases!.forEach(
42+
async (c: ITestCase, caseIndex) => {
43+
// Run the case - required to run like this because the
44+
// hooks need to be ran inside the Deno.test call. Deno.test seems to queue
45+
// the tests, meaning all hooks are ran, and **then** the tests are ran
46+
const hookAttachedTestFn = async () => {
47+
if (
48+
this.plan.before_all_suite_hook && !executedBeforeAllSuiteHook
49+
) {
50+
await this.plan.before_all_suite_hook();
51+
executedBeforeAllSuiteHook = true;
52+
}
53+
if (
54+
this.plan.before_each_suite_hook && !executedBeforeEachSuiteHook
55+
) {
56+
await this.plan.before_each_suite_hook();
57+
executedBeforeEachSuiteHook = true;
58+
}
59+
if (
60+
this.plan.suites[suiteName].before_all_case_hook &&
61+
!executedBeforeAllCaseHook
62+
) {
63+
await this.plan.suites[suiteName].before_all_case_hook!();
64+
executedBeforeAllCaseHook = true;
65+
}
66+
if (this.plan.suites[suiteName].before_each_case_hook) {
67+
await this.plan.suites[suiteName].before_each_case_hook!();
68+
}
6669

67-
await c.testFn();
70+
await c.testFn();
6871

69-
if (this.plan.suites[suiteName].after_each_case_hook) {
70-
await this.plan.suites[suiteName].after_each_case_hook!();
71-
}
72-
const isLastCase = (this.plan!.suites[suiteName].cases!.length - 1) == caseIndex;
73-
if (
74-
this.plan.suites[suiteName].after_all_case_hook &&
75-
!executedAfterAllCaseHook && isLastCase
76-
) {
77-
await this.plan.suites[suiteName].after_all_case_hook!();
78-
executedAfterAllCaseHook = true;
79-
}
80-
if (this.plan.after_each_suite_hook && !executedAfterEachSuiteHook) {
81-
await this.plan.after_each_suite_hook();
82-
executedAfterEachSuiteHook = true;
83-
}
84-
const isLastSuite = (Object.keys(this.plan!.suites).length - 1) == suiteIndex;
85-
if (this.plan.after_all_suite_hook && !executedAfterAllSuiteHook && isLastSuite) {
86-
await this.plan.after_all_suite_hook();
87-
executedAfterAllSuiteHook = true;
72+
if (this.plan.suites[suiteName].after_each_case_hook) {
73+
await this.plan.suites[suiteName].after_each_case_hook!();
74+
}
75+
const isLastCase =
76+
(this.plan!.suites[suiteName].cases!.length - 1) == caseIndex;
77+
if (
78+
this.plan.suites[suiteName].after_all_case_hook &&
79+
!executedAfterAllCaseHook && isLastCase
80+
) {
81+
await this.plan.suites[suiteName].after_all_case_hook!();
82+
executedAfterAllCaseHook = true;
83+
}
84+
if (
85+
this.plan.after_each_suite_hook && !executedAfterEachSuiteHook
86+
) {
87+
await this.plan.after_each_suite_hook();
88+
executedAfterEachSuiteHook = true;
89+
}
90+
const isLastSuite =
91+
(Object.keys(this.plan!.suites).length - 1) == suiteIndex;
92+
if (
93+
this.plan.after_all_suite_hook && !executedAfterAllSuiteHook &&
94+
isLastSuite
95+
) {
96+
await this.plan.after_all_suite_hook();
97+
executedAfterAllSuiteHook = true;
98+
}
99+
};
100+
// (ebebbington) To stop the output of test running being horrible
101+
// in the CI, we will only display the new name which should be
102+
// "plan | suite " case", as opposed to the "super saiyan"
103+
// version. This name is generated differently inside `formatTestCaseName`
104+
// based on if the tests are being ran inside a CI job
105+
if (Deno.env.get("CI") === "true") {
106+
await Deno.test(c.new_name, async () => {
107+
await hookAttachedTestFn();
108+
});
109+
} else {
110+
await Deno.test(c.name, async () => {
111+
Deno.stdout.writeSync(encoder.encode(c.new_name));
112+
await hookAttachedTestFn();
113+
});
88114
}
89-
};
90-
// (ebebbington) To stop the output of test running being horrible
91-
// in the CI, we will only display the new name which should be
92-
// "plan | suite " case", as opposed to the "super saiyan"
93-
// version. This name is generated differently inside `formatTestCaseName`
94-
// based on if the tests are being ran inside a CI job
95-
if (Deno.env.get("CI") === "true") {
96-
await Deno.test(c.new_name, async () => {
97-
await hookAttachedTestFn();
98-
});
99-
} else {
100-
await Deno.test(c.name, async () => {
101-
Deno.stdout.writeSync(encoder.encode(c.new_name));
102-
await hookAttachedTestFn();
103-
});
104-
}
105-
});
115+
},
116+
);
106117
});
107118
}
108119
}

0 commit comments

Comments
 (0)