Move sourcemap tests to cli-integration

This commit is contained in:
Dave Bartolomeo
2022-08-01 12:14:00 -04:00
parent 7f3fcce1ac
commit 8f5611b074
4 changed files with 71 additions and 85 deletions

View File

@@ -0,0 +1,67 @@
import { fail } from 'assert';
import { commands, Selection, window, workspace } from 'vscode';
import * as path from 'path';
import * as assert from 'assert';
import { expect } from 'chai';
import { tmpDir } from '../../helpers';
import * as fs from 'fs-extra';
/**
* Integration tests for queries
*/
describe('SourceMap', function() {
this.timeout(20000);
it('should jump to QL code', async () => {
try {
const root = workspace.workspaceFolders![0].uri.fsPath;
const srcFiles = {
summary: path.join(root, 'log-summary', 'evaluator-log.summary'),
summaryMap: path.join(root, 'log-summary', 'evaluator-log.summary.map')
};
// We need to modify the source map so that its paths point to the actual location of the
// workspace root on this machine. We'll copy the summary and its source map to a temp
// directory, modify the source map their, and open that summary.
const tempFiles = await copyFilesToTempDirectory(srcFiles);
// The checked-in sourcemap has placeholders of the form `${root}`, which we need to replace
// with the actual root directory.
const mapText = await fs.readFile(tempFiles.summaryMap, 'utf-8');
// Always use forward slashes, since they work everywhere.
const slashRoot = root.replaceAll('\\', '/');
const newMapText = mapText.replaceAll('${root}', slashRoot);
await fs.writeFile(tempFiles.summaryMap, newMapText);
const summaryDocument = await workspace.openTextDocument(tempFiles.summary);
assert(summaryDocument.languageId === 'ql-summary');
const summaryEditor = await window.showTextDocument(summaryDocument);
summaryEditor.selection = new Selection(356, 10, 356, 10);
await commands.executeCommand('codeQL.gotoQL');
const newEditor = window.activeTextEditor;
expect(newEditor).to.be.not.undefined;
const newDocument = newEditor!.document;
expect(path.basename(newDocument.fileName)).to.equal('Namespace.qll');
const newSelection = newEditor!.selection;
expect(newSelection.start.line).to.equal(60);
expect(newSelection.start.character).to.equal(2);
} catch (e) {
console.error('Test Failed');
fail(e as Error);
}
});
async function copyFilesToTempDirectory<T extends Record<string, string>>(files: T): Promise<T> {
const tempDir = path.join(tmpDir.name, 'log-summary');
await fs.ensureDir(tempDir);
const result: Record<string, string> = {};
for (const key in files) {
const srcPath = files[key];
const destPath = path.join(tempDir, path.basename(srcPath));
await fs.copy(srcPath, destPath);
result[key] = destPath;
}
return result as T;
}
});

View File

@@ -2,7 +2,6 @@ import * as assert from 'assert';
import * as path from 'path';
import * as vscode from 'vscode';
import * as determiningSelectedQueryTest from './determining-selected-query-test';
import * as sourcemapTest from './sourcemap.test';
describe('launching with a minimal workspace', async () => {
@@ -19,7 +18,7 @@ describe('launching with a minimal workspace', async () => {
});
it('should activate the extension when a .ql file is opened', async function() {
this.timeout(600000);
this.timeout(60000);
await delay();
const folders = vscode.workspace.workspaceFolders;
@@ -34,9 +33,8 @@ describe('launching with a minimal workspace', async () => {
});
async function delay() {
await new Promise(resolve => setTimeout(resolve, 40000));
await new Promise(resolve => setTimeout(resolve, 4000));
}
});
determiningSelectedQueryTest.run();
sourcemapTest.run();

View File

@@ -1,73 +0,0 @@
import { fail } from 'assert';
import { commands, extensions, Selection, window, workspace } from 'vscode';
import * as path from 'path';
import * as assert from 'assert';
import { expect } from 'chai';
import { tmpDir } from '../../helpers';
import * as fs from 'fs-extra';
export function run() {
/**
* Integration tests for queries
*/
describe('SourceMap', function() {
this.timeout(200000);
it('should jump to QL code', async () => {
try {
this.timeout(60000);
const ext = extensions.getExtension('GitHub.vscode-codeql');
await ext?.activate();
const root = workspace.workspaceFolders![0].uri.fsPath;
const srcFiles = {
summary: path.join(root, 'log-summary', 'evaluator-log.summary'),
summaryMap: path.join(root, 'log-summary', 'evaluator-log.summary.map')
};
// We need to modify the source map so that its paths point to the actual location of the
// workspace root on this machine. We'll copy the summary and its source map to a temp
// directory, modify the source map their, and open that summary.
const tempFiles = await copyFilesToTempDirectory(srcFiles);
// The checked-in sourcemap has placeholders of the form `${root}`, which we need to replace
// with the actual root directory.
const mapText = await fs.readFile(tempFiles.summaryMap, 'utf-8');
// Always use forward slashes, since they work everywhere.
const slashRoot = root.replaceAll('\\', '/');
const newMapText = mapText.replaceAll('${root}', slashRoot);
await fs.writeFile(tempFiles.summaryMap, newMapText);
const summaryDocument = await workspace.openTextDocument(tempFiles.summary);
assert(summaryDocument.languageId === 'ql-summary');
const summaryEditor = await window.showTextDocument(summaryDocument);
summaryEditor.selection = new Selection(356, 10, 356, 10);
await commands.executeCommand('codeQL.gotoQL');
const newEditor = window.activeTextEditor;
expect(newEditor).to.be.not.undefined;
const newDocument = newEditor!.document;
expect(path.basename(newDocument.fileName)).to.equal('Namespace.qll');
const newSelection = newEditor!.selection;
expect(newSelection.start.line).to.equal(60);
expect(newSelection.start.character).to.equal(2);
} catch (e) {
console.error('Test Failed');
fail(e as Error);
}
});
async function copyFilesToTempDirectory<T extends Record<string, string>>(files: T): Promise<T> {
const tempDir = path.join(tmpDir.name, 'log-summary');
await fs.ensureDir(tempDir);
const result: Record<string, string> = {};
for (const key in files) {
const srcPath = files[key];
const destPath = path.join(tempDir, path.basename(srcPath));
await fs.copy(srcPath, destPath);
result[key] = destPath;
}
return result as T;
}
});
}

View File

@@ -76,6 +76,7 @@ async function main() {
const testDirsString = process.argv[2];
const dirs = testDirsString.split(',').map(dir => dir.trim().toLocaleLowerCase());
const extensionTestsEnv: Record<string, string> = {};
if (dirs.includes(TestDir.CliIntegration)) {
console.log('Installing required extensions');
const cliPath = resolveCliPathFromVSCodeExecutablePath(vscodeExecutablePath);
cp.spawnSync(
@@ -91,7 +92,6 @@ async function main() {
stdio: 'inherit',
}
);
if (dirs.includes(TestDir.CliIntegration)) {
extensionTestsEnv.INTEGRATION_TEST_MODE = 'true';
}
@@ -130,13 +130,7 @@ function getLaunchArgs(dir: TestDir) {
case TestDir.MinimalWorksspace:
return [
// explicitly disable extensions that are known to interfere with the CLI integration tests
'--disable-extension',
'eamodio.gitlens',
'--disable-extension',
'github.codespaces',
'--disable-extension',
'github.copilot',
'--disable-extensions',
'--disable-gpu',
'--user-data-dir=' + path.join(tmpDir.name, dir, 'user-data'),
path.resolve(__dirname, '../../test/data')