microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
7b48f26eb8caae7ed9cc1a09249195dfed76fa76

Branches

Tags

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

Clone

HTTPS

Download ZIP

test/extension/experimentService/experimentService.test.ts

85lines · 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
4import {
5 ExperimentService,
6 ExperimentConfig,
7 ExperimentStatuses,
8 ExperimentResult,
9} from "../../../src/extension/services/experimentService/experimentService";
10import Configstore = require("configstore");
11import assert = require("assert");
12
13suite("experimentService", function () {
14 const configName = "reactNativeToolsConfig";
15 const testExperimentName = "testName";
16 const config = new Configstore(configName);
17
18 teardown(() => {
19 (<any>ExperimentService).instance = null;
20 });
21
22 suite("initializationAndExperimentConfig", function () {
23 test("should return correct experiment config", async () => {
24 let experimentService = ExperimentService.create();
25 let downloadedExperimentsConfig: ExperimentConfig[] = await (<any>experimentService)
26 .downloadConfigRequest;
27 let result = downloadedExperimentsConfig.every(
28 expConfig =>
29 typeof expConfig.enabled === "boolean" &&
30 typeof expConfig.experimentName === "string" &&
31 typeof expConfig.popCoveragePercent === "number",
32 );
33
34 assert.strictEqual(result, true);
35 });
36 });
37
38 suite("executeExperiment", function () {
39 const expTestConfig = {
40 experimentName: testExperimentName,
41 popCoveragePercent: 0.5,
42 enabled: true,
43 };
44
45 const RNTPreviewPromptExp = {
46 experimentName: "RNTPreviewPrompt",
47 popCoveragePercent: 1,
48 enabled: true,
49 };
50
51 async function configureExperimentService(
52 experimentService: any,
53 expConfig: ExperimentConfig,
54 ) {
55 experimentService.downloadedExperimentsConfig = [expConfig];
56 experimentService.experimentsInstances =
57 await experimentService.initializeExperimentsInstances();
58 }
59
60 teardown(() => {
61 (<any>ExperimentService).instance = null;
62 config.delete(testExperimentName);
63 config.delete(RNTPreviewPromptExp.experimentName);
64 });
65
66 test("should skip the experiment", async () => {
67 config.set(testExperimentName, expTestConfig);
68 let experimentService = <any>ExperimentService.create();
69 await configureExperimentService(experimentService, expTestConfig);
70 let experimentResult: ExperimentResult = await experimentService.executeExperiment(
71 expTestConfig,
72 );
73 assert.strictEqual(experimentResult.resultStatus, ExperimentStatuses.DISABLED);
74 });
75
76 test("should succeed the experiment", async () => {
77 let experimentService = <any>ExperimentService.create();
78 await configureExperimentService(experimentService, RNTPreviewPromptExp);
79 let experimentResult: ExperimentResult = await experimentService.executeExperiment(
80 RNTPreviewPromptExp,
81 );
82 assert.strictEqual(experimentResult.resultStatus, ExperimentStatuses.ENABLED);
83 });
84 });
85});
86