Skip to content

Commit

Permalink
Use string primitive instead of String wrapper object Fixes #134
Browse files Browse the repository at this point in the history
  • Loading branch information
bcaudan committed Apr 15, 2017
1 parent 8fd461e commit e1b2ad9
Show file tree
Hide file tree
Showing 15 changed files with 75 additions and 60 deletions.
16 changes: 16 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,19 @@
# 4.0.0

* Use string primitive instead of String wrapper object [#134](https://github.com/bcaudan/jasmine-spec-reporter/issues/134), [#137](https://github.com/bcaudan/jasmine-spec-reporter/issues/137)

## Breaking change

It only impacts TypeScript integrations, `DisplayProcessor` methods signature now use `string` instead of `String`.

Before:

displaySuite(suite: CustomReporterResult, log: String): String;

Now:

displaySuite(suite: CustomReporterResult, log: string): string;

# 3.3.0

* Add low-level print configuration option [#129](https://github.com/bcaudan/jasmine-spec-reporter/issues/129), [#130](https://github.com/bcaudan/jasmine-spec-reporter/issues/130)
Expand Down
2 changes: 1 addition & 1 deletion examples/typescript/README.md
Expand Up @@ -10,7 +10,7 @@ const Jasmine = require("jasmine");
import SuiteInfo = jasmine.SuiteInfo;

class CustomProcessor extends DisplayProcessor {
public displayJasmineStarted(info: SuiteInfo, log: String): String {
public displayJasmineStarted(info: SuiteInfo, log: string): string {
return `TypeScript ${log}`;
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/typescript/spec/helpers/jasmine-runner.ts
Expand Up @@ -4,7 +4,7 @@ const Jasmine = require("jasmine");
import SuiteInfo = jasmine.SuiteInfo;

class CustomProcessor extends DisplayProcessor {
public displayJasmineStarted(info: SuiteInfo, log: String): String {
public displayJasmineStarted(info: SuiteInfo, log: string): string {
return `TypeScript ${log}`;
}
}
Expand Down
16 changes: 8 additions & 8 deletions spec/helpers/test-processor.ts
Expand Up @@ -9,35 +9,35 @@ export class TestProcessor extends DisplayProcessor {
this.test = configuration.customOptions.test;
}

public displayJasmineStarted(info: any, log: String): String {
public displayJasmineStarted(info: any, log: string): string {
return log + this.test;
}

public displaySuite(suite: any, log: String): String {
public displaySuite(suite: any, log: string): string {
return log + this.test;
}

public displaySpecStarted(spec: any, log: String): String {
public displaySpecStarted(spec: any, log: string): string {
return spec.description + this.test;
}

public displaySuccessfulSpec(spec: any, log: String): String {
public displaySuccessfulSpec(spec: any, log: string): string {
return log + this.test;
}

public displayFailedSpec(spec: any, log: String): String {
public displayFailedSpec(spec: any, log: string): string {
return log + this.test;
}

public displaySpecErrorMessages(spec: any, log: String): String {
public displaySpecErrorMessages(spec: any, log: string): string {
return log + this.test;
}

public displaySummaryErrorMessages(spec: any, log: String): String {
public displaySummaryErrorMessages(spec: any, log: string): string {
return log + this.test;
}

public displayPendingSpec(spec: any, log: String): String {
public displayPendingSpec(spec: any, log: string): string {
return log + this.test;
}
}
4 changes: 2 additions & 2 deletions src/configuration.ts
Expand Up @@ -114,7 +114,7 @@ export class Configuration {
/**
* Customize stacktrace filtering
*/
filter?(stacktrace: String): String;
filter?(stacktrace: string): string;
};
/**
* list of display processor to customize output
Expand All @@ -130,5 +130,5 @@ export class Configuration {
* Use process.stdout.write(log + '\n'); to avoid output to
* devtools console while still reporting to command line.
*/
public print?: (log: String) => void;
public print?: (log: string) => void;
}
16 changes: 8 additions & 8 deletions src/display-processor.ts
Expand Up @@ -9,35 +9,35 @@ export class DisplayProcessor {
this.configuration = configuration;
}

public displayJasmineStarted(info: SuiteInfo, log: String): String {
public displayJasmineStarted(info: SuiteInfo, log: string): string {
return log;
}

public displaySuite(suite: CustomReporterResult, log: String): String {
public displaySuite(suite: CustomReporterResult, log: string): string {
return log;
}

public displaySpecStarted(spec: CustomReporterResult, log: String): String {
public displaySpecStarted(spec: CustomReporterResult, log: string): string {
return log;
}

public displaySuccessfulSpec(spec: CustomReporterResult, log: String): String {
public displaySuccessfulSpec(spec: CustomReporterResult, log: string): string {
return log;
}

public displayFailedSpec(spec: CustomReporterResult, log: String): String {
public displayFailedSpec(spec: CustomReporterResult, log: string): string {
return log;
}

public displaySpecErrorMessages(spec: CustomReporterResult, log: String): String {
public displaySpecErrorMessages(spec: CustomReporterResult, log: string): string {
return log;
}

public displaySummaryErrorMessages(spec: CustomReporterResult, log: String): String {
public displaySummaryErrorMessages(spec: CustomReporterResult, log: string): string {
return log;
}

public displayPendingSpec(spec: CustomReporterResult, log: String): String {
public displayPendingSpec(spec: CustomReporterResult, log: string): string {
return log;
}
}
14 changes: 7 additions & 7 deletions src/display/execution-display.ts
Expand Up @@ -28,7 +28,7 @@ export class ExecutionDisplay {
}

public jasmineStarted(suiteInfo: SuiteInfo): void {
this.logger.process(suiteInfo, (displayProcessor: DisplayProcessor, object: SuiteInfo, log: String) => {
this.logger.process(suiteInfo, (displayProcessor: DisplayProcessor, object: SuiteInfo, log: string) => {
return displayProcessor.displayJasmineStarted(object, log);
});
}
Expand All @@ -38,7 +38,7 @@ export class ExecutionDisplay {
this.ensureSuiteDisplayed();
this.logger.process(
result,
(displayProcessor: DisplayProcessor, object: CustomReporterResult, log: String) => {
(displayProcessor: DisplayProcessor, object: CustomReporterResult, log: string) => {
return displayProcessor.displaySpecStarted(object, log);
}
);
Expand All @@ -51,7 +51,7 @@ export class ExecutionDisplay {
this.ensureSuiteDisplayed();
this.logger.process(
result,
(displayProcessor: DisplayProcessor, object: CustomReporterResult, log: String) => {
(displayProcessor: DisplayProcessor, object: CustomReporterResult, log: string) => {
return displayProcessor.displaySuccessfulSpec(object, log);
}
);
Expand All @@ -64,15 +64,15 @@ export class ExecutionDisplay {
this.ensureSuiteDisplayed();
this.logger.process(
result,
(displayProcessor: DisplayProcessor, object: CustomReporterResult, log: String) => {
(displayProcessor: DisplayProcessor, object: CustomReporterResult, log: string) => {
return displayProcessor.displayFailedSpec(object, log);
}
);
if (this.configuration.spec.displayErrorMessages) {
this.logger.increaseIndent();
this.logger.process(
result,
(displayProcessor: DisplayProcessor, object: CustomReporterResult, log: String) => {
(displayProcessor: DisplayProcessor, object: CustomReporterResult, log: string) => {
return displayProcessor.displaySpecErrorMessages(object, log);
}
);
Expand All @@ -87,7 +87,7 @@ export class ExecutionDisplay {
this.ensureSuiteDisplayed();
this.logger.process(
result,
(displayProcessor: DisplayProcessor, object: CustomReporterResult, log: String) => {
(displayProcessor: DisplayProcessor, object: CustomReporterResult, log: string) => {
return displayProcessor.displayPendingSpec(object, log);
}
);
Expand Down Expand Up @@ -129,7 +129,7 @@ export class ExecutionDisplay {
private displaySuite(suite: CustomReporterResult): void {
this.logger.newLine();
this.computeSuiteIndent();
this.logger.process(suite, (displayProcessor: DisplayProcessor, object: CustomReporterResult, log: String) => {
this.logger.process(suite, (displayProcessor: DisplayProcessor, object: CustomReporterResult, log: string) => {
return displayProcessor.displaySuite(object, log);
});
this.logger.increaseIndent();
Expand Down
10 changes: 5 additions & 5 deletions src/display/logger.ts
Expand Up @@ -2,26 +2,26 @@ import {DisplayProcessor} from "../display-processor";
import {CustomReporterResult} from "../spec-reporter";
import SuiteInfo = jasmine.SuiteInfo;

export type ProcessFunction = (displayProcessor: DisplayProcessor, object: ProcessObject, log: String) => String;
export type ProcessFunction = (displayProcessor: DisplayProcessor, object: ProcessObject, log: string) => string;
export type ProcessObject = SuiteInfo | CustomReporterResult;

export class Logger {
private indent = " ";
private currentIndent = "";
private lastWasNewLine = false;

constructor(private displayProcessors: DisplayProcessor[], private print: (line: String) => void) {
constructor(private displayProcessors: DisplayProcessor[], private print: (line: string) => void) {
}

public log(stuff: String): void {
stuff.split("\n").forEach((line: String) => {
public log(stuff: string): void {
stuff.split("\n").forEach((line: string) => {
this.print(line !== "" ? this.currentIndent + line : line);
});
this.lastWasNewLine = false;
}

public process(object: ProcessObject, processFunction: ProcessFunction): void {
let log: String = "";
let log = "";
this.displayProcessors.forEach((displayProcessor: DisplayProcessor) => {
log = processFunction(displayProcessor, object, log);
});
Expand Down
2 changes: 1 addition & 1 deletion src/display/summary-display.ts
Expand Up @@ -71,7 +71,7 @@ export class SummaryDisplay {
this.logger.increaseIndent();
this.logger.process(
spec,
(displayProcessor: DisplayProcessor, object: CustomReporterResult, log: String) => {
(displayProcessor: DisplayProcessor, object: CustomReporterResult, log: string) => {
return displayProcessor.displaySummaryErrorMessages(object, log);
}
);
Expand Down
20 changes: 10 additions & 10 deletions src/processors/default-processor.ts
Expand Up @@ -2,40 +2,40 @@ import {DisplayProcessor} from "../display-processor";
import {CustomReporterResult} from "../spec-reporter";

export class DefaultProcessor extends DisplayProcessor {
private static displaySpecDescription(spec: CustomReporterResult): String {
private static displaySpecDescription(spec: CustomReporterResult): string {
return spec.description;
}

public displayJasmineStarted(): String {
public displayJasmineStarted(): string {
return "Spec started";
}

public displaySuite(suite: CustomReporterResult): String {
public displaySuite(suite: CustomReporterResult): string {
return suite.description;
}

public displaySuccessfulSpec(spec: CustomReporterResult): String {
public displaySuccessfulSpec(spec: CustomReporterResult): string {
return DefaultProcessor.displaySpecDescription(spec);
}

public displayFailedSpec(spec: CustomReporterResult): String {
public displayFailedSpec(spec: CustomReporterResult): string {
return DefaultProcessor.displaySpecDescription(spec);
}

public displaySpecErrorMessages(spec: CustomReporterResult): String {
public displaySpecErrorMessages(spec: CustomReporterResult): string {
return this.displayErrorMessages(spec, this.configuration.spec.displayStacktrace);
}

public displaySummaryErrorMessages(spec: CustomReporterResult): String {
public displaySummaryErrorMessages(spec: CustomReporterResult): string {
return this.displayErrorMessages(spec, this.configuration.summary.displayStacktrace);
}

public displayPendingSpec(spec: CustomReporterResult): String {
public displayPendingSpec(spec: CustomReporterResult): string {
return DefaultProcessor.displaySpecDescription(spec);
}

private displayErrorMessages(spec: CustomReporterResult, withStacktrace: boolean): String {
const logs: String[] = [];
private displayErrorMessages(spec: CustomReporterResult, withStacktrace: boolean): string {
const logs: string[] = [];
for (const failedExpectation of spec.failedExpectations) {
logs.push("- ".failed + failedExpectation.message.failed);
if (withStacktrace && failedExpectation.stack) {
Expand Down
6 changes: 3 additions & 3 deletions src/processors/spec-colors-processor.ts
Expand Up @@ -2,15 +2,15 @@ import {DisplayProcessor} from "../display-processor";
import {CustomReporterResult} from "../spec-reporter";

export class SpecColorsProcessor extends DisplayProcessor {
public displaySuccessfulSpec(spec: CustomReporterResult, log: String): String {
public displaySuccessfulSpec(spec: CustomReporterResult, log: string): string {
return log.successful;
}

public displayFailedSpec(spec: CustomReporterResult, log: String): String {
public displayFailedSpec(spec: CustomReporterResult, log: string): string {
return log.failed;
}

public displayPendingSpec(spec: CustomReporterResult, log: String): String {
public displayPendingSpec(spec: CustomReporterResult, log: string): string {
return log.pending;
}
}
6 changes: 3 additions & 3 deletions src/processors/spec-durations-processor.ts
Expand Up @@ -2,15 +2,15 @@ import {DisplayProcessor} from "../display-processor";
import {CustomReporterResult} from "../spec-reporter";

export class SpecDurationsProcessor extends DisplayProcessor {
private static displayDuration(spec: CustomReporterResult, log: String): String {
private static displayDuration(spec: CustomReporterResult, log: string): string {
return `${log} (${spec.duration})`;
}

public displaySuccessfulSpec(spec: CustomReporterResult, log: String): String {
public displaySuccessfulSpec(spec: CustomReporterResult, log: string): string {
return SpecDurationsProcessor.displayDuration(spec, log);
}

public displayFailedSpec(spec: CustomReporterResult, log: String): String {
public displayFailedSpec(spec: CustomReporterResult, log: string): string {
return SpecDurationsProcessor.displayDuration(spec, log);
}
}
6 changes: 3 additions & 3 deletions src/processors/spec-prefixes-processor.ts
Expand Up @@ -2,15 +2,15 @@ import {DisplayProcessor} from "../display-processor";
import {CustomReporterResult} from "../spec-reporter";

export class SpecPrefixesProcessor extends DisplayProcessor {
public displaySuccessfulSpec(spec: CustomReporterResult, log: String): String {
public displaySuccessfulSpec(spec: CustomReporterResult, log: string): string {
return this.configuration.prefixes.successful + log;
}

public displayFailedSpec(spec: CustomReporterResult, log: String): String {
public displayFailedSpec(spec: CustomReporterResult, log: string): string {
return this.configuration.prefixes.failed + log;
}

public displayPendingSpec(spec: CustomReporterResult, log: String): String {
public displayPendingSpec(spec: CustomReporterResult, log: string): string {
return this.configuration.prefixes.pending + log;
}
}
14 changes: 7 additions & 7 deletions src/processors/suite-numbering-processor.ts
Expand Up @@ -2,28 +2,28 @@ import {DisplayProcessor} from "../display-processor";
import {CustomReporterResult} from "../spec-reporter";

interface SuiteHierarchyInfo {
name: String;
name: string;
number: number;
}

export class SuiteNumberingProcessor extends DisplayProcessor {
private static getParentName(element: CustomReporterResult): String {
private static getParentName(element: CustomReporterResult): string {
return element.fullName.replace(element.description, "").trim();
}

private suiteHierarchy: SuiteHierarchyInfo[] = [];

public displaySuite(suite: CustomReporterResult, log: String): String {
public displaySuite(suite: CustomReporterResult, log: string): string {
return `${this.computeNumber(suite)} ${log}`;
}

private computeNumber(suite: CustomReporterResult): String {
private computeNumber(suite: CustomReporterResult): string {
this.computeHierarchy(suite);
return this.computeHierarchyNumber();
}

private computeHierarchy(suite: CustomReporterResult): void {
const parentName: String = SuiteNumberingProcessor.getParentName(suite);
const parentName: string = SuiteNumberingProcessor.getParentName(suite);
let i = 0;
for (; i < this.suiteHierarchy.length; i++) {
if (this.suiteHierarchy[i].name === parentName) {
Expand All @@ -37,8 +37,8 @@ export class SuiteNumberingProcessor extends DisplayProcessor {
}
}

private computeHierarchyNumber(): String {
let hierarchyNumber: String = "";
private computeHierarchyNumber(): string {
let hierarchyNumber = "";
for (const suite of this.suiteHierarchy) {
hierarchyNumber += suite.number + ".";
}
Expand Down

0 comments on commit e1b2ad9

Please sign in to comment.