Skip to content

Commit c9d9686

Browse files
committed
VSCode test
1 parent 0eb04d4 commit c9d9686

File tree

4 files changed

+106
-0
lines changed

4 files changed

+106
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/// Docstring.
2+
/// @type String
3+
$from-other: 'hello';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
@use "sass:string"
2+
@use "other"
3+
4+
$_id: string.unique-id()
5+
$_prefix: other.$from-other
6+
7+
.card
8+
.body:has(:not(.stuff))
9+
padding: 4px
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
const assert = require('node:assert');
2+
const path = require('node:path');
3+
const vscode = require('vscode');
4+
const { showFile, sleepCI } = require('../util');
5+
6+
const stylesUri = vscode.Uri.file(
7+
path.resolve(__dirname, 'fixtures', 'styles.sass')
8+
);
9+
10+
before(async () => {
11+
await showFile(stylesUri);
12+
await sleepCI();
13+
});
14+
15+
after(async () => {
16+
await vscode.commands.executeCommand('workbench.action.closeAllEditors');
17+
});
18+
19+
/**
20+
* @param {import('vscode').Hover[]} hover
21+
* @returns {string}
22+
*/
23+
function getHoverContents(hover) {
24+
return hover
25+
.flatMap((item) => {
26+
return item.contents.map((content) =>
27+
typeof content === 'string' ? content : content.value
28+
);
29+
})
30+
.join('\n');
31+
}
32+
33+
/**
34+
* @param {import('vscode').Uri} documentUri
35+
* @param {import('vscode').Position} position
36+
* @returns {Promise<import('vscode').Hover[]>}
37+
*/
38+
async function hover(documentUri, position) {
39+
const result = await vscode.commands.executeCommand(
40+
'vscode.executeHoverProvider',
41+
documentUri,
42+
position
43+
);
44+
return result;
45+
}
46+
47+
test('gets hover information from the same document', async () => {
48+
const result = await hover(stylesUri, new vscode.Position(7, 10));
49+
50+
assert.match(
51+
getHoverContents(result),
52+
/\.card \.body:has\(:not\(\.stuff\)\)/
53+
);
54+
});
55+
56+
test('gets hover information from the workspace', async () => {
57+
const result = await hover(stylesUri, new vscode.Position(4, 19));
58+
59+
assert.match(getHoverContents(result), /Docstring/);
60+
});
61+
62+
test('gets hover information for Sass built-in', async () => {
63+
const result = await hover(stylesUri, new vscode.Position(3, 14));
64+
65+
assert.match(
66+
getHoverContents(result),
67+
/Returns a randomly-generated unquoted string/
68+
);
69+
});
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
const path = require('node:path');
2+
const fs = require('node:fs/promises');
3+
const vscode = require('vscode');
4+
const { runMocha } = require('../mocha');
5+
6+
/**
7+
* @returns {Promise<void>}
8+
*/
9+
async function run() {
10+
const filePaths = [];
11+
12+
const dir = await fs.readdir(__dirname, { withFileTypes: true });
13+
for (let entry of dir) {
14+
if (entry.isFile() && entry.name.endsWith('test.js')) {
15+
filePaths.push(path.join(entry.parentPath, entry.name));
16+
}
17+
}
18+
19+
await runMocha(
20+
filePaths,
21+
vscode.Uri.file(path.resolve(__dirname, 'fixtures', 'styles.sass'))
22+
);
23+
}
24+
25+
module.exports = { run };

0 commit comments

Comments
 (0)