@@ -32,27 +32,23 @@ describe('ide_editCodeFile telemetry', function () {
32
32
let jsonUri1 : vscode . Uri | undefined
33
33
let jsonUri2 : vscode . Uri | undefined
34
34
let tsUri : vscode . Uri | undefined
35
+ let noiseUri1 ! : vscode . Uri
36
+ let noiseUri2 ! : vscode . Uri
35
37
36
38
beforeEach ( async function ( ) {
37
39
await testUtil . closeAllEditors ( )
38
-
39
- const jsonFile1 = workspaceUtils . tryGetAbsolutePath (
40
- vscode . workspace . workspaceFolders ?. [ 0 ] ,
41
- 'ts-plain-sam-app/tsconfig.json'
42
- )
43
- jsonUri1 = vscode . Uri . file ( jsonFile1 )
44
-
45
- const jsonFile2 = workspaceUtils . tryGetAbsolutePath (
46
- vscode . workspace . workspaceFolders ?. [ 0 ] ,
47
- 'ts-plain-sam-app/package.json'
48
- )
49
- jsonUri2 = vscode . Uri . file ( jsonFile2 )
50
-
51
- const tsFile = workspaceUtils . tryGetAbsolutePath (
52
- vscode . workspace . workspaceFolders ?. [ 0 ] ,
53
- 'ts-plain-sam-app/src/app.ts'
54
- )
55
- tsUri = vscode . Uri . file ( tsFile )
40
+ const ws = vscode . workspace . workspaceFolders ?. [ 0 ]
41
+
42
+ jsonUri1 = vscode . Uri . file ( workspaceUtils . tryGetAbsolutePath ( ws , 'ts-plain-sam-app/tsconfig.json' ) )
43
+ jsonUri2 = vscode . Uri . file ( workspaceUtils . tryGetAbsolutePath ( ws , 'ts-plain-sam-app/package.json' ) )
44
+ tsUri = vscode . Uri . file ( workspaceUtils . tryGetAbsolutePath ( ws , 'ts-plain-sam-app/src/app.ts' ) )
45
+ // Simulate ~/.vscode/argv.json which is emitted by vscode `onDidOpenTextDocument` event.
46
+ // filetypes.ts no longer listens to `onDidOpenTextDocument`, but this test protects against
47
+ // regressions.
48
+ noiseUri1 = vscode . Uri . file ( workspaceUtils . tryGetAbsolutePath ( ws , '.vscode/argv.json' ) )
49
+ await testUtil . toFile ( 'fake argv.json' , noiseUri1 )
50
+ noiseUri2 = vscode . Uri . file ( workspaceUtils . tryGetAbsolutePath ( ws , 'foo/bar/zub.git' ) )
51
+ await testUtil . toFile ( 'fake *.git file' , noiseUri2 )
56
52
} )
57
53
58
54
after ( async function ( ) {
@@ -67,6 +63,14 @@ describe('ide_editCodeFile telemetry', function () {
67
63
await vscode . commands . executeCommand ( 'vscode.open' , jsonUri1 )
68
64
// Different file, same extension (.json), thus `ide_editCodeFile` should be skipped/deduped.
69
65
await vscode . commands . executeCommand ( 'vscode.open' , jsonUri2 )
66
+
67
+ // Open some "noise" documents WITHOUT showing them in a text editor. This triggers
68
+ // `onDidOpenTextDocument` but not `onDidChangeActiveTextEditor`. This simulates typical
69
+ // vscode activity. Noise documents should NOT trigger `ide_editCodeFile` or any similar
70
+ // metric.
71
+ await vscode . workspace . openTextDocument ( noiseUri1 )
72
+ await vscode . workspace . openTextDocument ( noiseUri2 )
73
+
70
74
// Wait for metrics...
71
75
const r1 = await getMetrics ( 2 , 'ide_editCodeFile' )
72
76
const m1 = r1 ?. [ 0 ]
@@ -92,10 +96,12 @@ describe('ide_editCodeFile telemetry', function () {
92
96
93
97
describe ( 'file_editAwsFile telemetry' , function ( ) {
94
98
let awsConfigUri : vscode . Uri | undefined
99
+ let ssmJsonUri : vscode . Uri | undefined
95
100
let cfnUri : vscode . Uri | undefined
96
101
97
102
beforeEach ( async function ( ) {
98
103
await testUtil . closeAllEditors ( )
104
+ const ws = vscode . workspace . workspaceFolders ?. [ 0 ]
99
105
100
106
// Create a dummy file in ~/.aws on the system.
101
107
// Note: We consider _any_ file in ~/.aws to be an "AWS config" file,
@@ -104,11 +110,8 @@ describe('file_editAwsFile telemetry', function () {
104
110
awsConfigUri = vscode . Uri . file ( awsConfigFile )
105
111
await testUtil . toFile ( 'Test file from the aws-toolkit-vscode test suite.' , awsConfigFile )
106
112
107
- const cfnFile = workspaceUtils . tryGetAbsolutePath (
108
- vscode . workspace . workspaceFolders ?. [ 0 ] ,
109
- 'python3.7-plain-sam-app/template.yaml'
110
- )
111
- cfnUri = vscode . Uri . file ( cfnFile )
113
+ ssmJsonUri = vscode . Uri . file ( workspaceUtils . tryGetAbsolutePath ( ws , 'test.ssm.json' ) )
114
+ cfnUri = vscode . Uri . file ( workspaceUtils . tryGetAbsolutePath ( ws , 'python3.7-plain-sam-app/template.yaml' ) )
112
115
} )
113
116
114
117
after ( async function ( ) {
@@ -118,10 +121,7 @@ describe('file_editAwsFile telemetry', function () {
118
121
it ( 'emits when opened by user' , async function ( ) {
119
122
await vscode . commands . executeCommand ( 'vscode.open' , cfnUri )
120
123
await vscode . commands . executeCommand ( 'vscode.open' , awsConfigUri )
121
- await vscode . workspace . openTextDocument ( {
122
- content : 'test content for SSM JSON' ,
123
- language : 'ssm-json' ,
124
- } )
124
+ await vscode . commands . executeCommand ( 'vscode.open' , ssmJsonUri )
125
125
126
126
const r = await getMetrics ( 3 , 'file_editAwsFile' , 5000 )
127
127
0 commit comments