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 · modeblame

14c2611bdigeff10 years ago1// 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;
7only(expectation: string, recordingNames: string[], assertion?: () => void): Mocha.ITest;
8only(expectation: string, recordingNames: string[], assertion?: (done: MochaDone) => void): Mocha.ITest;
9skip(expectation: string, recordingNames: string[], assertion?: () => void): void;
10skip(expectation: string, recordingNames: string[], assertion?: (done: MochaDone) => void): void;
11}
12
13export interface IRecordingConsumer {
14loadRecordingFromName(recordingName: string): Q.Promise<void>;
15}
16
17/* This class makes it easy to create a test using a recording. Recommended usage is:
18const testWithRecordings = new RecordingsHelper(() => recordingConsumer).test;
19testWithRecordings("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 {
28public test: TestUsingRecording;
29
30constructor(private getRecordingConsumer: () => IRecordingConsumer) {
31this.initializeTest();
32}
33
34private initializeTest(): void {
35this.test = <TestUsingRecording>((testName: string, recordingNames: string[], code: () => Q.Promise<void>): void => {
a4a82040digeff10 years ago36if (code.length !== 0) { // Check how many arguments the function has
37throw new RangeError("(done: mochaDone) parameter is not supported. Please return a promise instead.");
38}
39const recordingsHelper = this;
14c2611bdigeff10 years ago40recordingNames.forEach(recordingName => {
a4a82040digeff10 years ago41test(`${testName} using recording ${recordingName}`, function () { // We use function () because we need the this pointer
42return recordingsHelper.getRecordingConsumer().loadRecordingFromName(recordingName).then(code.bind(this));
14c2611bdigeff10 years ago43});
44});
45});
46this.test.skip = (expectation: string, recordingNames: string[], assertion?: (done: MochaDone) => void) => {
47test.skip(expectation, assertion);
48};
49}
50}