-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: enable telemetry notice * chore: update telemetry date, notify * chore(telemetry): refactor telemetry notices * chore: add changeset * chore: improve debugging * chore: update debug * fix: logical error * chore(lint): remove unused input * chore: improve telemetry debug * chore: improve telemetry tests * chore: allow isCI to be stubbed * chore: stub process.env * chore: stub process.env * chore: add env to class * chore: act like we're not on CI * test: didn't commit the env stub properly * chore: tweak wording
- Loading branch information
1 parent
1db4e92
commit 0c7b42d
Showing
6 changed files
with
133 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'@astrojs/telemetry': patch | ||
'astro': patch | ||
--- | ||
|
||
Update telemetry notice |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,83 @@ | ||
import { expect } from 'chai'; | ||
import { AstroTelemetry } from '../dist/index.js'; | ||
|
||
describe('AstroTelemetry', () => { | ||
function setup() { | ||
const config = new Map(); | ||
const telemetry = new AstroTelemetry({ version: '0.0.0-test.1' }); | ||
const logs = []; | ||
// Stub isCI to false so we can test user-facing behavior | ||
telemetry.isCI = false; | ||
// Stub process.env to properly test in Astro's own CI | ||
telemetry.env = {}; | ||
// Override config so we can inspect it | ||
telemetry.config = config; | ||
// Override debug so we can inspect it | ||
telemetry.debug.enabled = true; | ||
telemetry.debug.log = (...args) => logs.push(args); | ||
|
||
return { telemetry, config, logs } | ||
} | ||
describe('AstroTelemetry', () => { | ||
let oldCI; | ||
before(() => { | ||
oldCI = process.env.CI; | ||
// Stub process.env.CI to `false` | ||
process.env.CI = 'false'; | ||
}) | ||
after(() => { | ||
process.env.CI = oldCI; | ||
}) | ||
it('initializes when expected arguments are given', () => { | ||
const telemetry = new AstroTelemetry({ version: '0.0.0-test.1' }); | ||
const { telemetry } = setup(); | ||
expect(telemetry).to.be.instanceOf(AstroTelemetry); | ||
}); | ||
it('does not record event if disabled', async () => { | ||
const { telemetry, config, logs } = setup(); | ||
telemetry.setEnabled(false); | ||
const [key] = Array.from(config.keys()); | ||
expect(key).not.to.be.undefined; | ||
expect(config.get(key)).to.be.false; | ||
expect(telemetry.enabled).to.be.false; | ||
expect(telemetry.isDisabled).to.be.true; | ||
const result = await telemetry.record(['TEST']); | ||
expect(result).to.be.undefined; | ||
const [log] = logs; | ||
expect(log).not.to.be.undefined; | ||
expect(logs.join('')).to.match(/disabled/); | ||
}); | ||
it('records event if enabled', async () => { | ||
const { telemetry, config, logs } = setup(); | ||
telemetry.setEnabled(true); | ||
const [key] = Array.from(config.keys()); | ||
expect(key).not.to.be.undefined; | ||
expect(config.get(key)).to.be.true; | ||
expect(telemetry.enabled).to.be.true; | ||
expect(telemetry.isDisabled).to.be.false; | ||
await telemetry.record(['TEST']); | ||
expect(logs.length).to.equal(2); | ||
}); | ||
it('respects disable from notify', async () => { | ||
const { telemetry, config, logs } = setup(); | ||
await telemetry.notify(() => false); | ||
const [key] = Array.from(config.keys()); | ||
expect(key).not.to.be.undefined; | ||
expect(config.get(key)).to.be.false; | ||
expect(telemetry.enabled).to.be.false; | ||
expect(telemetry.isDisabled).to.be.true; | ||
const [log] = logs; | ||
expect(log).not.to.be.undefined; | ||
expect(logs.join('')).to.match(/disabled/); | ||
}); | ||
it('respects enable from notify', async () => { | ||
const { telemetry, config, logs } = setup(); | ||
await telemetry.notify(() => true); | ||
const [key] = Array.from(config.keys()); | ||
expect(key).not.to.be.undefined; | ||
expect(config.get(key)).to.be.true; | ||
expect(telemetry.enabled).to.be.true; | ||
expect(telemetry.isDisabled).to.be.false; | ||
const [log] = logs; | ||
expect(log).not.to.be.undefined; | ||
expect(logs.join('')).to.match(/enabled/); | ||
}); | ||
}); |