@@ -15,6 +15,7 @@ import {
15
15
loadDocument ,
16
16
loadFolder ,
17
17
log ,
18
+ logRed ,
18
19
logYellow ,
19
20
sampleWorkspaceUri ,
20
21
sleep ,
@@ -65,6 +66,7 @@ describe('Launch code spell extension', function () {
65
66
const docUri = getDocUri ( 'diagnostics.txt' ) ;
66
67
67
68
this . beforeAll ( async ( ) => {
69
+ await loadFolder ( getDocUri ( '.' ) ) ;
68
70
await activateExtension ( ) ;
69
71
} ) ;
70
72
@@ -105,42 +107,48 @@ describe('Launch code spell extension', function () {
105
107
} ) ;
106
108
} ) ;
107
109
108
- it ( 'Verifies that some spelling errors were found' , async ( ) => {
109
- logYellow ( 'Verifies that some spelling errors were found' ) ;
110
- await loadFolder ( getDocUri ( '.' ) ) ;
111
- const uri = getDocUri ( 'example.md' ) ;
112
- const config = getVscodeWorkspace ( ) . getConfiguration ( undefined , uri ) ;
113
- await config . update ( 'cSpell.diagnosticLevel' , 'Information' ) ;
114
- await config . update ( 'cSpell.useCustomDecorations' , false , 1 ) ;
115
- const docContextMaybe = await loadDocument ( uri ) ;
116
- await sleep ( 500 ) ;
117
- // Force a spell check by making an edit.
118
- const r = vscode . window . activeTextEditor ?. edit ( ( edit ) => edit . insert ( new vscode . Position ( 0 , 0 ) , '#' ) ) ;
119
- expect ( docContextMaybe ) . to . not . be . undefined ;
120
- const wait = waitForSpellComplete ( uri , 5000 ) ;
121
- await r ;
122
-
123
- const found = await wait ;
124
- log ( 'found %o' , found ) ;
125
-
126
- const diags = await getDiagsFromVsCode ( uri , 2000 ) ;
127
-
128
- if ( ! diags . length ) {
129
- log ( 'all diags: %o' , vscode . languages . getDiagnostics ( ) ) ;
130
- }
110
+ it (
111
+ 'Verifies that some spelling errors were found' ,
112
+ logError ( async ( ) => {
113
+ logYellow ( 'Verifies that some spelling errors were found' ) ;
114
+ await loadFolder ( getDocUri ( '.' ) ) ;
115
+ const uri = getDocUri ( 'example.md' ) ;
116
+ const config = getVscodeWorkspace ( ) . getConfiguration ( undefined , uri ) ;
117
+ await config . update ( 'cSpell.diagnosticLevel' , 'Information' , 3 ) ;
118
+ await config . update ( 'cSpell.useCustomDecorations' , false , 1 ) ;
119
+ const docContextMaybe = await loadDocument ( uri ) ;
120
+ await sleep ( 1000 ) ;
121
+ logYellow ( 'document loaded' ) ;
122
+ // Force a spell check by making an edit.
123
+ logYellow ( 'edit start' ) ;
124
+ const r = vscode . window . activeTextEditor ?. edit ( ( edit ) => edit . insert ( new vscode . Position ( 0 , 0 ) , '#' ) ) ;
125
+ expect ( docContextMaybe ) . to . not . be . undefined ;
126
+ const wait = waitForSpellComplete ( uri , 5000 ) ;
127
+ await r ;
128
+ logYellow ( 'edit finished' ) ;
131
129
132
- // await sleep(5 * 1000);
130
+ const found = await wait ;
131
+ log ( 'found %o' , found ) ;
133
132
134
- expect ( found ) . to . not . be . undefined ;
133
+ const diags = await getDiagsFromVsCode ( uri , 2000 ) ;
135
134
136
- const msgs = diags . map ( ( a ) => `C: ${ a . source } M: ${ a . message } ` ) . join ( '\n' ) ;
137
- log ( `Diag Messages: size( ${ diags . length } ) msg: \n ${ msgs } ` ) ;
138
- log ( 'diags: %o' , diags ) ;
135
+ if ( ! diags . length ) {
136
+ log ( 'all diags: %o' , vscode . languages . getDiagnostics ( ) ) ;
137
+ }
139
138
140
- // cspell:ignore spellling
141
- expect ( msgs ) . contains ( 'spellling' ) ;
142
- logYellow ( 'Done: Verifies that some spelling errors were found' ) ;
143
- } ) ;
139
+ // await sleep(5 * 1000);
140
+
141
+ expect ( found ) . to . not . be . undefined ;
142
+
143
+ const msgs = diags . map ( ( a ) => `C: ${ a . source } M: ${ a . message } ` ) . join ( '\n' ) ;
144
+ log ( `Diag Messages: size(${ diags . length } ) msg: \n${ msgs } ` ) ;
145
+ log ( 'diags: %o' , diags ) ;
146
+
147
+ // cspell:ignore spellling
148
+ expect ( msgs ) . contains ( 'spellling' ) ;
149
+ logYellow ( 'Done: Verifies that some spelling errors were found' ) ;
150
+ } ) ,
151
+ ) ;
144
152
145
153
it ( 'register a config and check doc' , async ( ) => {
146
154
const ext = await activateExtension ( ) ;
@@ -169,6 +177,17 @@ describe('Launch code spell extension', function () {
169
177
} ) ;
170
178
} ) ;
171
179
180
+ function logError ( fn : ( ) => Promise < void > ) : ( ) => Promise < void > {
181
+ return async ( ) => {
182
+ try {
183
+ await fn ( ) ;
184
+ } catch ( e ) {
185
+ logRed ( 'Error: %o' , e ) ;
186
+ throw e ;
187
+ }
188
+ } ;
189
+ }
190
+
172
191
function streamOnSpellCheckDocumentNotification ( cSpellClient : CSpellClient ) : Stream < OnSpellCheckDocumentStep , undefined > {
173
192
return stream < OnSpellCheckDocumentStep , undefined > ( ( emitter ) => {
174
193
const d = cSpellClient . onSpellCheckDocumentNotification ( emitter . value ) ;
0 commit comments