Skip to content

Commit

Permalink
test: Add test for #3543 (#3544)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason3S authored Aug 18, 2024
1 parent 23575b2 commit 9e68828
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
43 changes: 41 additions & 2 deletions packages/_integrationTests/src/extension.test.mts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import { createRequire } from 'node:module';
import { expect } from 'chai';
import type { Stream } from 'kefir';
import { stream } from 'kefir';
import { type Diagnostic, type languages as vscodeLanguages, type Position, type Uri, type window as vscodeWindow } from 'vscode';
import type { Diagnostic, languages as vscodeLanguages, Position, Uri, window as vscodeWindow } from 'vscode';

import type { CSpellClient, ExtensionApi, OnSpellCheckDocumentStep } from './ExtensionApi.mjs';
import {
activateExtension,
getDocPath,
getDocUri,
getVSCodeCommands,
getVscodeWorkspace,
loadDocument,
loadFolder,
Expand Down Expand Up @@ -118,7 +119,6 @@ describe('Launch code spell extension', function () {
'Verifies that some spelling errors were found',
logError(async () => {
logYellow('Verifies that some spelling errors were found');
await loadFolder(getDocUri('.'));
const uri = getDocUri('example.md');
const config = getVscodeWorkspace().getConfiguration(undefined, uri);
await config.update('cSpell.diagnosticLevel', 'Information', 3);
Expand Down Expand Up @@ -175,6 +175,45 @@ describe('Launch code spell extension', function () {
expect(result.issues).to.be.empty;
});

it('creates a new file with some spelling errors.', async () => {
logYellow('Verifies that some spelling errors were found in a new file');
const uri = vscode.Uri.parse('untitled:Untitled-1');
const config = getVscodeWorkspace().getConfiguration(undefined, getDocUri('example.md'));
await config.update('cSpell.diagnosticLevel', 'Information', 3);
await config.update('cSpell.useCustomDecorations', false, 1);
logYellow('Create new untitled file');
await getVSCodeCommands().executeCommand('workbench.action.files.newUntitledFile');
await sleep(1000);
logYellow('Created new untitled file');

logYellow('edit start');
const r = vscode.window.activeTextEditor?.edit((edit) =>
edit.insert(new vscode.Position(0, 0), 'This document has spellling errors.'),
);
const wait = waitForSpellComplete(uri, 5000);
await r;
logYellow('edit finished');

const found = await wait;
log('found %o', found);

const diags = await getDiagsFromVsCode(uri, 2000);

if (!diags.length) {
log('all diags: %o', vscode.languages.getDiagnostics());
}

expect(found).to.not.be.undefined;

const msgs = diags.map((a) => `C: ${a.source} M: ${a.message}`).join('\n');
log(`Diag Messages: size(${diags.length}) msg: \n${msgs}`);
log('diags: %o', diags);

// cspell:ignore spellling
expect(msgs).contains('spellling');
logYellow('Done: Verifies that some spelling errors were found in a new file');
});

it('Wait a bit', async () => {
// This is useful for debugging and you want to see the VS Code UI.
// Set `secondsToWait` to 30 or more.
Expand Down
4 changes: 4 additions & 0 deletions packages/_integrationTests/src/helper.mts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ export async function loadDocument(docUri: Uri): Promise<DocumentContext | undef
}
}

export function getVSCodeCommands(): typeof vscode.commands {
return vscode.commands;
}

export async function loadFolder(folderUri: Uri): Promise<void> {
return await vscode.commands.executeCommand('vscode.openFolder', folderUri, { forceNewWindow: false, forceReuseWindow: true });
}
Expand Down

0 comments on commit 9e68828

Please sign in to comment.