提交 19ad2f30 编写于 作者: J Joao

fix debug tests

上级 5e85ee5a
......@@ -5,32 +5,57 @@
import * as assert from 'assert';
import * as http from 'http';
import * as os from 'os';
import * as path from 'path';
import * as fs from 'fs';
import * as stripJsonComments from 'strip-json-comments';
import { SpectronApplication, VSCODE_BUILD } from '../../spectron/application';
import { SpectronApplication, VSCODE_BUILD, EXTENSIONS_DIR } from '../../spectron/application';
describe('Debug', () => {
let app: SpectronApplication = new SpectronApplication();
if (app.build === VSCODE_BUILD.DEV) {
const extensionsPath = path.join(os.homedir(), '.vscode-oss-dev', 'extensions');
const debugPath = path.join(extensionsPath, 'vscode-node-debug');
const debugExists = fs.existsSync(debugPath);
const debug2Path = path.join(extensionsPath, 'vscode-node-debug2');
const debug2Exists = fs.existsSync(debug2Path);
if (!debugExists) {
console.warn(`Skipping debug tests because vscode-node-debug extension was not found in ${extensionsPath}`);
return;
}
if (!debug2Exists) {
console.warn(`Skipping debug tests because vscode-node-debug2 extension was not found in ${extensionsPath}`);
return;
}
fs.symlinkSync(debugPath, path.join(EXTENSIONS_DIR, 'vscode-node-debug'));
fs.symlinkSync(debug2Path, path.join(EXTENSIONS_DIR, 'vscode-node-debug2'));
}
before(() => app.start());
after(() => app.stop());
if (app.build !== VSCODE_BUILD.DEV) {
it('configure launch json', async function () {
await app.workbench.debug.openDebugViewlet();
await app.workbench.openFile('app.js');
await app.workbench.debug.configure();
const content = await app.workbench.editor.getEditorVisibleText();
const json = JSON.parse(stripJsonComments(content));
assert.equal(json.configurations[0].request, 'launch');
assert.equal(json.configurations[0].type, 'node');
if (process.platform === 'win32') {
assert.equal(json.configurations[0].program, '${workspaceRoot}\\bin\\www');
} else {
assert.equal(json.configurations[0].program, '${workspaceRoot}/bin/www');
}
});
}
it('configure launch json', async function () {
await app.workbench.debug.openDebugViewlet();
await app.workbench.openFile('app.js');
await app.workbench.debug.configure();
const content = await app.workbench.editor.getEditorVisibleText();
const json = JSON.parse(stripJsonComments(content));
assert.equal(json.configurations[0].request, 'launch');
assert.equal(json.configurations[0].type, 'node');
if (process.platform === 'win32') {
assert.equal(json.configurations[0].program, '${workspaceRoot}\\bin\\www');
} else {
assert.equal(json.configurations[0].program, '${workspaceRoot}/bin/www');
}
});
it('breakpoints', async function () {
await app.workbench.openFile('index.js');
......@@ -39,7 +64,7 @@ describe('Debug', () => {
it('start debugging', async function () {
await app.workbench.debug.startDebugging();
setTimeout(() => http.get('http://localhost:3000').on('error', e => void 0), 200);
setTimeout(() => http.get(`http://localhost:3000`).on('error', e => void 0), 400);
await app.workbench.debug.waitForStackFrame(sf => sf.name === 'index.js' && sf.lineNumber === 6);
});
......@@ -64,7 +89,7 @@ describe('Debug', () => {
it('continue', async function () {
await app.workbench.debug.continue();
setTimeout(() => http.get('http://localhost:3000').on('error', e => void 0), 200);
setTimeout(() => http.get(`http://localhost:3000`).on('error', e => void 0), 400);
await app.workbench.debug.waitForStackFrame(sf => sf.name === 'index.js' && sf.lineNumber === 6);
});
......
......@@ -23,7 +23,9 @@ const NOT_DEBUG_STATUS_BAR = `.statusbar:not(debugging)`;
const TOOLBAR_HIDDEN = `.debug-actions-widget.builder-hidden`;
const STACK_FRAME = `${VIEWLET} .monaco-tree-row .stack-frame`;
const VARIABLE = `${VIEWLET} .debug-variables .monaco-tree-row .expression`;
const CONSOLE_OUTPUT = `.repl .input-output-pair .output.expression`;
const CONSOLE_OUTPUT = `.repl .output.expression`;
const CONSOLE_INPUT_OUTPUT = `.repl .input-output-pair .output.expression`;
const SCOPE = `${VIEWLET} .debug-variables .scope`;
const REPL_FOCUSED = '.repl-input-wrapper .monaco-editor.focused';
......@@ -86,7 +88,7 @@ export class Debug extends Viewlet {
return await this.spectron.client.waitFor(async () => {
const stackFrames = await this.getStackFrames();
return stackFrames.filter(func)[0];
});;
});
}
async focusStackFrame(name: string): Promise<any> {
......@@ -99,12 +101,14 @@ export class Debug extends Viewlet {
await this.spectron.workbench.commandPallette.runCommand('Debug: Focus Debug Console');
await this.spectron.client.waitForElement(REPL_FOCUSED);
await this.spectron.client.type(text);
await this.spectron.client.waitForElement(CONSOLE_OUTPUT + ` .${type}`);
await this.spectron.client.waitForElement(CONSOLE_INPUT_OUTPUT + ` .${type}`);
return this.getLastConsoleOutput();
const result = await this.getConsoleOutput();
return result[result.length - 1] || '';
}
async getLocalVariableCount(): Promise<number> {
await this.spectron.client.waitForElement(SCOPE);
return await this.spectron.webclient.selectorExecute(VARIABLE, div => (Array.isArray(div) ? div : [div]).length);
}
......@@ -126,14 +130,14 @@ export class Debug extends Viewlet {
return result.map(({ name, lineNumber, element }) => ({ name, lineNumber, id: element.ELEMENT }));
}
private async getLastConsoleOutput(): Promise<string> {
private async getConsoleOutput(): Promise<string[]> {
const result = await this.spectron.webclient.selectorExecute(CONSOLE_OUTPUT,
div => (Array.isArray(div) ? div : [div]).map(element => {
const value = element.querySelector('.value') as HTMLElement;
return value.textContent;
})
return value && value.textContent;
}).filter(line => !!line)
);
return result.pop();
return result;
}
}
......@@ -10,6 +10,7 @@ import * as path from 'path';
import * as minimist from 'minimist';
import * as tmp from 'tmp';
import * as rimraf from 'rimraf';
import * as mkdirp from 'mkdirp';
const [, , ...args] = process.argv;
const opts = minimist(args, { string: ['build', 'stable-build', 'screenshot'] });
......@@ -22,6 +23,8 @@ const workspacePath = path.join(testDataPath, 'smoketest.code-workspace');
const testRepoUrl = 'https://github.com/Microsoft/vscode-smoketest-express';
const testRepoLocalDir = path.join(testDataPath, 'vscode-smoketest-express');
const keybindingsPath = path.join(testDataPath, 'keybindings.json');
const extensionsPath = path.join(testDataPath, 'extensions-dir');
mkdirp.sync(extensionsPath);
function fail(errorMessage): void {
console.error(errorMessage);
......@@ -72,7 +75,7 @@ if (!fs.existsSync(testCodePath)) {
}
process.env.VSCODE_USER_DIR = path.join(testDataPath, 'user-dir');
process.env.VSCODE_EXTENSIONS_DIR = path.join(testDataPath, 'extensions-dir');
process.env.VSCODE_EXTENSIONS_DIR = extensionsPath;
process.env.SCREENSHOTS_DIR = path.join(testDataPath, 'screenshots-dir');
process.env.SMOKETEST_REPO = testRepoLocalDir;
process.env.VSCODE_WORKSPACE_PATH = workspacePath;
......
......@@ -112,7 +112,7 @@ export class SpectronApplication {
// Prevent 'Getting Started' web page from opening on clean user-data-dir
args.push('--skip-getting-started');
// Ensure that running over custom extensions directory, rather than picking up the one that was used by a tester previously
args.push(`--extensions-dir=${path.join(EXTENSIONS_DIR, new Date().getTime().toString())}`);
args.push(`--extensions-dir=${EXTENSIONS_DIR}`);
args.push(...moreArgs);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册