Skip to content

Commit

Permalink
test: update to latest test-web, patch for search provider
Browse files Browse the repository at this point in the history
Awaiting feedback on PR upstream, but let's get this thing on CI
  • Loading branch information
wkillerud committed Dec 17, 2023
1 parent 58227ce commit 4c6a876
Show file tree
Hide file tree
Showing 26 changed files with 10,831 additions and 51 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,6 @@ jobs:
timeout_minutes: 5
max_attempts: 3
command: npm run test:e2e

- name: Run web e2e tests
run: npm run test:web
64 changes: 52 additions & 12 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,6 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Integration Tests",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}",
"--extensionTestsPath=${workspaceFolder}/e2e/out/suite",
"${workspaceFolder}/fixtures/e2e/"
],
"outFiles": ["${workspaceFolder}/e2e/out/**/*.js"]
},
{
"type": "extensionHost",
"request": "launch",
Expand Down Expand Up @@ -42,6 +30,58 @@
"type": "npm",
"script": "dev"
}
},
{
"name": "Integration Tests",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}",
"--extensionTestsPath=${workspaceFolder}/e2e/out/suite",
"${workspaceFolder}/fixtures/e2e/"
],
"outFiles": ["${workspaceFolder}/e2e/out/**/*.js"]
},
{
"type": "chrome",
"request": "attach",
"name": "Attach to web integration test",
"skipFiles": ["<node_internals>/**"],
"port": 9229,
"timeout": 30000, // give it time to download vscode if needed
"resolveSourceMapLocations": [
"!**/vs/**", // exclude core vscode sources
"!**/static/build/extensions/**" // exclude built-in extensions
],
"presentation": {
"hidden": true
}
},
{
"type": "node",
"request": "launch",
"name": "Launch web integration test",
"outputCapture": "std",
"program": "${workspaceFolder}/web/dist/runTest.js",
"args": ["--waitForDebugger=9229"],
"cascadeTerminateToConfigurations": ["Launch web integration test"],
"presentation": {
"hidden": true
},
"preLaunchTask": {
"type": "npm",
"script": "pretest:web"
}
}
],
"compounds": [
{
"name": "Web Integration Tests",
"configurations": [
"Launch web integration test",
"Attach to web integration test"
]
}
]
}
5 changes: 1 addition & 4 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@
"**/bower_components/**"
],
"somesass.scanImportedFiles": true,
"somesass.showErrors": false,
"somesass.suggestAllFromOpenDocument": false,
"somesass.suggestFromUseOnly": false,
"somesass.suggestVariables": true,
"somesass.suggestMixins": true,
"somesass.suggestFunctions": true,
"somesass.suggestionStyle": "all",
"somesass.suggestFunctionsInStringContextAfterSymbols": " (+-*%"
}
7 changes: 7 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@
"reveal": "never"
},
"problemMatcher": ["$ts-webpack-watch"]
},
{
"type": "npm",
"script": "pretest:web",
"problemMatcher": [],
"label": "npm: pretest:web",
"detail": "webpack --config ./webpack.test-web.config.js && cd web && npm run compile"
}
]
}
8 changes: 7 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,10 @@ Breakpoints set, go to the Run and Debug and run the Integration Tests configura

### Debugging integration tests for the web extension

Unfortunately there are no integration tests for the web version at the moment.
Like [debugging integration tests](#debugging-integration-tests), this is recommended only when you want to debug the tests themselves. The web integration tests can be found in `web/src/suite/`.

Set breakpoints in the compiled output (`web/dist/suite/index.js`).

> Note: at time of writing you may have to set the breakpoints after
> the debugger has attached. I've had the best success rate just
> spam clicking in the gutter to set the breakpoint :(
10 changes: 8 additions & 2 deletions client/src/browser-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,14 @@ function getOuterMostWorkspaceFolder(folder: WorkspaceFolder): WorkspaceFolder {
export async function activate(context: ExtensionContext): Promise<void> {
async function didOpenTextDocument(document: TextDocument): Promise<void> {
if (
document.languageId !== "scss" ||
(document.uri.scheme !== "file" && document.uri.scheme !== "untitled")
document.uri.scheme !== "file" &&
document.uri.scheme !== "untitled" &&
document.uri.scheme !== "vscode-vfs" &&
document.uri.scheme !== "vscode-test-web" &&
document.languageId !== "scss" &&
document.languageId !== "vue" &&
document.languageId !== "svelte" &&
document.languageId !== "astro"
) {
return;
}
Expand Down
5 changes: 5 additions & 0 deletions client/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export function createLanguageClientOptions(
* Otherwise, each client will participate in each workspace.
*/
const pattern = `${currentWorkspace.uri.fsPath.replace(/\\/g, "/")}/**`;
const webPattern = `${currentWorkspace.uri.path}**`;

documentSelector = [
{ scheme: "file", language: "scss", pattern },
Expand All @@ -60,6 +61,10 @@ export function createLanguageClientOptions(
{ scheme: "vscode-vfs", language: "vue", pattern },
{ scheme: "vscode-vfs", language: "svelte", pattern },
{ scheme: "vscode-vfs", language: "astro", pattern },
{ scheme: "vscode-test-web", language: "scss", pattern: webPattern },
{ scheme: "vscode-test-web", language: "vue", pattern: webPattern },
{ scheme: "vscode-test-web", language: "svelte", pattern: webPattern },
{ scheme: "vscode-test-web", language: "astro", pattern: webPattern },
];
}

Expand Down
9 changes: 7 additions & 2 deletions client/src/node-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,13 @@ export async function activate(context: ExtensionContext): Promise<void> {

async function didOpenTextDocument(document: TextDocument): Promise<void> {
if (
document.languageId !== "scss" ||
(document.uri.scheme !== "file" && document.uri.scheme !== "untitled")
document.uri.scheme !== "file" &&
document.uri.scheme !== "untitled" &&
document.uri.scheme !== "vscode-vfs" &&
document.languageId !== "scss" &&
document.languageId !== "vue" &&
document.languageId !== "svelte" &&
document.languageId !== "astro"
) {
return;
}
Expand Down
26 changes: 12 additions & 14 deletions fixtures/e2e/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
{
"somesass.scannerDepth": 30,
"somesass.scannerExclude": [
"**/.git/**",
"**/node_modules/**",
"**/bower_components/**"
],
"somesass.scanImportedFiles": true,
"somesass.showErrors": false,
"somesass.suggestAllFromOpenDocument": false,
"somesass.suggestFromUseOnly": false,
"somesass.suggestVariables": true,
"somesass.suggestMixins": true,
"somesass.suggestFunctions": true,
"somesass.suggestFunctionsInStringContextAfterSymbols": " (+-*%"
"mochaExplorer.cwd": "server",
"somesass.scannerDepth": 30,
"somesass.scannerExclude": [
"**/.git/**",
"**/node_modules/**",
"**/bower_components/**"
],
"somesass.scanImportedFiles": true,
"somesass.suggestAllFromOpenDocument": false,
"somesass.suggestFromUseOnly": false,
"somesass.suggestionStyle": "all",
"somesass.suggestFunctionsInStringContextAfterSymbols": " (+-*%"
}
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,16 @@
"vscode:prepublish": "npm run build",
"clean": "rimraf dist",
"build": "npm run clean && webpack --mode production --devtool hidden-source-map",
"build:debug": "npm run clean && webpack --mode development --devtool hidden-source-map",
"dev": "webpack --mode development --watch",
"start:web": "vscode-test-web --browserType=chromium",
"start:test-web": "vscode-test-web --browserType=chromium --extensionDevelopmentPath=. ./fixtures/e2e",
"lint": "eslint \"**/*.ts\" --cache",
"test": "cd server && npm test",
"test:e2e": "npm run build && cd e2e && npm test",
"postinstall": "cd client && npm install && cd ../e2e && npm install && cd ../server && npm install"
"pretest:web": "webpack --config ./webpack.test-web.config.js && cd web && npm run compile",
"test:web": "cd web && npm run test",
"postinstall": "cd client && npm install && cd ../e2e && npm install && cd ../server && npm install && cd ../web && npm install"
},
"__metadata": {
"id": "6d35099c-3671-464c-ac0b-34a0c3823927",
Expand Down
17 changes: 7 additions & 10 deletions server/src/file-system-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,8 @@ export function getFileSystemProvider(
return handler.stat(uri);
}
try {
const res = await connection.sendRequest(
FsStatRequest.type,
uri.toString(),
);
const params = uri.toString();
const res = await connection.sendRequest(FsStatRequest.type, params);
return res as FileStat;
} catch (e) {
return {
Expand All @@ -67,8 +65,10 @@ export function getFileSystemProvider(
if (handler) {
return await handler.readFile(uri);
}

const params = uri.toString();
const res = await connection.sendRequest(FsReadFileRequest.type, {
uri: uri.toString(),
uri: params,
encoding,
});
return res;
Expand Down Expand Up @@ -108,10 +108,8 @@ export function getFileSystemProvider(
}

try {
const res = await connection.sendRequest(
FsStatRequest.type,
uri.toString(),
);
const params = uri.toString();
const res = await connection.sendRequest(FsStatRequest.type, params);
const exists = res.type !== FileType.Unknown;
return exists;
} catch {
Expand All @@ -123,7 +121,6 @@ export function getFileSystemProvider(
if (handler) {
return handler.realPath(uri);
}

return Promise.resolve(uri);
},
};
Expand Down
27 changes: 22 additions & 5 deletions server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,12 @@ export class SomeSassServer {
return null;
}

const { storage } = useContext();
const context = useContext();
if (!context) {
return;
}

const { storage } = context;
const newFiles: URI[] = [];
for (const change of event.changes) {
const uri = URI.parse(change.uri);
Expand Down Expand Up @@ -320,7 +325,12 @@ export class SomeSassServer {
});

this.connection.onCodeAction(async (params) => {
const { editorSettings } = useContext();
const context = useContext();
if (!context) {
return;
}

const { editorSettings } = context;
const codeActionProviders = [new ExtractProvider(editorSettings)];

const document = documents.get(params.textDocument.uri);
Expand Down Expand Up @@ -400,7 +410,12 @@ export class SomeSassServer {
return null;
}

const { storage } = useContext();
const context = useContext();
if (!context) {
return null;
}

const { storage } = context;
const scssDocument = storage.get(document.uri);
if (!scssDocument) {
// For the first open document, we may have a race condition where the scanner
Expand Down Expand Up @@ -430,8 +445,10 @@ export class SomeSassServer {
});

this.connection.onShutdown(() => {
const { storage } = useContext();
storage.clear();
const context = useContext();
if (context) {
context.storage.clear();
}
});

this.connection.listen();
Expand Down
Loading

0 comments on commit 4c6a876

Please sign in to comment.