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

Commit 5dab402

Browse files
authored
chore(typings): remove ptor from gulp types (#3307)
- after investigation, variables in the namespace cannot be assigned a value - types will require import of the classes and then setting the value from global ``` import {Browser} from 'protractor'; var browser: Browser = global['browser']; ``` - update typing tests to set the value of the type
1 parent f018aa0 commit 5dab402

7 files changed

+30
-11
lines changed

gulpfile.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,14 @@ gulp.task('default',['prepublish']);
7272

7373
gulp.task('types', function(done) {
7474
var folder = 'built';
75-
var files = ['ptor', 'browser', 'element', 'locators', 'expectedConditions'];
75+
var files = ['browser', 'element', 'locators', 'expectedConditions'];
7676
var outputFile = path.resolve(folder, 'index.d.ts');
7777
var contents = '';
78+
contents += 'declare namespace protractor {\n';
7879
files.forEach(file => {
7980
contents += parseTypingsFile(folder, file);
8081
});
82+
contents += '}\n';
8183

8284
// add module declaration
8385
contents += 'declare module "protractor" {\n';
@@ -104,6 +106,9 @@ var parseTypingsFile = function(folder, file) {
104106
if (line.indexOf('export') !== -1) {
105107
line = line.replace('export', '').trim();
106108
}
109+
if (line.indexOf('declare') !== -1) {
110+
line = line.replace('declare', '').trim();
111+
}
107112

108113
// Remove webdriver types and plugins for now
109114
line = removeTypes(line,'webdriver.ActionSequence');
@@ -115,7 +120,6 @@ var parseTypingsFile = function(folder, file) {
115120
line = removeTypes(line,'Plugins');
116121
contents += line + '\n';
117122
}
118-
119123
}
120124
return contents;
121125
}

scripts/typings_tests/test_fail_browser.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/// <reference path="../../built/index.d.ts" />
2-
import {browser} from 'protractor';
2+
import {Browser} from 'protractor';
3+
let browser: Browser;
34
browser.getProcessedConfig(0);
45
browser.getProcessedConfig('1');
56
browser.getProcessedConfig(true);

scripts/typings_tests/test_fail_by.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
/// <reference path="../../built/index.d.ts" />
2-
import {by, By} from 'protractor';
2+
import {ProtractorBy} from 'protractor';
3+
let by: ProtractorBy;
4+
let By: ProtractorBy;
35
by.addLocator(0, () => {});
46
by.addLocator(() => {}, () => {});
57
by.addLocator('', () => {}, () => {});

scripts/typings_tests/test_fail_elements.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
/// <reference path="../../built/index.d.ts" />
2-
import {element, by, $, $$} from 'protractor';
2+
import {ElementArrayFinder, ElementFinder, ElementHelper, ProtractorBy} from 'protractor';
3+
let element: ElementHelper;
4+
let by: ProtractorBy;
5+
let $: (search: string) => ElementFinder;
6+
let $$: (search: string) => ElementArrayFinder;
37
element.all(by.css('')).clone('clone');
48
element.all(by.css('')).clone(1);
59
element.all(by.css('')).clone(false);

scripts/typings_tests/test_fail_expected_conditions.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/// <reference path="../../built/index.d.ts" />
2-
import {element, by, ExpectedConditions} from 'protractor';
2+
import {ExpectedConditions_} from 'protractor';
3+
let ExpectedConditions: ExpectedConditions_;
34
ExpectedConditions.not(0);
45
ExpectedConditions.not('1');
56
ExpectedConditions.not(true);

scripts/typings_tests/test_pass.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
/// <reference path="../../built/index.d.ts" />
2-
import {browser, element, by, By, $, $$, ExpectedConditions} from 'protractor';
2+
import {Browser, ElementArrayFinder, ElementFinder, ElementHelper, ExpectedConditions_, ProtractorBy} from 'protractor';
3+
let browser: Browser;
4+
let by: ProtractorBy;
5+
let By: ProtractorBy;
6+
let element: ElementHelper;
7+
let $: (search: string) => ElementFinder;
8+
let $$: (search: string) => ElementArrayFinder;
9+
let ExpectedConditions: ExpectedConditions_;
310
element.all(by.css('')).clone();
411
element.all(by.css('')).then(() => {}, () => {}); // this is not appearing on the website
512
element.all(by.css('')).filter(() => {});

scripts/typings_tests/test_typings.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,10 @@ var testPassing = function(file) {
7575

7676

7777
// The tests:
78-
testFailures('test_fail_elements.ts', 3, 478);
79-
testFailures('test_fail_browser.ts', 3, 93);
80-
testFailures('test_fail_expected_conditions.ts', 3, 24);
81-
testFailures('test_fail_by.ts', 3, 207);
78+
testFailures('test_fail_browser.ts', 4, 94);
79+
testFailures('test_fail_by.ts', 5, 209);
80+
testFailures('test_fail_elements.ts', 7, 482);
81+
testFailures('test_fail_expected_conditions.ts', 4, 25);
8282
testPassing('test_pass.ts');
8383

8484
// Test evaluation and exiting:

0 commit comments

Comments
 (0)