From 64de1d9aec80ea9c8e500a30dfbe901b1ddb02b1 Mon Sep 17 00:00:00 2001 From: Dominik Ehrenberg Date: Tue, 5 Nov 2019 22:41:46 +0100 Subject: [PATCH] [jasmine] Add definition for jasmine.Env.configure and mark methods as deprecated (#40013) * Add definition for jasmine.Env.configure and mark Env methods throwOnExpectationFailure, stopOnSpecFailure, seed and randomizeTests as deprecated * Rename Configuration to EnvConfiguration to prevent possible naaming conflicts * Synchronize files in ts3.1 and root * Move EnvConfiguration to jasmine namespace --- types/jasmine/index.d.ts | 27 +++++++++++++++++++++++++++ types/jasmine/jasmine-tests.ts | 10 +++++++--- types/jasmine/ts3.1/index.d.ts | 27 +++++++++++++++++++++++++++ types/jasmine/ts3.1/jasmine-tests.ts | 10 +++++++--- 4 files changed, 68 insertions(+), 6 deletions(-) diff --git a/types/jasmine/index.d.ts b/types/jasmine/index.d.ts index c359198dce..0fcb1fa189 100644 --- a/types/jasmine/index.d.ts +++ b/types/jasmine/index.d.ts @@ -14,6 +14,7 @@ // Stephen Farrar // Mochamad Arfin // Alex Povar +// Dominik Ehrenberg // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.8 // For ddescribe / iit use : https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/karma-jasmine/karma-jasmine.d.ts @@ -203,6 +204,18 @@ declare namespace jasmine { (ReadonlyArray | { [methodName: string]: any }) : (ReadonlyArray | { [P in keyof T]?: T[P] extends Func ? ReturnType : any }); + /** + * Configuration that can be used when configuring Jasmine via {@link jasmine.Env.configure} + */ + interface EnvConfiguration { + random?: boolean; + seed?: number; + failFast?: boolean; + oneFailurePerSpec?: boolean; + hideDisabled?: boolean; + specFilter?: Function; + } + function clock(): Clock; var matchersUtil: MatchersUtil; @@ -371,14 +384,28 @@ declare namespace jasmine { addCustomEqualityTester(equalityTester: CustomEqualityTester): void; addMatchers(matchers: CustomMatcherFactories): void; specFilter(spec: Spec): boolean; + /** + * @deprecated Use oneFailurePerSpec option in {@link jasmine.Env.configure} instead. + */ throwOnExpectationFailure(value: boolean): void; + /** + * @deprecated Use failFast option in {@link jasmine.Env.configure} instead. + */ + stopOnSpecFailure(value: boolean): void; + /** + * @deprecated Use seed option in {@link jasmine.Env.configure} instead. + */ seed(seed: string | number): string | number; provideFallbackReporter(reporter: Reporter): void; throwingExpectationFailures(): boolean; allowRespy(allow: boolean): void; randomTests(): boolean; + /** + * @deprecated Use random option in {@link jasmine.Env.configure} instead. + */ randomizeTests(b: boolean): void; clearReporters(): void; + configure(configuration: EnvConfiguration): void; } interface FakeTimer { diff --git a/types/jasmine/jasmine-tests.ts b/types/jasmine/jasmine-tests.ts index 082c99cac4..117b25dcf1 100644 --- a/types/jasmine/jasmine-tests.ts +++ b/types/jasmine/jasmine-tests.ts @@ -1413,15 +1413,19 @@ describe("Randomize Tests", () => { it("should allow randomization of the order of tests", () => { expect(() => { const env = jasmine.getEnv(); - env.randomizeTests(true); + env.configure({ + random: true + }); }).not.toThrow(); }); it("should allow a seed to be passed in for randomization", () => { expect(() => { const env = jasmine.getEnv(); - env.randomizeTests(true); - return env.seed(1234); + env.configure({ + random: true, + seed: 1234 + }); }).not.toThrow(); }); }); diff --git a/types/jasmine/ts3.1/index.d.ts b/types/jasmine/ts3.1/index.d.ts index c048ea9bc6..172c0fb082 100644 --- a/types/jasmine/ts3.1/index.d.ts +++ b/types/jasmine/ts3.1/index.d.ts @@ -13,6 +13,7 @@ // Stephen Farrar // Mochamad Arfin // Alex Povar +// Dominik Ehrenberg // For ddescribe / iit use : https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/karma-jasmine/karma-jasmine.d.ts /** @@ -206,6 +207,18 @@ declare namespace jasmine { (ReadonlyArray | { [methodName: string]: any }) : (ReadonlyArray | { [P in keyof T]?: T[P] extends Func ? ReturnType : any }); + /** + * Configuration that can be used when configuring Jasmine via {@link jasmine.Env.configure} + */ + interface EnvConfiguration { + random?: boolean; + seed?: number; + failFast?: boolean; + oneFailurePerSpec?: boolean; + hideDisabled?: boolean; + specFilter?: Function; + } + function clock(): Clock; var matchersUtil: MatchersUtil; @@ -374,14 +387,28 @@ declare namespace jasmine { addCustomEqualityTester(equalityTester: CustomEqualityTester): void; addMatchers(matchers: CustomMatcherFactories): void; specFilter(spec: Spec): boolean; + /** + * @deprecated Use oneFailurePerSpec option in {@link jasmine.Env.configure} instead. + */ throwOnExpectationFailure(value: boolean): void; + /** + * @deprecated Use failFast option in {@link jasmine.Env.configure} instead. + */ + stopOnSpecFailure(value: boolean): void; + /** + * @deprecated Use seed option in {@link jasmine.Env.configure} instead. + */ seed(seed: string | number): string | number; provideFallbackReporter(reporter: Reporter): void; throwingExpectationFailures(): boolean; allowRespy(allow: boolean): void; randomTests(): boolean; + /** + * @deprecated Use random option in {@link jasmine.Env.configure} instead. + */ randomizeTests(b: boolean): void; clearReporters(): void; + configure(configuration: EnvConfiguration): void; } interface FakeTimer { diff --git a/types/jasmine/ts3.1/jasmine-tests.ts b/types/jasmine/ts3.1/jasmine-tests.ts index 189245bef8..327ebb8ab1 100644 --- a/types/jasmine/ts3.1/jasmine-tests.ts +++ b/types/jasmine/ts3.1/jasmine-tests.ts @@ -1413,15 +1413,19 @@ describe("Randomize Tests", () => { it("should allow randomization of the order of tests", () => { expect(() => { const env = jasmine.getEnv(); - env.randomizeTests(true); + env.configure({ + random: true + }); }).not.toThrow(); }); it("should allow a seed to be passed in for randomization", () => { expect(() => { const env = jasmine.getEnv(); - env.randomizeTests(true); - return env.seed(1234); + env.configure({ + random: true, + seed: 1234 + }); }).not.toThrow(); }); });