Skip to content

Commit 205563c

Browse files
authored
Merge pull request #78 from stbestichhh/refactor
Patch 1.0.7
2 parents aed828b + 594a15c commit 205563c

File tree

7 files changed

+36
-20
lines changed

7 files changed

+36
-20
lines changed

SECURITY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
| Version | Supported |
66
|---------|--------------------|
7+
| 1.0.7 | :white_check_mark: |
78
| 1.0.6 | :white_check_mark: |
89
| 1.0.5 | :white_check_mark: |
910
| 1.0.4 | :x: |

bin/cli/cli.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const handleOptionsAndExecuteAction = async (options: StestOptions) => {
2020
program
2121
.name('stest')
2222
.description('Testing framework for TypeScript Node.js applications')
23-
.version('1.0.7.beta.1');
23+
.version('1.0.7');
2424

2525
program
2626
.option(

bin/errorInfo/error.info.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
export function findWhereErrorHasBeenThrown(e: Error, testClassName: string) {
1+
export function findWhereErrorHasBeenThrown(
2+
e: Error,
3+
testClassName: string,
4+
): string | undefined {
25
const stackLines = e.stack?.split('\n');
36
if (stackLines) {
47
const relevantLine = stackLines.find((line) =>

bin/logger/testRunner.logger.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ export class TestRunnerLogger extends LoggerService {
2121
if (e instanceof Error) {
2222
const testClassName = testSuite.constructor.name;
2323
const errorInfo = findWhereErrorHasBeenThrown(e, testClassName);
24-
console.error(` ⚠︎ ${errorInfo || e}`.brightRed);
24+
const errorLog = ` ⚠︎ ${errorInfo || e}`;
25+
console.error(errorLog.brightRed);
26+
return errorLog;
2527
}
2628
}
2729
}

bin/runner/test.runner.ts

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,14 @@ export class TestRunner {
6969
const testSuite = new target();
7070
console.log(colors.white.bold(`\n${testName}`));
7171

72-
await this.runTestCycle(target, testSuite);
72+
await this.runTestCycle(target, testSuite, testName);
7373
}
7474

75-
private static async runTestCycle(target: any, testSuite: any) {
75+
private static async runTestCycle(
76+
target: any,
77+
testSuite: any,
78+
testSuiteName: string,
79+
) {
7680
const testCases: ITestCase[] = target.testCases || [];
7781
const dataSetsArray: IDataSet[] = target.testCasesDataSets || [];
7882
const dataTableArray: IDataTableArray[] = target.testCasesDataTable || [];
@@ -88,6 +92,7 @@ export class TestRunner {
8892
await this.runLifecycleMethods(testSuite, beforeEach, 'beforeEach');
8993
await this.runTestCase(
9094
testSuite,
95+
testSuiteName,
9196
methodName,
9297
caseDescription,
9398
dataSetsArray,
@@ -132,6 +137,7 @@ export class TestRunner {
132137

133138
private static async runTestCase(
134139
testSuiteInstance: any,
140+
testSuiteName: string,
135141
methodName: string,
136142
caseDescription: string,
137143
dataSetsArray: IDataSet[],
@@ -140,7 +146,7 @@ export class TestRunner {
140146
) {
141147
const startTime = performance.now();
142148
let status: 'PASSED' | 'FAILED' = 'FAILED';
143-
let error: string = '';
149+
let error: string | undefined = '';
144150
let duration: number = 0;
145151

146152
try {
@@ -162,14 +168,18 @@ export class TestRunner {
162168
this.log.logTestResult(caseDescription || methodName, status, 'grey');
163169
} catch (e: unknown) {
164170
status = 'FAILED';
165-
error = e instanceof Error ? e.message : `Unknown error: ${e}`;
166171
this.isAllPassed = false;
167-
this.log.handleError(e, methodName, caseDescription, testSuiteInstance);
172+
error = this.log.handleError(
173+
e,
174+
methodName,
175+
caseDescription,
176+
testSuiteInstance,
177+
);
168178
} finally {
169179
duration = performance.now() - startTime;
170180
this.reportTestResult(
171-
testSuiteInstance,
172-
methodName,
181+
testSuiteName,
182+
caseDescription || methodName,
173183
status,
174184
duration,
175185
error,
@@ -178,19 +188,19 @@ export class TestRunner {
178188
}
179189

180190
private static reportTestResult(
181-
testSuiteInstance: any,
191+
testSuiteName: string,
182192
methodName: string,
183193
status: 'PASSED' | 'FAILED',
184194
duration: number,
185-
error: string,
195+
error?: string,
186196
) {
187197
if (
188198
this.isReportingEnabled &&
189199
this.reporterModule?.ReportBuilder &&
190200
this.reporterModule?.ReportsRegistry
191201
) {
192202
const reportBuilder = new this.reporterModule.ReportBuilder(
193-
testSuiteInstance.constructor.name,
203+
testSuiteName,
194204
methodName,
195205
)
196206
.status(status)

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@stlib/testing",
3-
"version": "1.0.7-beta.1",
3+
"version": "1.0.7",
44
"description": "Testing framework for TypeScript Node.js applications",
55
"main": "stutil.ts",
66
"types": "stutil.d.ts",
@@ -42,7 +42,7 @@
4242
"@commitlint/cli": "^19.5.0",
4343
"@commitlint/config-conventional": "^19.5.0",
4444
"@commitlint/types": "^19.5.0",
45-
"@stlib/testing-reporter": "^0.0.1",
45+
"@stlib/testing-reporter": "^0.0.2",
4646
"@types/jest": "^29.5.12",
4747
"@types/node": "^20.12.10",
4848
"@typescript-eslint/eslint-plugin": "^7.8.0",

yarn.lock

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,10 +1044,10 @@ __metadata:
10441044
languageName: node
10451045
linkType: hard
10461046

1047-
"@stlib/testing-reporter@npm:^0.0.1":
1048-
version: 0.0.1
1049-
resolution: "@stlib/testing-reporter@npm:0.0.1"
1050-
checksum: 10c0/c5f23f783184f7d001017b925bff9f5e05f131de7b0d6b3baa9eb6dbbdcfceb88c1b9c97c040b829da20837e29d2ba58e4b304a98ecaf24396830fd66e61e38e
1047+
"@stlib/testing-reporter@npm:^0.0.2":
1048+
version: 0.0.2
1049+
resolution: "@stlib/testing-reporter@npm:0.0.2"
1050+
checksum: 10c0/1ad11327967530f7438c9140603bd5eeec0b984a12d4c79ad85ea082e3ffc1c25fc757bd55482a8546d68fe8a3268ee4ae2e4d6ea13fb927c3ac70cf918e22ce
10511051
languageName: node
10521052
linkType: hard
10531053

@@ -1059,7 +1059,7 @@ __metadata:
10591059
"@commitlint/cli": "npm:^19.5.0"
10601060
"@commitlint/config-conventional": "npm:^19.5.0"
10611061
"@commitlint/types": "npm:^19.5.0"
1062-
"@stlib/testing-reporter": "npm:^0.0.1"
1062+
"@stlib/testing-reporter": "npm:^0.0.2"
10631063
"@types/exit": "npm:^0.1.33"
10641064
"@types/jest": "npm:^29.5.12"
10651065
"@types/node": "npm:^20.12.10"

0 commit comments

Comments
 (0)