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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

[Full changelog](https://github.com/mozilla/glean.js/compare/v0.6.0...main)

* [#143](https://github.com/mozilla/glean.js/pull/143): Provide a way to initialize and reset Glean.js in tests.

# v0.6.0 (2021-03-22)

* [#123](https://github.com/mozilla/glean.js/pull/123): BUGFIX: Fix support for ES6 environments.
Expand Down
22 changes: 22 additions & 0 deletions glean/src/index/webext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,26 @@ export default {
unsetSourceTags(): void {
Glean.unsetSourceTags();
},

/**
* **Test-only API**
*
* Resets the Glean singleton to its initial state and re-initializes it.
*
* TODO: Only allow this function to be called on test mode (depends on Bug 1682771).
*
* @param applicationId The application ID (will be sanitized during initialization).
* @param uploadEnabled Determines whether telemetry is enabled.
* If disabled, all persisted metrics, events and queued pings (except
* first_run_date) are cleared. Default to `true`.
* @param config Glean configuration options.
* @returns A promise that resolves when the initialization is complete.
*/
async testResetGlean(
applicationId: string,
uploadEnabled = true,
config?: ConfigurationInterface
): Promise<void> {
return Glean.testResetGlean(applicationId, uploadEnabled, config);
}
};
18 changes: 18 additions & 0 deletions glean/tests/core/glean.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -412,4 +412,22 @@ describe("Glean", function() {
await Glean.dispatcher.testBlockOnQueue();
assert.strictEqual(Glean.sourceTags, undefined);
});

it("testResetGlean correctly resets", async function () {
const metric = new StringMetricType({
category: "aCategory",
name: "aStringMetric",
sendInPings: ["aPing"],
lifetime: Lifetime.Ping,
disabled: false
});

const TEST_VALUE = "TEST VALUE";
metric.set(TEST_VALUE);

assert.strictEqual(await metric.testGetValue(), TEST_VALUE);
await Glean.testResetGlean(testAppId);

assert.strictEqual(await metric.testGetValue(), undefined);
});
});
Loading