Skip to content

Commit

Permalink
Correctly set and clean up the env variable in set
Browse files Browse the repository at this point in the history
Signed-off-by: Olga Bulat <[email protected]>
  • Loading branch information
obulat committed May 14, 2024
1 parent 9bfd1da commit 53014e4
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions frontend/test/unit/specs/stores/feature-flag-store.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,14 @@ jest.mock(
)

describe("Feature flag store", () => {
let initialEnv
beforeEach(() => {
setActivePinia(createPinia())
initialEnv = process.env.DEPLOYMENT_ENV
})

afterEach(() => {
process.env.DEPLOYMENT_ENV = initialEnv
})

it("initialises state from JSON", () => {
Expand Down Expand Up @@ -145,7 +151,7 @@ describe("Feature flag store", () => {
`(
"returns $featureState for $environment",
({ environment, featureState }) => {
const initialValue = process.env.DEPLOYMENT_ENV
// The value is cleaned up in afterEach
process.env.DEPLOYMENT_ENV = environment
const featureFlagStore = useFeatureFlagStore()

Expand All @@ -155,7 +161,6 @@ describe("Feature flag store", () => {
expect(featureFlagStore.isOn("feat_env_specific")).toEqual(
featureState === "on"
)
process.env.DEPLOYMENT_ENV = initialValue
}
)

Expand All @@ -167,13 +172,12 @@ describe("Feature flag store", () => {
`(
"handles fallback for missing $environment",
({ environment, flagStatus }) => {
const initialValue = process.env.DEPLOYMENT_ENV
// The value is cleaned up in afterEach
process.env.DEPLOYMENT_ENV = environment
const actualStatus = getFlagStatus({
status: { staging: "switchable" },
})
expect(actualStatus).toEqual(flagStatus)
process.env.DEPLOYMENT_ENV = initialValue
}
)

Expand Down

0 comments on commit 53014e4

Please sign in to comment.