55'use strict' ;
66
77import * as assert from 'assert' ;
8+ import * as path from 'path' ;
9+ import * as os from 'os' ;
10+ import * as fs from 'fs' ;
811import { TPromise } from 'vs/base/common/winjs.base' ;
912import { resolveWorkbenchCommonProperties } from 'vs/platform/telemetry/node/workbenchCommonProperties' ;
1013import { StorageService , InMemoryLocalStorage } from 'vs/platform/storage/common/storageService' ;
1114import { TestWorkspace } from 'vs/platform/workspace/test/common/testWorkspace' ;
15+ import { getRandomTestPath } from 'vs/workbench/test/workbenchTestServices' ;
16+ import { del } from 'vs/base/node/extfs' ;
17+ import { mkdirp } from 'vs/base/node/pfs' ;
1218
1319suite ( 'Telemetry - common properties' , function ( ) {
20+ const parentDir = getRandomTestPath ( os . tmpdir ( ) , 'vsctests' , 'telemetryservice' ) ;
21+ const installSource = path . join ( parentDir , 'installSource' ) ;
1422
1523 const commit : string = void 0 ;
1624 const version : string = void 0 ;
17- const source : string = void 0 ;
1825 let storageService : StorageService ;
1926
2027 setup ( ( ) => {
2128 storageService = new StorageService ( new InMemoryLocalStorage ( ) , null , TestWorkspace . id ) ;
2229 } ) ;
2330
24- test ( 'default' , function ( ) {
25-
26- return resolveWorkbenchCommonProperties ( storageService , commit , version , source , 'someMachineId' ) . then ( props => {
27-
28- assert . ok ( 'commitHash' in props ) ;
29- assert . ok ( 'sessionID' in props ) ;
30- assert . ok ( 'timestamp' in props ) ;
31- assert . ok ( 'common.platform' in props ) ;
32- assert . ok ( 'common.nodePlatform' in props ) ;
33- assert . ok ( 'common.nodeArch' in props ) ;
34- assert . ok ( 'common.timesincesessionstart' in props ) ;
35- assert . ok ( 'common.sequence' in props ) ;
36-
37- // assert.ok('common.version.shell' in first.data); // only when running on electron
38- // assert.ok('common.version.renderer' in first.data);
39- assert . ok ( 'common.osVersion' in props , 'osVersion' ) ;
40- assert . ok ( 'version' in props ) ;
41- assert . ok ( 'common.source' in props ) ;
42-
43- assert . ok ( 'common.firstSessionDate' in props , 'firstSessionDate' ) ;
44- assert . ok ( 'common.lastSessionDate' in props , 'lastSessionDate' ) ; // conditional, see below, 'lastSessionDate'ow
45- assert . ok ( 'common.isNewSession' in props , 'isNewSession' ) ;
31+ teardown ( done => {
32+ del ( parentDir , os . tmpdir ( ) , done ) ;
33+ } ) ;
4634
47- // machine id et al
48- assert . ok ( 'common.instanceId' in props , 'instanceId' ) ;
49- assert . ok ( 'common.machineId' in props , 'machineId' ) ;
35+ test ( 'pasero default' , function ( ) {
36+ return mkdirp ( parentDir ) . then ( ( ) => {
37+ fs . writeFileSync ( installSource , 'my.install.source' ) ;
38+
39+ return resolveWorkbenchCommonProperties ( storageService , commit , version , 'someMachineId' , installSource ) . then ( props => {
40+ assert . ok ( 'commitHash' in props ) ;
41+ assert . ok ( 'sessionID' in props ) ;
42+ assert . ok ( 'timestamp' in props ) ;
43+ assert . ok ( 'common.platform' in props ) ;
44+ assert . ok ( 'common.nodePlatform' in props ) ;
45+ assert . ok ( 'common.nodeArch' in props ) ;
46+ assert . ok ( 'common.timesincesessionstart' in props ) ;
47+ assert . ok ( 'common.sequence' in props ) ;
48+
49+ // assert.ok('common.version.shell' in first.data); // only when running on electron
50+ // assert.ok('common.version.renderer' in first.data);
51+ assert . ok ( 'common.osVersion' in props , 'osVersion' ) ;
52+ assert . ok ( 'version' in props ) ;
53+ assert . equal ( props [ 'common.source' ] , 'my.install.source' ) ;
54+
55+ assert . ok ( 'common.firstSessionDate' in props , 'firstSessionDate' ) ;
56+ assert . ok ( 'common.lastSessionDate' in props , 'lastSessionDate' ) ; // conditional, see below, 'lastSessionDate'ow
57+ assert . ok ( 'common.isNewSession' in props , 'isNewSession' ) ;
58+
59+ // machine id et al
60+ assert . ok ( 'common.instanceId' in props , 'instanceId' ) ;
61+ assert . ok ( 'common.machineId' in props , 'machineId' ) ;
5062
63+ } ) ;
5164 } ) ;
5265 } ) ;
5366
5467 test ( 'lastSessionDate when aviablale' , function ( ) {
5568
5669 storageService . store ( 'telemetry.lastSessionDate' , new Date ( ) . toUTCString ( ) ) ;
5770
58- return resolveWorkbenchCommonProperties ( storageService , commit , version , source , 'someMachineId' ) . then ( props => {
71+ return resolveWorkbenchCommonProperties ( storageService , commit , version , 'someMachineId' , installSource ) . then ( props => {
5972
6073 assert . ok ( 'common.lastSessionDate' in props ) ; // conditional, see below
6174 assert . ok ( 'common.isNewSession' in props ) ;
@@ -64,7 +77,7 @@ suite('Telemetry - common properties', function () {
6477 } ) ;
6578
6679 test ( 'values chance on ask' , function ( ) {
67- return resolveWorkbenchCommonProperties ( storageService , commit , version , source , 'someMachineId' ) . then ( props => {
80+ return resolveWorkbenchCommonProperties ( storageService , commit , version , 'someMachineId' , installSource ) . then ( props => {
6881 let value1 = props [ 'common.sequence' ] ;
6982 let value2 = props [ 'common.sequence' ] ;
7083 assert . ok ( value1 !== value2 , 'seq' ) ;
0 commit comments