mirror of
https://github.com/microsoft/vscode.git
synced 2026-07-06 05:56:09 -05:00
smoke: fix dataloss tests
This commit is contained in:
@@ -93,6 +93,18 @@ export class Editor {
|
||||
await this.spectron.client.waitAndClick(selector);
|
||||
}
|
||||
|
||||
public async waitForTypeInEditor(filename: string, text: string): Promise<any> {
|
||||
const editor = `.monaco-editor[data-uri$="${filename}"]`;
|
||||
await this.spectron.client.waitAndClick(editor);
|
||||
|
||||
const textarea = `${editor} textarea`;
|
||||
await this.spectron.client.waitForActiveElement(textarea);
|
||||
|
||||
await this.spectron.client.type(text);
|
||||
|
||||
await this.waitForEditorContents(filename, c => c.indexOf(text) > -1);
|
||||
}
|
||||
|
||||
public async waitForEditorContents(filename: string, accept: (contents: string) => boolean): Promise<any> {
|
||||
const selector = `.monaco-editor[data-uri$="${filename}"] .view-lines`;
|
||||
return this.spectron.client.waitForTextContent(selector, undefined, c => accept(c.replace(/\u00a0/g, ' ')));
|
||||
@@ -103,35 +115,35 @@ export class Editor {
|
||||
return this.spectron.client.waitForActiveElement(selector);
|
||||
}
|
||||
|
||||
public async waitForActiveEditorFirstLineText(filename: string): Promise<string> {
|
||||
const selector = `.editor-container .monaco-editor[data-uri$="${filename}"] textarea`;
|
||||
const result = await this.spectron.client.waitFor(
|
||||
() => this.spectron.client.spectron.client.execute(s => {
|
||||
if (!document.activeElement.matches(s)) {
|
||||
return undefined;
|
||||
}
|
||||
// public async waitForActiveEditorFirstLineText(filename: string): Promise<string> {
|
||||
// const selector = `.editor-container .monaco-editor[data-uri$="${filename}"] textarea`;
|
||||
// const result = await this.spectron.client.waitFor(
|
||||
// () => this.spectron.client.spectron.client.execute(s => {
|
||||
// if (!document.activeElement.matches(s)) {
|
||||
// return undefined;
|
||||
// }
|
||||
|
||||
let element: Element | null = document.activeElement;
|
||||
while (element && !/monaco-editor/.test(element.className) && element !== document.body) {
|
||||
element = element.parentElement;
|
||||
}
|
||||
// let element: Element | null = document.activeElement;
|
||||
// while (element && !/monaco-editor/.test(element.className) && element !== document.body) {
|
||||
// element = element.parentElement;
|
||||
// }
|
||||
|
||||
if (element && /monaco-editor/.test(element.className)) {
|
||||
const firstLine = element.querySelector('.view-lines span span:nth-child(1)');
|
||||
// if (element && /monaco-editor/.test(element.className)) {
|
||||
// const firstLine = element.querySelector('.view-lines span span:nth-child(1)');
|
||||
|
||||
if (firstLine) {
|
||||
return (firstLine.textContent || '').replace(/\u00a0/g, ' '); // DAMN
|
||||
}
|
||||
}
|
||||
// if (firstLine) {
|
||||
// return (firstLine.textContent || '').replace(/\u00a0/g, ' '); // DAMN
|
||||
// }
|
||||
// }
|
||||
|
||||
return undefined;
|
||||
}, selector),
|
||||
r => typeof r.value === 'string',
|
||||
`wait for active editor first line: ${selector}`
|
||||
);
|
||||
// return undefined;
|
||||
// }, selector),
|
||||
// r => typeof r.value === 'string',
|
||||
// `wait for active editor first line: ${selector}`
|
||||
// );
|
||||
|
||||
return result.value;
|
||||
}
|
||||
// return result.value;
|
||||
// }
|
||||
|
||||
private async getClassSelectors(term: string, viewline: number): Promise<string[]> {
|
||||
const result: { text: string, className: string }[] = await this.spectron.webclient.selectorExecute(`${Editor.VIEW_LINES}>:nth-child(${viewline}) span span`,
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as assert from 'assert';
|
||||
import { SpectronApplication } from '../../spectron/application';
|
||||
|
||||
describe('Dataloss', () => {
|
||||
@@ -13,27 +12,29 @@ describe('Dataloss', () => {
|
||||
beforeEach(function () { app.screenCapturer.testName = this.currentTest.title; });
|
||||
|
||||
it(`verifies that 'hot exit' works for dirty files`, async function () {
|
||||
const textToType = 'Hello, Code', textToTypeInUntitled = 'Hello, Unitled Code', fileName = 'readme.md', untitled = 'Untitled-1';
|
||||
await app.workbench.newUntitledFile();
|
||||
await app.client.type(textToTypeInUntitled);
|
||||
|
||||
const untitled = 'Untitled-1';
|
||||
const textToTypeInUntitled = 'Hello, Unitled Code';
|
||||
await app.workbench.editor.waitForTypeInEditor(untitled, textToTypeInUntitled);
|
||||
await app.screenCapturer.capture('Untitled file before reload');
|
||||
await app.workbench.explorer.openFile(fileName);
|
||||
await app.client.type(textToType);
|
||||
await app.screenCapturer.capture(`${fileName} before reload`);
|
||||
await app.screenCapturer.capture('Before reload');
|
||||
|
||||
const readmeMd = 'readme.md';
|
||||
const textToType = 'Hello, Code';
|
||||
await app.workbench.explorer.openFile(readmeMd);
|
||||
await app.workbench.editor.waitForTypeInEditor(readmeMd, textToType);
|
||||
await app.screenCapturer.capture(`${readmeMd} before reload`);
|
||||
|
||||
await app.reload();
|
||||
await app.screenCapturer.capture('After reload');
|
||||
|
||||
await app.workbench.waitForActiveTab(fileName, true);
|
||||
await app.screenCapturer.capture(`${fileName} after reload`);
|
||||
let actual = await app.workbench.editor.waitForActiveEditorFirstLineText(fileName);
|
||||
assert.ok(actual.startsWith(textToType), `'${actual}' did not start with '${textToType}'`);
|
||||
await app.workbench.waitForActiveTab(readmeMd, true);
|
||||
await app.screenCapturer.capture(`${readmeMd} after reload`);
|
||||
await app.workbench.editor.waitForEditorContents(readmeMd, c => c.indexOf(textToType) > -1);
|
||||
|
||||
await app.workbench.waitForTab(untitled, true);
|
||||
await app.workbench.selectTab('Untitled-1', true);
|
||||
await app.workbench.selectTab(untitled, true);
|
||||
await app.screenCapturer.capture('Untitled file after reload');
|
||||
actual = await app.workbench.editor.waitForActiveEditorFirstLineText('Untitled-1');
|
||||
assert.ok(actual.startsWith(textToTypeInUntitled), `'${actual}' did not start with '${textToTypeInUntitled}'`);
|
||||
await app.workbench.editor.waitForEditorContents(untitled, c => c.indexOf(textToTypeInUntitled) > -1);
|
||||
});
|
||||
});
|
||||
@@ -19,14 +19,14 @@ describe('Data Migration', () => {
|
||||
|
||||
it('checks if the Untitled file is restored migrating from stable to latest', async function () {
|
||||
const textToType = 'Very dirty file';
|
||||
console.log(STABLE_PATH);
|
||||
|
||||
// Setting up stable version
|
||||
let app = new SpectronApplication(STABLE_PATH);
|
||||
await app.start('Data Migration');
|
||||
app.screenCapturer.testName = 'Untitled is restorted';
|
||||
|
||||
await app.workbench.newUntitledFile();
|
||||
await app.client.type(textToType);
|
||||
await app.workbench.editor.waitForTypeInEditor('Untitled-1', textToType);
|
||||
|
||||
await app.stop();
|
||||
await app.wait(.5); // wait until all resources are released (e.g. locked local storage)
|
||||
@@ -37,9 +37,9 @@ describe('Data Migration', () => {
|
||||
app.screenCapturer.testName = 'Untitled is restorted';
|
||||
|
||||
assert.ok(await app.workbench.waitForActiveTab('Untitled-1', true), `Untitled-1 tab is not present after migration.`);
|
||||
const actual = await app.workbench.editor.waitForActiveEditorFirstLineText('Untitled-1');
|
||||
|
||||
await app.workbench.editor.waitForEditorContents('Untitled-1', c => c.indexOf(textToType) > -1);
|
||||
await app.screenCapturer.capture('Untitled file text');
|
||||
assert.ok(actual.startsWith(textToType), `${actual} did not start with ${textToType}`);
|
||||
});
|
||||
|
||||
it('checks if the newly created dirty file is restored migrating from stable to latest', async function () {
|
||||
@@ -67,9 +67,7 @@ describe('Data Migration', () => {
|
||||
|
||||
const filename = fileName.split('/')[1];
|
||||
assert.ok(await app.workbench.waitForActiveTab(filename), `Untitled-1 tab is not present after migration.`);
|
||||
const actual = await app.workbench.editor.waitForActiveEditorFirstLineText(filename);
|
||||
await app.screenCapturer.capture(fileName + ' text');
|
||||
assert.ok(actual.startsWith(firstTextPart.concat(secondTextPart)), `${actual} did not start with ${firstTextPart.concat(secondTextPart)}`);
|
||||
await app.workbench.editor.waitForEditorContents(filename, c => c.indexOf(firstTextPart + secondTextPart) > -1);
|
||||
|
||||
await Util.removeFile(`${fileName}`);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user