Skip to content

Commit

Permalink
Handle null transmission in flush (#253)
Browse files Browse the repository at this point in the history
* Update libhoney.js
* Add support for async tests
* Add test for flush
  • Loading branch information
sjchmiela authored Apr 26, 2022
1 parent 177a17b commit 79e0c56
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 1 deletion.
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"jest": "^27.2.4",
"jest-in-case": "^1.0.2",
"prettier": "^2.3.1",
"regenerator-runtime": "^0.13.9",
"rollup": "^2.58.0",
"superagent-mocker": "^0.5.2"
},
Expand All @@ -57,6 +58,9 @@
"https-proxy-agent": "^3.0.0"
},
"jest": {
"setupFilesAfterEnv": [
"./setupTests.js"
],
"testPathIgnorePatterns": [
"dist/",
"/node_modules/"
Expand Down
1 change: 1 addition & 0 deletions setupTests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import "regenerator-runtime/runtime";
3 changes: 2 additions & 1 deletion src/__tests__/libhoney_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ describe("libhoney", () => {
});

describe("disabled = true", () => {
it("should not hit transmission", () => {
it("should not hit transmission", async () => {
let honey = new libhoney({
// these two properties are required
writeKey: "12345",
Expand All @@ -165,6 +165,7 @@ describe("libhoney", () => {
let transmission = honey.transmission;

expect(transmission).toBe(null);
await expect(honey.flush()).resolves.toBeUndefined();
});
});
});
4 changes: 4 additions & 0 deletions src/libhoney.js
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,10 @@ export default class Libhoney extends EventEmitter {
this._options
);

if (!transmission) {
return Promise.resolve();
}

return transmission.flush();
}
}
Expand Down

0 comments on commit 79e0c56

Please sign in to comment.