|
| 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 | +}); |
0 commit comments