Skip to content
This repository was archived by the owner on Jul 29, 2024. It is now read-only.

Commit eb5913a

Browse files
authored
chore(test): clean up no control flow typescript tests (#5023)
1 parent 8fd6370 commit eb5913a

File tree

5 files changed

+72
-69
lines changed

5 files changed

+72
-69
lines changed

scripts/test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ var passingTests = [
3939
// 'node built/cli.js spec/noGlobalsConf.js',
4040
// 'node built/cli.js spec/angular2Conf.js',
4141
// 'node built/cli.js spec/hybridConf.js',
42-
// 'node built/cli.js spec/built/noCFBasicConf.js',
43-
// 'node built/cli.js spec/built/noCFBasicConf.js --useBlockingProxy',
44-
// 'node built/cli.js spec/built/noCFPluginConf.js',
42+
'node built/cli.js spec/built/noCFBasicConf.js',
43+
'node built/cli.js spec/built/noCFBasicConf.js --useBlockingProxy',
44+
'node built/cli.js spec/built/noCFPluginConf.js',
4545
// //'node scripts/driverProviderAttachSession.js',
4646
// 'node built/cli.js spec/driverProviderUseExistingWebDriver.js',
4747
// 'node built/cli.js spec/driverProviderUseExistingWebDriver.js --useBlockingProxy',

spec/ts/basic/element_spec.ts

Lines changed: 60 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,186 +1,191 @@
11
// Based off of spec/basic/elements_spec.js
22
import * as q from 'q';
33

4-
import {$, $$, browser, by, By, element, ElementArrayFinder, ElementFinder, ExpectedConditions, promise as ppromise, WebElement} from '../../..';
4+
import {$, browser, by, element, ElementArrayFinder, ElementFinder, promise as ppromise, WebElement} from '../../..';
55

6-
describe('ElementFinder', function() {
7-
it('should return the same result as browser.findElement', async function() {
6+
describe('ElementFinder', () => {
7+
it('should return the same result as browser.findElement', async() => {
88
await browser.get('index.html#/form');
99
const nameByElement = element(by.binding('username'));
1010

11-
await expect(nameByElement.getText())
12-
.toEqual(browser.findElement(by.binding('username')).getText());
11+
expect(await nameByElement.getText())
12+
.toEqual(await browser.findElement(by.binding('username')).getText());
1313
});
1414

15-
it('should wait to grab the WebElement until a method is called', async function() {
15+
it('should wait to grab the WebElement until a method is called', async() => {
1616
// These should throw no error before a page is loaded.
1717
const usernameInput = element(by.model('username'));
1818
const name = element(by.binding('username'));
1919

2020
await browser.get('index.html#/form');
2121

22-
await expect(name.getText()).toEqual('Anon');
22+
expect(await name.getText()).toEqual('Anon');
2323

2424
await usernameInput.clear();
2525
await usernameInput.sendKeys('Jane');
26-
await expect(name.getText()).toEqual('Jane');
26+
expect(await name.getText()).toEqual('Jane');
2727
});
2828

29-
it('should chain element actions', async function() {
29+
it('should chain element actions', async() => {
3030
await browser.get('index.html#/form');
3131

3232
const usernameInput = element(by.model('username'));
3333
const name = element(by.binding('username'));
3434

35-
await expect(name.getText()).toEqual('Anon');
35+
expect(await name.getText()).toEqual('Anon');
3636

3737
await((usernameInput.clear() as any) as ElementFinder).sendKeys('Jane');
38-
await expect(name.getText()).toEqual('Jane');
38+
expect(await name.getText()).toEqual('Jane');
3939
});
4040

41-
it('should run chained element actions in sequence', function(done: any) {
41+
it('should run chained element actions in sequence', async(done: any) => {
4242
// Testing private methods is bad :(
4343
let els = new ElementArrayFinder(browser, () => {
44-
return ppromise.when([null as WebElement]);
44+
return Promise.resolve([null as WebElement]);
4545
});
4646
let applyAction_: (actionFn: (value: WebElement, index: number, array: WebElement[]) => any) =>
4747
ElementArrayFinder = (ElementArrayFinder as any).prototype.applyAction_;
4848
let order: string[] = [];
4949

50-
let deferredA = q.defer<void>();
50+
let deferredA: Promise<void>;
5151
els = applyAction_.call(els, () => {
52-
return deferredA.promise.then(() => {
52+
deferredA = new Promise<void>(resolve => {
5353
order.push('a');
54+
resolve();
5455
});
5556
});
56-
let deferredB = q.defer<void>();
57+
let deferredB: Promise<void>;
5758
els = applyAction_.call(els, () => {
58-
return deferredB.promise.then(() => {
59+
deferredB = new Promise<void>(resolve => {
5960
order.push('b');
61+
resolve();
6062
});
6163
});
6264

63-
deferredB.resolve();
65+
await deferredB;
6466
setTimeout(async function() {
65-
deferredA.resolve();
67+
await deferredA;
6668
await els;
6769
expect(order).toEqual(['a', 'b']);
6870
done();
6971
}, 100);
7072
});
7173

72-
it('chained call should wait to grab the WebElement until a method is called', async function() {
74+
it('chained call should wait to grab the WebElement until a method is called',
75+
async() => {
7376
// These should throw no error before a page is loaded.
74-
const reused = element(by.id('baz')).element(by.binding('item.reusedBinding'));
77+
const reused = element(by.id('baz'))
78+
.element(by.binding('item.reusedBinding'));
7579

7680
await browser.get('index.html#/conflict');
7781

78-
await expect(reused.getText()).toEqual('Inner: inner');
79-
await expect(reused.isPresent()).toBe(true);
82+
expect(await reused.getText()).toEqual('Inner: inner');
83+
expect(await reused.isPresent()).toBe(true);
8084
});
8185

82-
it('should differentiate elements with the same binding by chaining', async function() {
86+
it('should differentiate elements with the same binding by chaining',
87+
async() => {
8388
await browser.get('index.html#/conflict');
8489

8590
const outerReused = element(by.binding('item.reusedBinding'));
8691
const innerReused = element(by.id('baz')).element(by.binding('item.reusedBinding'));
8792

88-
await expect(outerReused.getText()).toEqual('Outer: outer');
89-
await expect(innerReused.getText()).toEqual('Inner: inner');
93+
expect(await outerReused.getText()).toEqual('Outer: outer');
94+
expect(await innerReused.getText()).toEqual('Inner: inner');
9095
});
9196

92-
it('should chain deeper than 2', async function() {
97+
it('should chain deeper than 2', async() => {
9398
// These should throw no error before a page is loaded.
94-
const reused =
95-
element(by.css('body')).element(by.id('baz')).element(by.binding('item.reusedBinding'));
99+
const reused = element(by.css('body')).element(by.id('baz'))
100+
.element(by.binding('item.reusedBinding'));
96101

97102
await browser.get('index.html#/conflict');
98103

99-
await expect(reused.getText()).toEqual('Inner: inner');
104+
expect(await reused.getText()).toEqual('Inner: inner');
100105
});
101106

102-
it('should allow handling errors', async function() {
107+
it('should allow handling errors', async() => {
103108
await browser.get('index.html#/form');
104109
try {
105110
await $('.nopenopenope').getText();
106111

107112
// The above line should have throw an error. Fail.
108-
await expect(true).toEqual(false);
113+
expect(true).toEqual(false);
109114
} catch (e) {
110-
await expect(true).toEqual(true);
115+
expect(true).toEqual(true);
111116
}
112117
});
113118

114-
it('should allow handling chained errors', async function() {
119+
it('should allow handling chained errors', async() => {
115120
await browser.get('index.html#/form');
116121
try {
117122
await $('.nopenopenope').$('furthernope').getText();
118123

119124
// The above line should have throw an error. Fail.
120-
await expect(true).toEqual(false);
125+
expect(true).toEqual(false);
121126
} catch (e) {
122-
await expect(true).toEqual(true);
127+
expect(true).toEqual(true);
123128
}
124129
});
125130

126-
it('should keep a reference to the original locator', async function() {
131+
it('should keep a reference to the original locator', async() => {
127132
await browser.get('index.html#/form');
128133

129134
const byCss = by.css('body');
130135
const byBinding = by.binding('greet');
131136

132-
await expect(element(byCss).locator()).toEqual(byCss);
133-
await expect(element(byBinding).locator()).toEqual(byBinding);
137+
expect(await element(byCss).locator()).toEqual(byCss);
138+
expect(await element(byBinding).locator()).toEqual(byBinding);
134139
});
135140

136-
it('should propagate exceptions', async function() {
141+
it('should propagate exceptions', async() => {
137142
await browser.get('index.html#/form');
138143

139144
const invalidElement = element(by.binding('INVALID'));
140145
const successful = invalidElement.getText().then(
141146
function() {
142147
return true;
143-
} as any as (() => ppromise.Promise<void>),
148+
} as any as (() => Promise<boolean>),
144149
function() {
145150
return false;
146-
} as any as (() => ppromise.Promise<void>));
147-
await expect(successful).toEqual(false);
151+
} as any as (() => Promise<boolean>));
152+
expect(await successful).toEqual(false);
148153
});
149154

150-
it('should be returned from a helper without infinite loops', async function() {
155+
it('should be returned from a helper without infinite loops', async() => {
151156
await browser.get('index.html#/form');
152-
const helperPromise = ppromise.when(true).then(function() {
157+
const helperPromise = Promise.resolve(true).then(() => {
153158
return element(by.binding('greeting'));
154159
});
155160

156-
await helperPromise.then(async function(finalResult: ElementFinder) {
157-
await expect(finalResult.getText()).toEqual('Hiya');
158-
} as any as (() => ppromise.Promise<void>));
161+
await helperPromise.then(async(finalResult: ElementFinder) => {
162+
expect(await finalResult.getText()).toEqual('Hiya');
163+
});
159164
});
160165

161-
it('should be usable in WebDriver functions', async function() {
166+
it('should be usable in WebDriver functions', async() => {
162167
await browser.get('index.html#/form');
163168
const greeting = element(by.binding('greeting'));
164169
await browser.executeScript('arguments[0].scrollIntoView', greeting);
165170
});
166171

167-
it('should allow null as success handler', async function() {
172+
it('should allow null as success handler', async() => {
168173
await browser.get('index.html#/form');
169174

170175
const name = element(by.binding('username'));
171176

172-
await expect(name.getText()).toEqual('Anon');
173-
await expect(name.getText().then(null, function() {})).toEqual('Anon');
177+
expect(await name.getText()).toEqual('Anon');
178+
expect(await name.getText().then(null, function() {})).toEqual('Anon');
174179

175180
});
176181

177-
it('should check equality correctly', async function() {
182+
it('should check equality correctly', async() => {
178183
await browser.get('index.html#/form');
179184

180185
const usernameInput = element(by.model('username'));
181186
const name = element(by.binding('username'));
182187

183-
await expect(usernameInput.equals(usernameInput)).toEqual(true);
184-
await expect(usernameInput.equals(name)).toEqual(false);
188+
expect(await usernameInput.equals(usernameInput)).toEqual(true);
189+
expect(await usernameInput.equals(name)).toEqual(false);
185190
});
186191
});

spec/ts/basic/is_disabled_spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import {browser, promise as ppromise} from '../../..';
22

3-
describe('verify control flow is off', function() {
3+
describe('verify control flow is off', () => {
44
it('should have set webdriver.promise.USE_PROMISE_MANAGER', () => {
55
expect((ppromise as any).USE_PROMISE_MANAGER).toBe(false);
66
});
77

8-
it('should not wait on one command before starting another', async function() {
8+
it('should not wait on one command before starting another', async() => {
99
// Wait forever
1010
browser.controlFlow().wait(
1111
(browser.controlFlow() as any).promise((): void => undefined) as ppromise.Promise<void>);

spec/ts/noCFPluginConf.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import * as q from 'q';
21
import {Config, protractor} from '../..';
3-
import {promise as wdpromise} from 'selenium-webdriver';
42
const env = require('../environment.js');
53

64
export let config: Config = {
@@ -20,11 +18,11 @@ export let config: Config = {
2018

2119
plugins: [{
2220
inline: {
23-
onPageLoad: function() {
24-
//TODO: remove cast when @types/selenium-webdriver understands disabling the control flow
25-
return (q.delay(100) as any as wdpromise.Promise<void>).then(function() {
26-
(protractor as any).ON_PAGE_LOAD = true;
21+
onPageLoad: async function() {
22+
await new Promise(resolve => {
23+
setTimeout(resolve, 100);
2724
});
25+
(protractor as any).ON_PAGE_LOAD = true;
2826
}
2927
}
3028
}]

spec/ts/plugin/plugin_spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import {browser, protractor} from '../../..';
22

3-
describe('plugins', function() {
4-
it('should have run the onPageLoad hook', async function() {
3+
describe('plugins', () => {
4+
it('should have run the onPageLoad hook', async() => {
55
await browser.get('index.html');
6-
await expect((protractor as any).ON_PAGE_LOAD).toBe(true);
6+
expect((protractor as any).ON_PAGE_LOAD).toBe(true);
77
});
88
});

0 commit comments

Comments
 (0)