Skip to content

Commit

Permalink
VSCode test
Browse files Browse the repository at this point in the history
  • Loading branch information
wkillerud committed Dec 16, 2024
1 parent 0eb04d4 commit c9d9686
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 0 deletions.
3 changes: 3 additions & 0 deletions extension/test/electron/hover/fixtures/other.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/// Docstring.
/// @type String
$from-other: 'hello';
9 changes: 9 additions & 0 deletions extension/test/electron/hover/fixtures/styles.sass
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@use "sass:string"
@use "other"

$_id: string.unique-id()
$_prefix: other.$from-other

.card
.body:has(:not(.stuff))
padding: 4px
69 changes: 69 additions & 0 deletions extension/test/electron/hover/hover.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
const assert = require('node:assert');
const path = require('node:path');
const vscode = require('vscode');
const { showFile, sleepCI } = require('../util');

const stylesUri = vscode.Uri.file(
path.resolve(__dirname, 'fixtures', 'styles.sass')
);

before(async () => {
await showFile(stylesUri);
await sleepCI();
});

after(async () => {
await vscode.commands.executeCommand('workbench.action.closeAllEditors');
});

/**
* @param {import('vscode').Hover[]} hover
* @returns {string}
*/
function getHoverContents(hover) {
return hover
.flatMap((item) => {
return item.contents.map((content) =>
typeof content === 'string' ? content : content.value
);
})
.join('\n');
}

/**
* @param {import('vscode').Uri} documentUri
* @param {import('vscode').Position} position
* @returns {Promise<import('vscode').Hover[]>}
*/
async function hover(documentUri, position) {
const result = await vscode.commands.executeCommand(
'vscode.executeHoverProvider',
documentUri,
position
);
return result;
}

test('gets hover information from the same document', async () => {
const result = await hover(stylesUri, new vscode.Position(7, 10));

assert.match(
getHoverContents(result),
/\.card \.body:has\(:not\(\.stuff\)\)/
);
});

test('gets hover information from the workspace', async () => {
const result = await hover(stylesUri, new vscode.Position(4, 19));

assert.match(getHoverContents(result), /Docstring/);
});

test('gets hover information for Sass built-in', async () => {
const result = await hover(stylesUri, new vscode.Position(3, 14));

assert.match(
getHoverContents(result),
/Returns a randomly-generated unquoted string/
);
});
25 changes: 25 additions & 0 deletions extension/test/electron/hover/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const path = require('node:path');
const fs = require('node:fs/promises');
const vscode = require('vscode');
const { runMocha } = require('../mocha');

/**
* @returns {Promise<void>}
*/
async function run() {
const filePaths = [];

const dir = await fs.readdir(__dirname, { withFileTypes: true });
for (let entry of dir) {
if (entry.isFile() && entry.name.endsWith('test.js')) {
filePaths.push(path.join(entry.parentPath, entry.name));
}
}

await runMocha(
filePaths,
vscode.Uri.file(path.resolve(__dirname, 'fixtures', 'styles.sass'))
);
}

module.exports = { run };

0 comments on commit c9d9686

Please sign in to comment.