Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* [#965](https://github.com/mozilla/glean.js/pull/965): Attempt to infer the Python virtualenv folder from the environment before falling back to the default `.venv`.
* Users may provide a folder name through the `VIRTUAL_ENV` environment variable.
* If the user is inside an active virtualenv the `VIRTUAL_ENV` environment variable is already set by Python. See: https://docs.python.org/3/library/venv.html.
* [#968](https://github.com/mozilla/glean.js/pull/968): Add runtime arguments type checking to `Glean.setUploadEnabled` API.

# v0.25.0 (2021-11-15)

Expand Down
9 changes: 9 additions & 0 deletions glean/src/core/glean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,15 @@ class Glean {
* @param flag When true, enable metric collection.
*/
static setUploadEnabled(flag: boolean): void {
if (!isBoolean(flag)) {
log(
LOG_TAG,
"Unable to change upload state, new value must be a boolean. Ignoring.",
LoggingLevel.Error
);
return;
}

Context.dispatcher.launch(async () => {
if (!Context.initialized) {
log(
Expand Down
14 changes: 14 additions & 0 deletions glean/tests/unit/core/glean.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -605,4 +605,18 @@ describe("Glean", function() {
await Glean.testResetGlean(testAppId, true);
assert.strictEqual(Context.initialized, true);
});

it("setUploadEnabled does nothing in case a non-boolean value is passed to it", async function() {
// Set the current upload value to false,
// strings are "truthy", this way we can be sure calling with the wrong type dod not work.
Glean.setUploadEnabled(false);
await Context.dispatcher.testBlockOnQueue();
assert.strictEqual(Context.uploadEnabled, false);

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
Glean.setUploadEnabled("not a boolean");
await Context.dispatcher.testBlockOnQueue();
assert.strictEqual(Context.uploadEnabled, false);
});
});