Skip to content

Commit 8f5611b

Browse files
author
Dave Bartolomeo
committed
Move sourcemap tests to cli-integration
1 parent 7f3fcce commit 8f5611b

File tree

4 files changed

+71
-85
lines changed

4 files changed

+71
-85
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import { fail } from 'assert';
2+
import { commands, Selection, window, workspace } from 'vscode';
3+
import * as path from 'path';
4+
import * as assert from 'assert';
5+
import { expect } from 'chai';
6+
import { tmpDir } from '../../helpers';
7+
import * as fs from 'fs-extra';
8+
9+
/**
10+
* Integration tests for queries
11+
*/
12+
describe('SourceMap', function() {
13+
this.timeout(20000);
14+
15+
it('should jump to QL code', async () => {
16+
try {
17+
const root = workspace.workspaceFolders![0].uri.fsPath;
18+
const srcFiles = {
19+
summary: path.join(root, 'log-summary', 'evaluator-log.summary'),
20+
summaryMap: path.join(root, 'log-summary', 'evaluator-log.summary.map')
21+
};
22+
// We need to modify the source map so that its paths point to the actual location of the
23+
// workspace root on this machine. We'll copy the summary and its source map to a temp
24+
// directory, modify the source map their, and open that summary.
25+
const tempFiles = await copyFilesToTempDirectory(srcFiles);
26+
27+
// The checked-in sourcemap has placeholders of the form `${root}`, which we need to replace
28+
// with the actual root directory.
29+
const mapText = await fs.readFile(tempFiles.summaryMap, 'utf-8');
30+
// Always use forward slashes, since they work everywhere.
31+
const slashRoot = root.replaceAll('\\', '/');
32+
const newMapText = mapText.replaceAll('${root}', slashRoot);
33+
await fs.writeFile(tempFiles.summaryMap, newMapText);
34+
35+
const summaryDocument = await workspace.openTextDocument(tempFiles.summary);
36+
assert(summaryDocument.languageId === 'ql-summary');
37+
const summaryEditor = await window.showTextDocument(summaryDocument);
38+
summaryEditor.selection = new Selection(356, 10, 356, 10);
39+
await commands.executeCommand('codeQL.gotoQL');
40+
41+
const newEditor = window.activeTextEditor;
42+
expect(newEditor).to.be.not.undefined;
43+
const newDocument = newEditor!.document;
44+
expect(path.basename(newDocument.fileName)).to.equal('Namespace.qll');
45+
const newSelection = newEditor!.selection;
46+
expect(newSelection.start.line).to.equal(60);
47+
expect(newSelection.start.character).to.equal(2);
48+
} catch (e) {
49+
console.error('Test Failed');
50+
fail(e as Error);
51+
}
52+
});
53+
54+
async function copyFilesToTempDirectory<T extends Record<string, string>>(files: T): Promise<T> {
55+
const tempDir = path.join(tmpDir.name, 'log-summary');
56+
await fs.ensureDir(tempDir);
57+
const result: Record<string, string> = {};
58+
for (const key in files) {
59+
const srcPath = files[key];
60+
const destPath = path.join(tempDir, path.basename(srcPath));
61+
await fs.copy(srcPath, destPath);
62+
result[key] = destPath;
63+
}
64+
65+
return result as T;
66+
}
67+
});

extensions/ql-vscode/src/vscode-tests/minimal-workspace/activation.test.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import * as assert from 'assert';
22
import * as path from 'path';
33
import * as vscode from 'vscode';
44
import * as determiningSelectedQueryTest from './determining-selected-query-test';
5-
import * as sourcemapTest from './sourcemap.test';
65

76
describe('launching with a minimal workspace', async () => {
87

@@ -19,7 +18,7 @@ describe('launching with a minimal workspace', async () => {
1918
});
2019

2120
it('should activate the extension when a .ql file is opened', async function() {
22-
this.timeout(600000);
21+
this.timeout(60000);
2322
await delay();
2423

2524
const folders = vscode.workspace.workspaceFolders;
@@ -34,9 +33,8 @@ describe('launching with a minimal workspace', async () => {
3433
});
3534

3635
async function delay() {
37-
await new Promise(resolve => setTimeout(resolve, 40000));
36+
await new Promise(resolve => setTimeout(resolve, 4000));
3837
}
3938
});
4039

4140
determiningSelectedQueryTest.run();
42-
sourcemapTest.run();

extensions/ql-vscode/src/vscode-tests/minimal-workspace/sourcemap.test.ts

Lines changed: 0 additions & 73 deletions
This file was deleted.

extensions/ql-vscode/src/vscode-tests/run-integration-tests.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ async function main() {
7676
const testDirsString = process.argv[2];
7777
const dirs = testDirsString.split(',').map(dir => dir.trim().toLocaleLowerCase());
7878
const extensionTestsEnv: Record<string, string> = {};
79+
if (dirs.includes(TestDir.CliIntegration)) {
7980
console.log('Installing required extensions');
8081
const cliPath = resolveCliPathFromVSCodeExecutablePath(vscodeExecutablePath);
8182
cp.spawnSync(
@@ -91,7 +92,6 @@ async function main() {
9192
stdio: 'inherit',
9293
}
9394
);
94-
if (dirs.includes(TestDir.CliIntegration)) {
9595
extensionTestsEnv.INTEGRATION_TEST_MODE = 'true';
9696
}
9797

@@ -130,13 +130,7 @@ function getLaunchArgs(dir: TestDir) {
130130

131131
case TestDir.MinimalWorksspace:
132132
return [
133-
// explicitly disable extensions that are known to interfere with the CLI integration tests
134-
'--disable-extension',
135-
'eamodio.gitlens',
136-
'--disable-extension',
137-
'github.codespaces',
138-
'--disable-extension',
139-
'github.copilot',
133+
'--disable-extensions',
140134
'--disable-gpu',
141135
'--user-data-dir=' + path.join(tmpDir.name, dir, 'user-data'),
142136
path.resolve(__dirname, '../../test/data')

0 commit comments

Comments
 (0)