Skip to content

Commit eb9795e

Browse files
committed
test: fix integration test runs
1 parent 352da92 commit eb9795e

File tree

2 files changed

+57
-32
lines changed

2 files changed

+57
-32
lines changed

packages/_integrationTests/src/extension.test.mts

Lines changed: 51 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
loadDocument,
1616
loadFolder,
1717
log,
18+
logRed,
1819
logYellow,
1920
sampleWorkspaceUri,
2021
sleep,
@@ -65,6 +66,7 @@ describe('Launch code spell extension', function () {
6566
const docUri = getDocUri('diagnostics.txt');
6667

6768
this.beforeAll(async () => {
69+
await loadFolder(getDocUri('.'));
6870
await activateExtension();
6971
});
7072

@@ -105,42 +107,48 @@ describe('Launch code spell extension', function () {
105107
});
106108
});
107109

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');
131129

132-
// await sleep(5 * 1000);
130+
const found = await wait;
131+
log('found %o', found);
133132

134-
expect(found).to.not.be.undefined;
133+
const diags = await getDiagsFromVsCode(uri, 2000);
135134

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+
}
139138

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+
);
144152

145153
it('register a config and check doc', async () => {
146154
const ext = await activateExtension();
@@ -169,6 +177,17 @@ describe('Launch code spell extension', function () {
169177
});
170178
});
171179

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+
172191
function streamOnSpellCheckDocumentNotification(cSpellClient: CSpellClient): Stream<OnSpellCheckDocumentStep, undefined> {
173192
return stream<OnSpellCheckDocumentStep, undefined>((emitter) => {
174193
const d = cSpellClient.onSpellCheckDocumentNotification(emitter.value);

packages/_integrationTests/src/helper.mts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,9 @@ export function logYellow(...params: Parameters<typeof console.log>): void {
111111
if (!message) return log('');
112112
log(chalk.yellow(message), ...rest);
113113
}
114+
115+
export function logRed(...params: Parameters<typeof console.log>): void {
116+
const [message, ...rest] = params;
117+
if (!message) return log('');
118+
log(chalk.red(message), ...rest);
119+
}

0 commit comments

Comments
 (0)