microsoft/vscode-react-native

Public

mirrored from https://github.com/microsoft/vscode-react-nativeAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
0.3.2

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

src/test/resources/recordingsHelper.ts

50lines · modecode

1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the MIT license. See LICENSE file in the project root for details.
3
4interface TestUsingRecording {
5 (expectation: string, recordingNames: string[], assertion?: () => void): Mocha.ITest;
6 (expectation: string, recordingNames: string[], assertion?: (done: MochaDone) => void): Mocha.ITest;
7 only(expectation: string, recordingNames: string[], assertion?: () => void): Mocha.ITest;
8 only(expectation: string, recordingNames: string[], assertion?: (done: MochaDone) => void): Mocha.ITest;
9 skip(expectation: string, recordingNames: string[], assertion?: () => void): void;
10 skip(expectation: string, recordingNames: string[], assertion?: (done: MochaDone) => void): void;
11}
12
13export interface IRecordingConsumer {
14 loadRecordingFromName(recordingName: string): Q.Promise<void>;
15}
16
17/* This class makes it easy to create a test using a recording. Recommended usage is:
18 const testWithRecordings = new RecordingsHelper(() => recordingConsumer).test;
19 testWithRecordings("expects to do some test thing",
20 [
21 "path/to/recording",
22 "path/to/recording"
23 ], () => {
24 // test code here
25 });
26*/
27export class RecordingsHelper {
28 public test: TestUsingRecording;
29
30 constructor(private getRecordingConsumer: () => IRecordingConsumer) {
31 this.initializeTest();
32 }
33
34 private initializeTest(): void {
35 this.test = <TestUsingRecording>((testName: string, recordingNames: string[], code: () => Q.Promise<void>): void => {
36 if (code.length !== 0) { // Check how many arguments the function has
37 throw new RangeError("(done: mochaDone) parameter is not supported. Please return a promise instead.");
38 }
39 const recordingsHelper = this;
40 recordingNames.forEach(recordingName => {
41 test(`${testName} using recording ${recordingName}`, function () { // We use function () because we need the this pointer
42 return recordingsHelper.getRecordingConsumer().loadRecordingFromName(recordingName).then(code.bind(this));
43 });
44 });
45 });
46 this.test.skip = (expectation: string, recordingNames: string[], assertion?: (done: MochaDone) => void) => {
47 test.skip(expectation, assertion);
48 };
49 }
50}