Skip to content

Commit 1ebb0dd

Browse files
committed
remove spectron references
1 parent 1b2f198 commit 1ebb0dd

24 files changed

Lines changed: 229 additions & 950 deletions

test/smoke/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,9 @@
2929
"ncp": "^2.0.0",
3030
"portastic": "^1.0.1",
3131
"rimraf": "^2.6.1",
32-
"spectron": "^3.7.2",
3332
"strip-json-comments": "^2.0.1",
3433
"tmp": "0.0.33",
3534
"typescript": "2.5.2",
3635
"watch": "^1.0.2"
3736
}
38-
}
37+
}

test/smoke/src/api.ts

Lines changed: 146 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,149 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { Driver, Element } from './driver';
6+
import { IDriver, IElement } from './vscode/driver';
7+
8+
export class CodeDriver {
9+
10+
constructor(
11+
private driver: IDriver,
12+
private verbose: boolean
13+
) { }
14+
15+
private _activeWindowId: number | undefined = undefined;
16+
17+
async dispatchKeybinding(keybinding: string): Promise<void> {
18+
if (this.verbose) {
19+
console.log('- dispatchKeybinding:', keybinding);
20+
}
21+
22+
const windowId = await this.getWindowId();
23+
await this.driver.dispatchKeybinding(windowId, keybinding);
24+
}
25+
26+
async click(selector: string, xoffset?: number | undefined, yoffset?: number | undefined): Promise<any> {
27+
if (this.verbose) {
28+
console.log('- click:', selector);
29+
}
30+
31+
const windowId = await this.getWindowId();
32+
await this.driver.click(windowId, selector, xoffset, yoffset);
33+
}
34+
35+
async doubleClick(selector: string): Promise<any> {
36+
if (this.verbose) {
37+
console.log('- doubleClick:', selector);
38+
}
39+
40+
const windowId = await this.getWindowId();
41+
await this.driver.doubleClick(windowId, selector);
42+
}
43+
44+
async move(selector: string): Promise<any> {
45+
if (this.verbose) {
46+
console.log('- move:', selector);
47+
}
48+
49+
const windowId = await this.getWindowId();
50+
await this.driver.move(windowId, selector);
51+
}
52+
53+
async setValue(selector: string, text: string): Promise<void> {
54+
if (this.verbose) {
55+
console.log('- setValue:', selector, text);
56+
}
57+
58+
const windowId = await this.getWindowId();
59+
await this.driver.setValue(windowId, selector, text);
60+
}
61+
62+
async getTitle(): Promise<string> {
63+
if (this.verbose) {
64+
console.log('- getTitle:');
65+
}
66+
67+
const windowId = await this.getWindowId();
68+
return await this.driver.getTitle(windowId);
69+
}
70+
71+
async isActiveElement(selector: string): Promise<boolean> {
72+
if (this.verbose) {
73+
console.log('- isActiveElement:', selector);
74+
}
75+
76+
const windowId = await this.getWindowId();
77+
return await this.driver.isActiveElement(windowId, selector);
78+
}
79+
80+
async getElements(selector: string, recursive = false): Promise<IElement[]> {
81+
if (this.verbose) {
82+
console.log('- getElements:', selector);
83+
}
84+
85+
const windowId = await this.getWindowId();
86+
return await this.driver.getElements(windowId, selector, recursive);
87+
}
88+
89+
async typeInEditor(selector: string, text: string): Promise<void> {
90+
if (this.verbose) {
91+
console.log('- typeInEditor:', selector, text);
92+
}
93+
94+
const windowId = await this.getWindowId();
95+
return await this.driver.typeInEditor(windowId, selector, text);
96+
}
97+
98+
async getTerminalBuffer(selector: string): Promise<string[]> {
99+
if (this.verbose) {
100+
console.log('- getTerminalBuffer:', selector);
101+
}
102+
103+
const windowId = await this.getWindowId();
104+
return await this.driver.getTerminalBuffer(windowId, selector);
105+
}
106+
107+
private async getWindowId(): Promise<number> {
108+
if (typeof this._activeWindowId !== 'number') {
109+
const windows = await this.driver.getWindowIds();
110+
this._activeWindowId = windows[0];
111+
}
112+
113+
return this._activeWindowId;
114+
}
115+
}
116+
117+
export function findElement(element: IElement, fn: (element: IElement) => boolean): IElement | null {
118+
const queue = [element];
119+
120+
while (queue.length > 0) {
121+
const element = queue.shift()!;
122+
123+
if (fn(element)) {
124+
return element;
125+
}
126+
127+
queue.push(...element.children);
128+
}
129+
130+
return null;
131+
}
132+
133+
export function findElements(element: IElement, fn: (element: IElement) => boolean): IElement[] {
134+
const result: IElement[] = [];
135+
const queue = [element];
136+
137+
while (queue.length > 0) {
138+
const element = queue.shift()!;
139+
140+
if (fn(element)) {
141+
result.push(element);
142+
}
143+
144+
queue.push(...element.children);
145+
}
146+
147+
return result;
148+
}
7149

8150
export class API {
9151

@@ -13,7 +155,7 @@ export class API {
13155
private readonly retryDuration = 100; // in milliseconds
14156

15157
constructor(
16-
private driver: Driver,
158+
private driver: CodeDriver,
17159
waitTime: number
18160
) {
19161
this.retryCount = (waitTime * 1000) / this.retryDuration;
@@ -58,11 +200,11 @@ export class API {
58200
return elements.length;
59201
}
60202

61-
waitForElements(selector: string, recursive: boolean, accept: (result: Element[]) => boolean = result => result.length > 0): Promise<Element[]> {
203+
waitForElements(selector: string, recursive: boolean, accept: (result: IElement[]) => boolean = result => result.length > 0): Promise<IElement[]> {
62204
return this.waitFor(() => this.driver.getElements(selector, recursive), accept, `elements with selector ${selector}`) as Promise<any>;
63205
}
64206

65-
waitForElement(selector: string, accept: (result: Element | undefined) => boolean = result => !!result): Promise<void> {
207+
waitForElement(selector: string, accept: (result: IElement | undefined) => boolean = result => !!result): Promise<void> {
66208
return this.waitFor(() => this.driver.getElements(selector).then(els => els[0]), accept, `element with selector ${selector}`) as Promise<any>;
67209
}
68210

test/smoke/src/application.ts

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { API } from './api';
6+
import { API, CodeDriver } from './api';
77
import { Workbench } from './areas/workbench/workbench';
88
import * as fs from 'fs';
99
import * as cp from 'child_process';
10-
import { CodeDriver } from './driver';
1110
import { Code, spawn, SpawnOptions } from './vscode/code';
1211

1312
export enum Quality {
@@ -16,32 +15,23 @@ export enum Quality {
1615
Stable
1716
}
1817

19-
export interface SpectronApplicationOptions extends SpawnOptions {
18+
export interface ApplicationOptions extends SpawnOptions {
2019
quality: Quality;
21-
electronPath: string;
2220
workspacePath: string;
23-
artifactsPath: string;
2421
workspaceFilePath: string;
2522
waitTime: number;
2623
verbose: boolean;
2724
}
2825

29-
/**
30-
* Wraps Spectron's Application instance with its used methods.
31-
*/
32-
export class SpectronApplication {
33-
34-
// private static count = 0;
26+
export class Application {
3527

3628
private _api: API;
3729
private _workbench: Workbench;
3830
private codeInstance: Code | undefined;
3931
private keybindings: any[];
4032
private stopLogCollection: (() => Promise<void>) | undefined;
4133

42-
constructor(
43-
private options: SpectronApplicationOptions
44-
) { }
34+
constructor(private options: ApplicationOptions) { }
4535

4636
get quality(): Quality {
4737
return this.options.quality;

test/smoke/src/areas/css/css.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,21 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { SpectronApplication } from '../../application';
6+
import { Application } from '../../application';
77
import { ProblemSeverity, Problems } from '../problems/problems';
88

99
export function setup() {
1010
describe('CSS', () => {
1111
it('verifies quick outline', async function () {
12-
const app = this.app as SpectronApplication;
12+
const app = this.app as Application;
1313
await app.workbench.quickopen.openFile('style.css');
1414

1515
await app.workbench.quickopen.openQuickOutline();
1616
await app.workbench.quickopen.waitForQuickOpenElements(names => names.length === 2);
1717
});
1818

1919
it('verifies warnings for the empty rule', async function () {
20-
const app = this.app as SpectronApplication;
20+
const app = this.app as Application;
2121
await app.workbench.quickopen.openFile('style.css');
2222
await app.workbench.editor.waitForTypeInEditor('style.css', '.foo{}');
2323

@@ -29,7 +29,7 @@ export function setup() {
2929
});
3030

3131
it('verifies that warning becomes an error once setting changed', async function () {
32-
const app = this.app as SpectronApplication;
32+
const app = this.app as Application;
3333
await app.workbench.settingsEditor.addUserSetting('css.lint.emptyRules', '"error"');
3434
await app.workbench.quickopen.openFile('style.css');
3535
await app.workbench.editor.waitForTypeInEditor('style.css', '.foo{}');

test/smoke/src/areas/debug/debug.test.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ import * as http from 'http';
88
import * as path from 'path';
99
import * as fs from 'fs';
1010
import * as stripJsonComments from 'strip-json-comments';
11-
import { SpectronApplication } from '../../application';
11+
import { Application } from '../../application';
1212

1313
export function setup() {
1414
describe('Debug', () => {
1515
it('configure launch json', async function () {
16-
const app = this.app as SpectronApplication;
16+
const app = this.app as Application;
1717

1818
await app.workbench.debug.openDebugViewlet();
1919
await app.workbench.quickopen.openFile('app.js');
@@ -37,15 +37,15 @@ export function setup() {
3737
});
3838

3939
it('breakpoints', async function () {
40-
const app = this.app as SpectronApplication;
40+
const app = this.app as Application;
4141

4242
await app.workbench.quickopen.openFile('index.js');
4343
await app.workbench.debug.setBreakpointOnLine(6);
4444
});
4545

4646
let port: number;
4747
it('start debugging', async function () {
48-
const app = this.app as SpectronApplication;
48+
const app = this.app as Application;
4949

5050
// TODO@isidor
5151
await new Promise(c => setTimeout(c, 100));
@@ -60,7 +60,7 @@ export function setup() {
6060
});
6161

6262
it('focus stack frames and variables', async function () {
63-
const app = this.app as SpectronApplication;
63+
const app = this.app as Application;
6464

6565
await app.api.waitFor(() => app.workbench.debug.getLocalVariableCount(), c => c === 4, 'there should be 4 local variables');
6666

@@ -75,7 +75,7 @@ export function setup() {
7575
});
7676

7777
it('stepOver, stepIn, stepOut', async function () {
78-
const app = this.app as SpectronApplication;
78+
const app = this.app as Application;
7979

8080
await app.workbench.debug.stepIn();
8181

@@ -89,7 +89,7 @@ export function setup() {
8989
});
9090

9191
it('continue', async function () {
92-
const app = this.app as SpectronApplication;
92+
const app = this.app as Application;
9393

9494
await app.workbench.debug.continue();
9595

@@ -102,13 +102,13 @@ export function setup() {
102102
});
103103

104104
it('debug console', async function () {
105-
const app = this.app as SpectronApplication;
105+
const app = this.app as Application;
106106

107107
await app.workbench.debug.waitForReplCommand('2 + 2', r => r === '4');
108108
});
109109

110110
it('stop debugging', async function () {
111-
const app = this.app as SpectronApplication;
111+
const app = this.app as Application;
112112

113113
await app.workbench.debug.stopDebugging();
114114
});

test/smoke/src/areas/debug/debug.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55

66
import { Viewlet } from '../workbench/viewlet';
77
import { Commands } from '../workbench/workbench';
8-
import { API } from '../../api';
8+
import { API, findElement } from '../../api';
99
import { Editors } from '../editor/editors';
1010
import { Editor } from '../editor/editor';
11-
import { findElement, Element } from '../../driver';
11+
import { IElement } from '../../vscode/driver';
1212

1313
const VIEWLET = 'div[id="workbench.view.debug"]';
1414
const DEBUG_VIEW = `${VIEWLET} .debug-view-content`;
@@ -37,7 +37,7 @@ export interface IStackFrame {
3737
lineNumber: number;
3838
}
3939

40-
function toStackFrame(element: Element): IStackFrame {
40+
function toStackFrame(element: IElement): IStackFrame {
4141
const name = findElement(element, e => /\bfile-name\b/.test(e.className))!;
4242
const line = findElement(element, e => /\bline-number\b/.test(e.className))!;
4343
const lineNumber = line.textContent ? parseInt(line.textContent.split(':').shift() || '0') : 0;

0 commit comments

Comments
 (0)