@@ -2,7 +2,7 @@ import type * as d from '../../../declarations';
22import * as telemetry from '../telemetry' ;
33import * as shouldTrack from '../shouldTrack' ;
44import { createSystem } from '../../../compiler/sys/stencil-sys' ;
5- import { mockLogger , mockValidatedConfig } from '@stencil/core/testing' ;
5+ import { mockValidatedConfig } from '@stencil/core/testing' ;
66import * as coreCompiler from '@stencil/core/compiler' ;
77import { anonymizeConfigForTelemetry } from '../telemetry' ;
88import { DIST , DIST_CUSTOM_ELEMENTS , DIST_HYDRATE_SCRIPT , WWW } from '../../../compiler/output-targets/output-utils' ;
@@ -148,25 +148,21 @@ describe('prepareData', () => {
148148 let sys : d . CompilerSystem ;
149149
150150 beforeEach ( ( ) => {
151- config = {
152- outputTargets : [ ] ,
153- flags : createConfigFlags ( ) ,
154- logger : mockLogger ( ) ,
155- } ;
156-
157- sys = createSystem ( ) ;
151+ config = mockValidatedConfig ( ) ;
152+ sys = config . sys ;
153+ // set static name + versions, otherwise tests will pull in the dev build's data (which changes per build)
154+ sys . name = 'in-memory' ;
155+ sys . version = '__VERSION:STENCIL__' ;
158156 } ) ;
159157
160- it ( 'provides an object' , async ( ) => {
158+ it ( 'prepares an object to send to ionic ' , async ( ) => {
161159 const data = await telemetry . prepareData ( coreCompiler , config , sys , 1000 ) ;
162160 expect ( data ) . toEqual ( {
163161 arguments : [ ] ,
164162 build : coreCompiler . buildId ,
165163 component_count : undefined ,
166- config : {
167- flags : createConfigFlags ( ) ,
168- outputTargets : [ ] ,
169- } ,
164+ // the configuration generation is tested elsewhere, just verify we're sending something under this flag
165+ config : expect . any ( Object ) ,
170166 cpu_model : '' ,
171167 duration_ms : 1000 ,
172168 has_app_pwa_config : false ,
@@ -185,101 +181,39 @@ describe('prepareData', () => {
185181 } ) ;
186182 } ) ;
187183
188- it ( 'updates when there is a PWA config' , async ( ) => {
189- const config : d . ValidatedConfig = {
190- flags : createConfigFlags ( ) ,
191- logger : mockLogger ( ) ,
192- outputTargets : [ { type : 'www' , baseUrl : 'https://example.com' , serviceWorker : { swDest : './tmp' } } ] ,
193- } ;
184+ describe ( 'has_app_pwa_config property' , ( ) => {
185+ it ( 'sets `has_app_pwa_config` to true when there is a service worker' , async ( ) => {
186+ const config = mockValidatedConfig ( {
187+ outputTargets : [ { type : 'www' , baseUrl : 'https://example.com' } ] ,
188+ } ) ;
194189
195- const data = await telemetry . prepareData ( coreCompiler , config , sys , 1000 ) ;
190+ const data = await telemetry . prepareData ( coreCompiler , config , sys , 1000 ) ;
196191
197- expect ( data ) . toEqual ( {
198- arguments : [ ] ,
199- build : coreCompiler . buildId ,
200- component_count : undefined ,
201- config : {
202- flags : {
203- args : [ ] ,
204- knownArgs : [ ] ,
205- task : null ,
206- unknownArgs : [ ] ,
207- } ,
208- outputTargets : [
209- {
210- baseUrl : 'omitted' ,
211- serviceWorker : {
212- swDest : 'omitted' ,
213- } ,
214- type : 'www' ,
215- } ,
216- ] ,
217- } ,
218- cpu_model : '' ,
219- duration_ms : 1000 ,
220- has_app_pwa_config : true ,
221- os_name : '' ,
222- os_version : '' ,
223- packages : [ ] ,
224- packages_no_versions : [ ] ,
225- rollup : coreCompiler . versions . rollup ,
226- stencil : coreCompiler . versions . stencil ,
227- system : 'in-memory __VERSION:STENCIL__' ,
228- system_major : 'in-memory __VERSION:STENCIL__' ,
229- targets : [ 'www' ] ,
230- task : null ,
231- typescript : coreCompiler . versions . typescript ,
232- yarn : false ,
192+ expect ( data . has_app_pwa_config ) . toBe ( true ) ;
233193 } ) ;
234- } ) ;
235194
236- it ( 'updates when there is a component count passed in' , async ( ) => {
237- const config : d . ValidatedConfig = {
238- flags : createConfigFlags ( ) ,
239- logger : mockLogger ( ) ,
240- outputTargets : [ { type : 'www' , baseUrl : 'https://example.com' , serviceWorker : { swDest : './tmp' } } ] ,
241- } ;
195+ it ( "sets `has_app_pwa_config` to true for a non '/' baseUrl" , async ( ) => {
196+ const config = mockValidatedConfig ( {
197+ outputTargets : [ { type : 'www' , serviceWorker : { swDest : './tmp' } } ] ,
198+ } ) ;
242199
243- const data = await telemetry . prepareData ( coreCompiler , config , sys , 1000 , 12 ) ;
200+ const data = await telemetry . prepareData ( coreCompiler , config , sys , 1000 ) ;
244201
245- expect ( data ) . toEqual ( {
246- arguments : [ ] ,
247- build : coreCompiler . buildId ,
248- component_count : 12 ,
249- config : {
250- flags : {
251- args : [ ] ,
252- knownArgs : [ ] ,
253- task : null ,
254- unknownArgs : [ ] ,
255- } ,
256- outputTargets : [
257- {
258- baseUrl : 'omitted' ,
259- serviceWorker : {
260- swDest : 'omitted' ,
261- } ,
262- type : WWW ,
263- } ,
264- ] ,
265- } ,
266- cpu_model : '' ,
267- duration_ms : 1000 ,
268- has_app_pwa_config : true ,
269- os_name : '' ,
270- os_version : '' ,
271- packages : [ ] ,
272- packages_no_versions : [ ] ,
273- rollup : coreCompiler . versions . rollup ,
274- stencil : coreCompiler . versions . stencil ,
275- system : 'in-memory __VERSION:STENCIL__' ,
276- system_major : 'in-memory __VERSION:STENCIL__' ,
277- targets : [ 'www' ] ,
278- task : null ,
279- typescript : coreCompiler . versions . typescript ,
280- yarn : false ,
202+ expect ( data . has_app_pwa_config ) . toBe ( true ) ;
281203 } ) ;
282204 } ) ;
205+
206+ it ( 'sends a component count when one is provided' , async ( ) => {
207+ const COMPONENT_COUNT = 12 ;
208+
209+ const config = mockValidatedConfig ( {
210+ outputTargets : [ { type : 'www' } ] ,
211+ } ) ;
212+
213+ const data = await telemetry . prepareData ( coreCompiler , config , sys , 1000 , COMPONENT_COUNT ) ;
214+
215+ expect ( data . component_count ) . toEqual ( COMPONENT_COUNT ) ;
216+ } ) ;
283217} ) ;
284218
285219describe ( 'anonymizeConfigForTelemetry' , ( ) => {
0 commit comments