-
Notifications
You must be signed in to change notification settings - Fork 794
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(cli): [STENCIL-12] Adding Telemetry and CLI features. #2964
Changes from 1 commit
f1deae7
628c0c7
d52a7d1
f524372
d889830
c635329
739e62c
cdf1879
dbbb0cb
aa5bb85
5ca6854
3d466ed
871ac40
60865ea
bce8319
6448a29
250f28c
66c8019
c251962
45f5a11
2e01743
b8986c7
f9644b8
063cc1c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import { initializeStencilCLIConfig } from '../../state/stencil-cli-config'; | ||
import { getStencilCLIConfig, initializeStencilCLIConfig } from '../../state/stencil-cli-config'; | ||
import * as telemetry from '../telemetry'; | ||
import * as shouldTrack from '../shouldTrack'; | ||
import { createSystem } from '../../../compiler/sys/stencil-sys'; | ||
|
@@ -76,3 +76,132 @@ describe('checkTelemetry', () => { | |
expect(await telemetry.checkTelemetry()).toBe(true); | ||
}); | ||
}); | ||
|
||
describe('hasAppTarget', () => { | ||
|
||
beforeEach(() => { | ||
getStencilCLIConfig()?.resetInstance(); | ||
|
||
initializeStencilCLIConfig({ | ||
sys: createSystem(), | ||
logger: mockLogger(), | ||
flags: { ci: false }, | ||
validatedConfig: { config: { outputTargets: [] } } as LoadConfigResults, | ||
args: [], | ||
}); | ||
}); | ||
|
||
|
||
it('Result is correct when outputTargets are empty', () => { | ||
getStencilCLIConfig().validatedConfig = { config: { outputTargets: [] } } as LoadConfigResults | ||
expect(telemetry.hasAppTarget()).toBe(false) | ||
}); | ||
|
||
it('Result is correct when outputTargets contains www with no baseUrl or serviceWorker', () => { | ||
getStencilCLIConfig().validatedConfig = { config: { outputTargets: [{ type: "www" }] } } as LoadConfigResults; | ||
expect(telemetry.hasAppTarget()).toBe(false) | ||
}); | ||
|
||
it('Result is correct when outputTargets contains www with default baseUrl value', () => { | ||
getStencilCLIConfig().validatedConfig = { config: { outputTargets: [{ type: "www", baseUrl: "/" }] } } as LoadConfigResults; | ||
expect(telemetry.hasAppTarget()).toBe(false) | ||
}); | ||
|
||
it('Result is correct when outputTargets contains www with serviceWorker', () => { | ||
getStencilCLIConfig().validatedConfig = { config: { outputTargets: [{ type: "www", serviceWorker: { swDest: "./tmp" }, }] } } as LoadConfigResults | ||
expect(telemetry.hasAppTarget()).toBe(true) | ||
}); | ||
|
||
it('Result is correct when outputTargets contains www with serviceWorker', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this test name needs to be updated, there's no service worker field set in this test |
||
getStencilCLIConfig().validatedConfig = { config: { outputTargets: [{ type: "www", baseUrl: "https://example.com" }] } } as LoadConfigResults | ||
expect(telemetry.hasAppTarget()).toBe(true) | ||
}); | ||
|
||
it('Result is correct when outputTargets contains www with serviceWorker', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this test name needs to be updated, it mimics the two previous test names |
||
getStencilCLIConfig().validatedConfig = { config: { outputTargets: [{ type: "www", baseUrl: "https://example.com", serviceWorker: { swDest: "./tmp" } }] } } as LoadConfigResults | ||
expect(telemetry.hasAppTarget()).toBe(true) | ||
}); | ||
}); | ||
|
||
describe('hasAppTarget', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This outer level describe matches the one on line 80. Did you mean 'prepareData'? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did! |
||
|
||
beforeEach(() => { | ||
getStencilCLIConfig()?.resetInstance(); | ||
|
||
initializeStencilCLIConfig({ | ||
sys: createSystem(), | ||
logger: mockLogger(), | ||
flags: { ci: false }, | ||
validatedConfig: { config: { outputTargets: [] } } as LoadConfigResults, | ||
args: [], | ||
}); | ||
}); | ||
|
||
it('provides an object', async () => { | ||
const data = await telemetry.prepareData(1000); | ||
expect(data).toEqual({ | ||
"arguments": undefined, | ||
"build": "unknown", | ||
"component_count": undefined, | ||
"cpu_model": "", | ||
"duration_ms": 1000, | ||
"has_app_pwa_config": false, | ||
"os_name": "", | ||
"os_version": "", | ||
"packages": [], | ||
"rollup": "unknown", | ||
"stencil": "unknown", | ||
"system": "in-memory __VERSION:STENCIL__", | ||
"targets": [], | ||
"task": undefined, | ||
"typescript": "unknown", | ||
"yarn": false | ||
}) | ||
}) | ||
|
||
it('updates when there is a PWA config', async () => { | ||
getStencilCLIConfig().validatedConfig = { config: { outputTargets: [{ type: "www", baseUrl: "https://example.com", serviceWorker: {swDest: "./tmp" } }] } } as LoadConfigResults | ||
const data = await telemetry.prepareData(1000); | ||
expect(data).toEqual({ | ||
"arguments": undefined, | ||
"build": "unknown", | ||
"component_count": undefined, | ||
"cpu_model": "", | ||
"duration_ms": 1000, | ||
"has_app_pwa_config": true, | ||
"os_name": "", | ||
"os_version": "", | ||
"packages": [], | ||
"rollup": "unknown", | ||
"stencil": "unknown", | ||
"system": "in-memory __VERSION:STENCIL__", | ||
"targets": ["www"], | ||
"task": undefined, | ||
"typescript": "unknown", | ||
"yarn": false | ||
}) | ||
}) | ||
|
||
it('updates when there is a component count passed in', async () => { | ||
getStencilCLIConfig().validatedConfig = { config: { outputTargets: [{ type: "www", baseUrl: "https://example.com", serviceWorker: {swDest: "./tmp" } }] } } as LoadConfigResults | ||
const data = await telemetry.prepareData(1000, 12); | ||
expect(data).toEqual({ | ||
"arguments": undefined, | ||
"build": "unknown", | ||
"component_count": 12, | ||
"cpu_model": "", | ||
"duration_ms": 1000, | ||
"has_app_pwa_config": true, | ||
"os_name": "", | ||
"os_version": "", | ||
"packages": [], | ||
"rollup": "unknown", | ||
"stencil": "unknown", | ||
"system": "in-memory __VERSION:STENCIL__", | ||
"targets": ["www"], | ||
"task": undefined, | ||
"typescript": "unknown", | ||
"yarn": false | ||
}) | ||
}) | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this always returns an array, and don't think we need the
|| []
here