1
- import type { Extension } from 'vscode' ;
1
+ import type { Extension , Uri } from 'vscode' ;
2
2
3
- import { ConfigurationTarget , type Uri , commands , workspace } from 'vscode' ;
3
+ import { ConfigurationTarget , commands , workspace } from 'vscode' ;
4
4
5
5
import {
6
6
activateHarper ,
@@ -12,7 +12,10 @@ import {
12
12
openFile ,
13
13
openUntitled ,
14
14
setTextDocumentLanguage ,
15
- sleep ,
15
+ waitForHarperToActivate ,
16
+ waitForUpdatesFromConfigChange ,
17
+ waitForUpdatesFromDeletedFile ,
18
+ waitForUpdatesFromOpenedFile ,
16
19
} from './helper' ;
17
20
18
21
describe ( 'Integration >' , ( ) => {
@@ -22,10 +25,8 @@ describe('Integration >', () => {
22
25
beforeAll ( async ( ) => {
23
26
await closeAll ( ) ;
24
27
harper = await activateHarper ( ) ;
25
- // Open test file so diagnostics can occur
26
28
markdownUri = await openFile ( 'integration.md' ) ;
27
- // Wait for `harper-ls` to start
28
- await sleep ( 500 ) ;
29
+ await waitForHarperToActivate ( ) ;
29
30
} ) ;
30
31
31
32
it ( 'runs' , ( ) => {
@@ -44,15 +45,17 @@ describe('Integration >', () => {
44
45
message : 'Did you mean to spell “errorz” this way?' ,
45
46
range : createRange ( 2 , 26 , 2 , 32 ) ,
46
47
} ,
48
+ {
49
+ message : 'Did you mean to spell “realise” this way?' ,
50
+ range : createRange ( 4 , 26 , 4 , 33 ) ,
51
+ } ,
47
52
) ,
48
53
) ;
49
54
} ) ;
50
55
51
56
it ( 'gives correct diagnostics for untitled' , async ( ) => {
52
57
const untitledUri = await openUntitled ( 'Errorz' ) ;
53
-
54
- // Wait for `harper-ls` to send diagnostics
55
- await sleep ( 500 ) ;
58
+ await waitForUpdatesFromOpenedFile ( ) ;
56
59
57
60
compareActualVsExpectedDiagnostics (
58
61
getActualDiagnostics ( untitledUri ) ,
@@ -68,7 +71,7 @@ describe('Integration >', () => {
68
71
await setTextDocumentLanguage ( untitledUri , 'plaintext' ) ;
69
72
70
73
// Wait for `harper-ls` to send diagnostics
71
- await sleep ( 500 ) ;
74
+ await waitForUpdatesFromConfigChange ( ) ;
72
75
73
76
compareActualVsExpectedDiagnostics (
74
77
getActualDiagnostics ( untitledUri ) ,
@@ -87,7 +90,7 @@ describe('Integration >', () => {
87
90
await setTextDocumentLanguage ( untitledUri , 'shellscript' ) ;
88
91
89
92
// Wait for `harper-ls` to send diagnostics
90
- await sleep ( 500 ) ;
93
+ await waitForUpdatesFromConfigChange ( ) ;
91
94
92
95
compareActualVsExpectedDiagnostics (
93
96
getActualDiagnostics ( untitledUri ) ,
@@ -101,29 +104,56 @@ describe('Integration >', () => {
101
104
it ( 'updates diagnostics on configuration change' , async ( ) => {
102
105
const config = workspace . getConfiguration ( 'harper.linters' ) ;
103
106
await config . update ( 'RepeatedWords' , false , ConfigurationTarget . Workspace ) ;
104
- // Wait for `harper-ls` to update diagnostics
105
- await sleep ( 300 ) ;
107
+ await waitForUpdatesFromConfigChange ( ) ;
106
108
107
109
compareActualVsExpectedDiagnostics (
108
110
getActualDiagnostics ( markdownUri ) ,
109
- createExpectedDiagnostics ( {
110
- message : 'Did you mean to spell “errorz” this way?' ,
111
- range : createRange ( 2 , 26 , 2 , 32 ) ,
112
- } ) ,
111
+ createExpectedDiagnostics (
112
+ {
113
+ message : 'Did you mean to spell “errorz” this way?' ,
114
+ range : createRange ( 2 , 26 , 2 , 32 ) ,
115
+ } ,
116
+ {
117
+ message : 'Did you mean to spell “realise” this way?' ,
118
+ range : createRange ( 4 , 26 , 4 , 33 ) ,
119
+ } ,
120
+ ) ,
113
121
) ;
114
122
115
123
// Set config back to default value
116
124
await config . update ( 'RepeatedWords' , true , ConfigurationTarget . Workspace ) ;
117
125
} ) ;
118
126
127
+ it ( 'accepts British spellings when dialect is set to British' , async ( ) => {
128
+ const config = workspace . getConfiguration ( 'harper' ) ;
129
+ await config . update ( 'dialect' , 'British' , ConfigurationTarget . Workspace ) ;
130
+ await waitForUpdatesFromConfigChange ( ) ;
131
+
132
+ compareActualVsExpectedDiagnostics (
133
+ getActualDiagnostics ( markdownUri ) ,
134
+ createExpectedDiagnostics (
135
+ {
136
+ message : 'Did you mean to repeat this word?' ,
137
+ range : createRange ( 2 , 39 , 2 , 48 ) ,
138
+ } ,
139
+ {
140
+ message : 'Did you mean to spell “errorz” this way?' ,
141
+ range : createRange ( 2 , 26 , 2 , 32 ) ,
142
+ } ,
143
+ ) ,
144
+ ) ;
145
+
146
+ // Set config back to default value
147
+ await config . update ( 'dialect' , 'American' , ConfigurationTarget . Workspace ) ;
148
+ } ) ;
149
+
119
150
it ( 'updates diagnostics when files are deleted' , async ( ) => {
120
151
const markdownContent = await workspace . fs . readFile ( markdownUri ) ;
121
152
122
- // Delete file through VSCode
153
+ // Delete file through VS Code
123
154
await commands . executeCommand ( 'workbench.files.action.showActiveFileInExplorer' ) ;
124
155
await commands . executeCommand ( 'deleteFile' ) ;
125
- // Wait for `harper-ls` to update diagnostics
126
- await sleep ( 450 ) ;
156
+ await waitForUpdatesFromDeletedFile ( ) ;
127
157
128
158
compareActualVsExpectedDiagnostics (
129
159
getActualDiagnostics ( markdownUri ) ,
@@ -133,13 +163,11 @@ describe('Integration >', () => {
133
163
// Restore and reopen deleted file
134
164
await workspace . fs . writeFile ( markdownUri , markdownContent ) ;
135
165
await openFile ( 'integration.md' ) ;
136
- // Wait for `harper-ls` to update diagnostics
137
- await sleep ( 75 ) ;
166
+ await waitForUpdatesFromOpenedFile ( ) ;
138
167
139
168
// Delete file directly
140
169
await workspace . fs . delete ( markdownUri ) ;
141
- // Wait for `harper-ls` to update diagnostics
142
- await sleep ( 450 ) ;
170
+ await waitForUpdatesFromDeletedFile ( ) ;
143
171
144
172
compareActualVsExpectedDiagnostics (
145
173
getActualDiagnostics ( markdownUri ) ,
0 commit comments