Skip to content

Commit 1336dba

Browse files
Merge pull request #46 from microsoft/main
Merge main to release/v1
2 parents 0b9f88b + 9108ea1 commit 1336dba

File tree

3 files changed

+85
-45
lines changed

3 files changed

+85
-45
lines changed

test/browser/browser.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,15 @@ test("Testcase can pass in browser environment", async ({ page }) => {
77
const filePath = path.join(__dirname, "index.html");
88

99
let hasPageError = false;
10-
1110
page.on("pageerror", (err) => {
1211
hasPageError = true;
1312
console.log(`Page Error: ${err.message}`);
1413
});
1514

1615
await page.goto(`file:${filePath}`);
16+
await page.waitForTimeout(10000);
1717

1818
const failures = await page.evaluate(() => (window as any).mochaFailures);
19-
2019
chai.expect(failures).to.equal(0);
2120
chai.expect(hasPageError).to.be.false;
2221
});

test/browser/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<script src="../../dist/umd/index.js"></script>
2020
<script src="./testcases.js"></script>
2121
<script class="mocha-exec">
22-
mocha.run(function (failures) {
22+
mocha.run(failures => {
2323
window.mochaFailures = failures;
2424
});
2525
</script>

test/browser/testcases.js

Lines changed: 83 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,104 @@
11
const ConfigurationObjectFeatureFlagProvider = FeatureManagement.ConfigurationObjectFeatureFlagProvider;
22
const FeatureManager = FeatureManagement.FeatureManager;
33

4-
describe("feature manager", () => {
5-
it("should load from json string",
6-
async () => {
7-
const jsonObject = {
8-
"feature_management": {
9-
"feature_flags": [
4+
const jsonObject = {
5+
"feature_management": {
6+
"feature_flags": [
7+
{
8+
"id": "ComplexTargeting",
9+
"description": "A feature flag using a targeting filter, that will return true for Alice, Stage1, and 50% of Stage2. Dave and Stage3 are excluded. The default rollout percentage is 25%.",
10+
"enabled": true,
11+
"conditions": {
12+
"client_filters": [
1013
{
11-
"id": "ComplexTargeting",
12-
"description": "A feature flag using a targeting filter, that will return true for Alice, Stage1, and 50% of Stage2. Dave and Stage3 are excluded. The default rollout percentage is 25%.",
13-
"enabled": true,
14-
"conditions": {
15-
"client_filters": [
16-
{
17-
"name": "Microsoft.Targeting",
18-
"parameters": {
19-
"Audience": {
20-
"Users": [
21-
"Alice"
22-
],
23-
"Groups": [
24-
{
25-
"Name": "Stage1",
26-
"RolloutPercentage": 100
27-
},
28-
{
29-
"Name": "Stage2",
30-
"RolloutPercentage": 50
31-
}
32-
],
33-
"DefaultRolloutPercentage": 25,
34-
"Exclusion": {
35-
"Users": ["Dave"],
36-
"Groups": ["Stage3"]
37-
}
38-
}
14+
"name": "Microsoft.Targeting",
15+
"parameters": {
16+
"Audience": {
17+
"Users": [
18+
"Alice"
19+
],
20+
"Groups": [
21+
{
22+
"Name": "Stage1",
23+
"RolloutPercentage": 100
24+
},
25+
{
26+
"Name": "Stage2",
27+
"RolloutPercentage": 50
3928
}
29+
],
30+
"DefaultRolloutPercentage": 25,
31+
"Exclusion": {
32+
"Users": ["Dave"],
33+
"Groups": ["Stage3"]
4034
}
41-
]
35+
}
4236
}
4337
}
4438
]
4539
}
46-
};
47-
48-
const provider = new ConfigurationObjectFeatureFlagProvider(jsonObject);
49-
const featureManager = new FeatureManager(provider);
40+
}
41+
]
42+
}
43+
};
44+
45+
const provider = new ConfigurationObjectFeatureFlagProvider(jsonObject);
46+
const featureManager = new FeatureManager(provider);
47+
48+
describe("feature manager", () => {
49+
it("should not target user Aiden in default rollout",
50+
async () => {
5051
chai.expect(await featureManager.isEnabled("ComplexTargeting", { userId: "Aiden" })).to.eq(false);
52+
}
53+
).timeout(1000);;
54+
55+
it("should target user Bloosom in default rollout",
56+
async () => {
5157
chai.expect(await featureManager.isEnabled("ComplexTargeting", { userId: "Blossom" })).to.eq(true);
58+
}
59+
).timeout(1000);;
60+
61+
it("should target user Alice",
62+
async () => {
5263
chai.expect(await featureManager.isEnabled("ComplexTargeting", { userId: "Alice" })).to.eq(true);
64+
}
65+
).timeout(1000);;
66+
67+
it("should target user Aiden in group Stage1",
68+
async () => {
5369
chai.expect(await featureManager.isEnabled("ComplexTargeting", { userId: "Aiden", groups: ["Stage1"] })).to.eq(true);
70+
}
71+
).timeout(1000);;
72+
73+
it("should not target user Dave in group Stage1",
74+
async () => {
75+
chai.expect(await featureManager.isEnabled("ComplexTargeting", { userId: "Dave", groups: ["Stage1"] })).to.eq(false);
76+
}
77+
).timeout(1000);;
78+
79+
it("should not target empty user in group Stage2",
80+
async () => {
5481
chai.expect(await featureManager.isEnabled("ComplexTargeting", { groups: ["Stage2"] })).to.eq(false);
82+
}
83+
).timeout(1000);;
84+
85+
it("should target user Aiden in group Stage2",
86+
async () => {
5587
chai.expect(await featureManager.isEnabled("ComplexTargeting", { userId: "Aiden", groups: ["Stage2"] })).to.eq(true);
88+
}
89+
).timeout(1000);;
90+
91+
it("should not target user Chris in group Stage2",
92+
async () => {
5693
chai.expect(await featureManager.isEnabled("ComplexTargeting", { userId: "Chris", groups: ["Stage2"] })).to.eq(false);
57-
chai.expect(await featureManager.isEnabled("ComplexTargeting", { groups: ["Stage3"] })).to.eq(false),
94+
}
95+
).timeout(1000);;
96+
97+
it("should not target group Stage3",
98+
async () => {
99+
chai.expect(await featureManager.isEnabled("ComplexTargeting", { groups: ["Stage3"] })).to.eq(false);
58100
chai.expect(await featureManager.isEnabled("ComplexTargeting", { userId: "Alice", groups: ["Stage3"] })).to.eq(false);
59101
chai.expect(await featureManager.isEnabled("ComplexTargeting", { userId: "Blossom", groups: ["Stage3"] })).to.eq(false);
60-
chai.expect(await featureManager.isEnabled("ComplexTargeting", { userId: "Dave", groups: ["Stage1"] })).to.eq(false);
61102
}
62-
);
103+
).timeout(1000);
63104
});

0 commit comments

Comments
 (0)