Skip to content

Commit 6b802cf

Browse files
temp
1 parent 21bf36f commit 6b802cf

File tree

8 files changed

+74
-47
lines changed

8 files changed

+74
-47
lines changed

sdk/feature-management/package-lock.json

Lines changed: 6 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/feature-management/package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@
3131
},
3232
"homepage": "https://github.com/microsoft/FeatureManagement-JavaScript#readme",
3333
"devDependencies": {
34+
"@playwright/test": "^1.46.1",
3435
"@rollup/plugin-typescript": "^11.1.5",
35-
"@types/mocha": "^10.0.6",
36+
"@types/mocha": "^10.0.7",
3637
"@types/node": "^20.10.7",
3738
"@typescript-eslint/eslint-plugin": "^6.18.1",
3839
"@typescript-eslint/parser": "^6.18.1",
39-
"@playwright/test": "^1.46.1",
4040
"chai": "^4.4.0",
4141
"chai-as-promised": "^7.1.1",
4242
"eslint": "^8.56.0",
@@ -46,7 +46,5 @@
4646
"rollup-plugin-dts": "^6.1.0",
4747
"tslib": "^2.6.2",
4848
"typescript": "^5.3.3"
49-
},
50-
"dependencies": {
5149
}
5250
}

sdk/feature-management/src/featureManager.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ export class FeatureManager implements IFeatureManager {
191191
}
192192
}
193193

194-
interface FeatureManagerOptions {
194+
export interface FeatureManagerOptions {
195195
/**
196196
* The custom filters to be used by the feature manager.
197197
*/
@@ -203,6 +203,20 @@ interface FeatureManagerOptions {
203203
onFeatureEvaluated?: (event: EvaluationResult) => void;
204204
}
205205

206+
export class EvaluationResult {
207+
constructor(
208+
// feature flag definition
209+
public readonly feature: FeatureFlag | undefined,
210+
211+
// enabled state
212+
public enabled: boolean = false,
213+
214+
// variant assignment
215+
public variant: Variant | undefined = undefined,
216+
public variantAssignmentReason: VariantAssignmentReason = VariantAssignmentReason.None
217+
) { }
218+
}
219+
206220
/**
207221
* Validates the format of the feature flag definition.
208222
*
@@ -273,17 +287,3 @@ enum VariantAssignmentReason {
273287
*/
274288
Percentile
275289
}
276-
277-
class EvaluationResult {
278-
constructor(
279-
// feature flag definition
280-
public readonly feature: FeatureFlag | undefined,
281-
282-
// enabled state
283-
public enabled: boolean = false,
284-
285-
// variant assignment
286-
public variant: Variant | undefined = undefined,
287-
public variantAssignmentReason: VariantAssignmentReason = VariantAssignmentReason.None
288-
) { }
289-
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT license.
33

4-
export { FeatureManager } from "./featureManager.js";
4+
export { FeatureManager, FeatureManagerOptions, EvaluationResult } from "./featureManager.js";
55
export { ConfigurationMapFeatureFlagProvider, ConfigurationObjectFeatureFlagProvider, IFeatureFlagProvider } from "./featureProvider.js";
66
export { IFeatureFilter } from "./filter/FeatureFilter.js";
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT license.
3+
4+
import * as chai from "chai";
5+
import * as chaiAsPromised from "chai-as-promised";
6+
chai.use(chaiAsPromised);
7+
const expect = chai.expect;
8+
9+
import { FeatureManager, ConfigurationObjectFeatureFlagProvider, EvaluationResult } from "../";
10+
11+
let evaluationResult: EvaluationResult;
12+
13+
const setEvaluationResult = (result: EvaluationResult) => {
14+
evaluationResult = result;
15+
}
16+
17+
describe("feature evaluation", () => {
18+
it("should assign the variant for reason", () => {
19+
const jsonObject = {
20+
"feature_management": {
21+
"feature_flags": [
22+
{ "id": "Alpha", "description": "", "enabled": true}
23+
]
24+
}
25+
};
26+
27+
const provider = new ConfigurationObjectFeatureFlagProvider(jsonObject);
28+
const featureManager = new FeatureManager(provider);
29+
return expect(featureManager.isEnabled("Alpha")).eventually.eq(true);
30+
});
31+
});

sdk/feature-management/tsconfig.base.json

Lines changed: 0 additions & 21 deletions
This file was deleted.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"compilerOptions": {
3+
"lib": [
4+
"DOM",
5+
"WebWorker",
6+
"ESNext"
7+
],
8+
"skipDefaultLibCheck": true,
9+
"module": "ESNext",
10+
"moduleResolution": "Node",
11+
"target": "ES2022",
12+
"strictNullChecks": true,
13+
"strictFunctionTypes": true,
14+
"sourceMap": true,
15+
"inlineSources": true
16+
},
17+
"include": ["src/**/*", "test/**/*"] // Make sure test files are included
18+
}

sdk/feature-management/tsconfig.test.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"extends": "./tsconfig.base.json",
2+
"extends": "./tsconfig.json",
33
"compilerOptions": {
44
"module": "CommonJS",
55
"outDir": "./out"

0 commit comments

Comments
 (0)