-
Notifications
You must be signed in to change notification settings - Fork 2
JS FM validation test #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
02699e6
add basic feature flag test
zhiyuanliang-ms 789f6f4
update readme
zhiyuanliang-ms e1be2af
remove out dir
zhiyuanliang-ms 4488687
update gitignore
zhiyuanliang-ms 7682616
Validation tests for dotnet (#16)
rossgrambo 351a1f9
Merge branch 'main' of https://github.com/microsoft/FeatureManagement…
zhiyuanliang-ms 5050dac
remove package-lock.json
zhiyuanliang-ms fa14233
update gitignore
zhiyuanliang-ms c2ea91f
add variant feature flag test
zhiyuanliang-ms 5d5f061
update string to boolean
zhiyuanliang-ms cfcecce
resolve merge conflict
zhiyuanliang-ms 289ff11
Merge branch 'main' of https://github.com/microsoft/FeatureManagement…
zhiyuanliang-ms 372a08b
update code ql & gitignore
zhiyuanliang-ms 6a6ccb1
add telemetry test with provider
zhiyuanliang-ms 376e6bb
update
zhiyuanliang-ms fa3b7bb
validate latest packages
zhiyuanliang-ms 8c2a0e3
update
zhiyuanliang-ms de62054
Merge branch 'main' into zhiyuanliang/js-validation
zhiyuanliang-ms File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -407,4 +407,10 @@ venv/ | |
| .project | ||
| .settings | ||
| mvnw* | ||
| target/ | ||
| target/ | ||
|
|
||
| package-lock.json | ||
|
|
||
| # JavaScript bundler folder | ||
| out/ | ||
| *.tgz | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| # JavaScript Feature Management Validation Tests | ||
|
|
||
| This directory contains test cases to verify that the correctness of the latest JS Feature Management library against the files in the `Samples` directory. | ||
|
|
||
| ## Running the test | ||
|
|
||
| To run the tests, execute the following command: | ||
|
|
||
| ```bash | ||
| npm install | ||
| npm run build | ||
| npm run test | ||
| ``` | ||
51 changes: 51 additions & 0 deletions
51
libraryValidations/JavaScript/featureEvaluationValidation.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT license. | ||
|
|
||
| import * as fs from "node:fs/promises"; | ||
| import { FeatureManager, ConfigurationObjectFeatureFlagProvider } from "@microsoft/feature-management"; | ||
| import {FILE_PATH, SAMPLE_JSON_KEY, TESTS_JSON_KEY, validateFeatureEvaluation, FeatureFlagTest } from "./utils.js"; | ||
|
|
||
| async function runTest(testName: string) { | ||
| const config = JSON.parse(await fs.readFile(FILE_PATH + testName + SAMPLE_JSON_KEY, "utf8")); | ||
| const testcases: FeatureFlagTest[] = JSON.parse(await fs.readFile(FILE_PATH + testName + TESTS_JSON_KEY, "utf8")); | ||
| const ffProvider = new ConfigurationObjectFeatureFlagProvider(config); | ||
| const fm = new FeatureManager(ffProvider); | ||
|
|
||
| for (const testcase of testcases){ | ||
| validateFeatureEvaluation(testcase, fm); | ||
| } | ||
| } | ||
|
|
||
| describe("feature evaluation validation", function () { | ||
| it("should pass NoFilters test", async () => { | ||
| await runTest("NoFilters"); | ||
| }); | ||
|
|
||
| it("should pass RequirementType test", async () => { | ||
| await runTest("RequirementType"); | ||
| }); | ||
|
|
||
| it("should pass RequirementType test", async () => { | ||
| await runTest("RequirementType"); | ||
| }); | ||
|
|
||
| it("should pass TimeWindowFilter test", async () => { | ||
| await runTest("TimeWindowFilter"); | ||
| }); | ||
|
|
||
| it("should pass TargetingFilter test", async () => { | ||
| await runTest("TargetingFilter"); | ||
| }); | ||
|
|
||
| it("should pass TargetingFilter.modified test", async () => { | ||
| await runTest("TargetingFilter.modified"); | ||
| }); | ||
|
|
||
| it("should pass BasicVariant test", async () => { | ||
| await runTest("BasicVariant"); | ||
| }); | ||
|
|
||
| it("should pass VariantAssignment test", async () => { | ||
| await runTest("VariantAssignment"); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| { | ||
| "type": "module", | ||
| "scripts": { | ||
| "build": "npm run clean && tsc -p ./tsconfig.json", | ||
| "clean": "rimraf out ", | ||
| "test": "mocha out/*.test.{js,cjs,mjs} --parallel" | ||
| }, | ||
| "dependencies": { | ||
| "@types/chai-as-promised": "^8.0.1", | ||
| "@types/mocha": "^10.0.6", | ||
| "@types/node": "^20.10.7", | ||
| "@types/sinon": "^17.0.1", | ||
| "chai": "^5.1.2", | ||
| "chai-as-promised": "^8.0.0", | ||
| "mocha": "^10.2.0", | ||
| "rimraf": "^5.0.5", | ||
| "sinon": "^15.2.0", | ||
| "tslib": "^2.6.2", | ||
| "typescript": "^5.3.3", | ||
| "@microsoft/feature-management": "2.0.0-preview.3", | ||
| "@microsoft/feature-management-applicationinsights-browser": "2.0.0-preview.3", | ||
| "@microsoft/feature-management-applicationinsights-node": "2.0.0-preview.3", | ||
| "@azure/app-configuration-provider": "2.0.0-preview.1", | ||
| "@microsoft/applicationinsights-web": "^3.3.4", | ||
| "applicationinsights": "^2.9.6" | ||
| } | ||
| } |
106 changes: 106 additions & 0 deletions
106
libraryValidations/JavaScript/telemetryWithProviderValidation.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT license. | ||
|
|
||
| import * as sinon from "sinon"; | ||
| import * as fs from "node:fs/promises"; | ||
| import { load } from "@azure/app-configuration-provider"; | ||
| import { FeatureManager, ConfigurationMapFeatureFlagProvider } from "@microsoft/feature-management"; | ||
| import { createTelemetryPublisher as createNodeTelemetryPublisher } from "@microsoft/feature-management-applicationinsights-node"; | ||
| import { createTelemetryPublisher as createBrowserTelemetryPublisher } from "@microsoft/feature-management-applicationinsights-browser"; | ||
| import {FILE_PATH, TESTS_JSON_KEY, FeatureFlagTest, validateFeatureEvaluation, validateTelemetryWithProvider } from "./utils.js"; | ||
| import { ApplicationInsights } from "@microsoft/applicationinsights-web"; | ||
| import applicationInsights from "applicationinsights"; | ||
|
|
||
| // For telemetry validation | ||
| let eventNameToValidate; | ||
| let eventPropertiesToValidate; | ||
|
|
||
| applicationInsights.setup("DUMMY-CONNECTION-STRING").start(); | ||
| sinon.stub(applicationInsights.defaultClient, "trackEvent").callsFake((event) => { | ||
| eventNameToValidate = event.name; | ||
| eventPropertiesToValidate = event.properties; | ||
| }); | ||
|
|
||
| const appInsights = new ApplicationInsights({ config: { connectionString: "DUMMY-CONNECTION-STRING" }}); | ||
| sinon.stub(appInsights, "trackEvent").callsFake((event, customProperties) => { | ||
| eventNameToValidate = event.name; | ||
| eventPropertiesToValidate = customProperties; | ||
| }); | ||
|
|
||
| async function runTestWithProviderAndNodePackage(testName: string) { | ||
| const connectionString = process.env["APP_CONFIG_VALIDATION_CONNECTION_STRING"]; | ||
| if (connectionString === undefined) { | ||
| console.log("Skipping test as environment variable APP_CONFIG_VALIDATION_CONNECTION_STRING is not set."); | ||
| return; | ||
| } | ||
| const config = await load( | ||
| connectionString, | ||
| { | ||
| featureFlagOptions: { | ||
| enabled: true, | ||
| selectors: [ | ||
| { | ||
| keyFilter: "*" | ||
| } | ||
| ] | ||
| } | ||
| }); | ||
| const testcases: FeatureFlagTest[] = JSON.parse(await fs.readFile(FILE_PATH + testName + TESTS_JSON_KEY, "utf8")); | ||
| const ffProvider = new ConfigurationMapFeatureFlagProvider(config); | ||
| const fm = new FeatureManager(ffProvider, { onFeatureEvaluated: createNodeTelemetryPublisher(applicationInsights.defaultClient) }); | ||
| for (const testcase of testcases){ | ||
| const featureFlagName = testcase.FeatureFlagName; | ||
| const context = { userId: testcase.Inputs?.User, groups: testcase.Inputs?.Groups }; | ||
| await fm.getVariant(featureFlagName, context); | ||
| validateTelemetryWithProvider(testcase, connectionString, eventNameToValidate, eventPropertiesToValidate); | ||
| } | ||
| } | ||
|
|
||
| async function runTestWithProviderAndBrowserPackage(testName: string) { | ||
| const connectionString = process.env["APP_CONFIG_VALIDATION_CONNECTION_STRING"]; | ||
| if (connectionString === undefined) { | ||
| console.log("Skipping test as environment variable APP_CONFIG_VALIDATION_CONNECTION_STRING is not set."); | ||
| return; | ||
| } | ||
| const config = await load( | ||
| connectionString, | ||
| { | ||
| featureFlagOptions: { | ||
| enabled: true, | ||
| selectors: [ | ||
| { | ||
| keyFilter: "*" | ||
| } | ||
| ] | ||
| } | ||
| }); | ||
| const testcases: FeatureFlagTest[] = JSON.parse(await fs.readFile(FILE_PATH + testName + TESTS_JSON_KEY, "utf8")); | ||
| const ffProvider = new ConfigurationMapFeatureFlagProvider(config); | ||
| const fm = new FeatureManager(ffProvider, { onFeatureEvaluated: createBrowserTelemetryPublisher(appInsights) }); | ||
| for (const testcase of testcases){ | ||
| const featureFlagName = testcase.FeatureFlagName; | ||
| const context = { userId: testcase.Inputs?.User, groups: testcase.Inputs?.Groups }; | ||
| await fm.getVariant(featureFlagName, context); | ||
| validateTelemetryWithProvider(testcase, connectionString, eventNameToValidate, eventPropertiesToValidate); | ||
| } | ||
| } | ||
|
|
||
| describe("telemetry with provider and node package", function () { | ||
| it("should pass ProviderTelemetry test", async () => { | ||
| await runTestWithProviderAndNodePackage("ProviderTelemetry"); | ||
| }); | ||
|
|
||
| it("should pass ProviderTelemetryComplete test", async () => { | ||
| await runTestWithProviderAndNodePackage("ProviderTelemetryComplete"); | ||
| }); | ||
| }); | ||
|
|
||
| describe("telemetry with provider and browser package", function () { | ||
| it("should pass ProviderTelemetry test", async () => { | ||
| await runTestWithProviderAndBrowserPackage("ProviderTelemetry"); | ||
| }); | ||
|
|
||
| it("should pass ProviderTelemetryComplete test", async () => { | ||
| await runTestWithProviderAndBrowserPackage("ProviderTelemetryComplete"); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| { | ||
| "compilerOptions": { | ||
| "lib": [ | ||
| "DOM", | ||
| "WebWorker", | ||
| "ESNext" | ||
| ], | ||
| "skipDefaultLibCheck": true, | ||
| "module": "ESNext", | ||
| "moduleResolution": "Node", | ||
| "target": "ES2022", | ||
| "strictNullChecks": true, | ||
| "strictFunctionTypes": true, | ||
| "sourceMap": true, | ||
| "inlineSources": true, | ||
| "esModuleInterop": true, | ||
| "outDir": "./out" | ||
| }, | ||
| "exclude": [ | ||
| "node_modules", | ||
| "**/node_modules/*" | ||
| ] | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.