swiftlang / vscode-swift

Visual Studio Code Extension for Swift
https://marketplace.visualstudio.com/items?itemName=sswg.swift-lang
Apache License 2.0
754 stars 54 forks source link

mockGlobalModule() cannot mock contextKeys module #1112

Closed matthewbastien closed 1 month ago

matthewbastien commented 1 month ago

Trying to set values on a mockGlobalModule() object does not set that value on the real global module. E.g. the following test will fail:

import { expect } from "chai";
import contextKeys from "../../src/contextKeys";
import { mockGlobalModule } from "../../MockUtils";

suite("test suite", () => {
    const mockedContextKeys = mockGlobalModule(contextKeys);

    test("can mock the contextKeys module", () => {
        mockedContextKeys.isActivated = true;
        expect(contextKeys.isActivated).to.be.true; // Error: expected undefined to be true
    });
});

This PR fixes that issue and adds a test to make sure it will continue working in the future.