Skip to content

Commit

Permalink
fix(Telemetry): Do not send request when there are no events
Browse files Browse the repository at this point in the history
  • Loading branch information
pgrzesik committed Apr 20, 2021
1 parent ef91ae1 commit f430224
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/utils/telemetry/index.js
Expand Up @@ -173,6 +173,8 @@ async function send(options = {}) {
)
).filter(Boolean);

if (!payloadsWithIds.length) return null;

return request(
payloadsWithIds
.map((item) => item.payload)
Expand Down
8 changes: 8 additions & 0 deletions test/unit/lib/utils/telemetry/index.test.js
Expand Up @@ -52,6 +52,8 @@ describe('test/unit/lib/utils/telemetry/index.test.js', () => {
});

afterEach(async () => {
usedOptions = null;
usedUrl = null;
const dirFilenames = await fse.readdir(cacheDirPath);
await Promise.all(
dirFilenames.map(async (filename) => fse.unlink(path.join(cacheDirPath, filename)))
Expand Down Expand Up @@ -104,4 +106,10 @@ describe('test/unit/lib/utils/telemetry/index.test.js', () => {
const dirFilenames = await fse.readdir(cacheDirPath);
expect(dirFilenames.filter(isFilename).length).to.equal(0);
});

it('Should not send request when there are no events to send', async () => {
await send();
expect(usedUrl).to.be.null;
expect(usedOptions).to.be.null;
});
});

0 comments on commit f430224

Please sign in to comment.