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

Commit 5034c89

Browse files
juliemrcnishina
authored andcommitted
feat(typescript): move typescript variable instances from protractor/… (#3565)
Breaking change for TypeScript: Instead of importing globals like `browser` from `protractor/globals`, import from `protractor`. Before: ```ts import {browser, element} from 'protractor/globals'; import {ElementFinder} from 'protractor'; describe('my app', () => { myElement: ElementFinder; beforeEach(() => { browser.get('example.com'); myElement = element(by.css('foo')); }); }); ``` After ```ts import {browser, element, ElementFinder} from 'protractor'; describe('my app', () => { myElement: ElementFinder; beforeEach(() => { browser.get('example.com'); myElement = element(by.css('foo')); }); }); ``` Closes #3564
1 parent 7c124f3 commit 5034c89

File tree

12 files changed

+46
-46
lines changed

12 files changed

+46
-46
lines changed

.gitignore

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,4 @@ npm-debug.log
1414
.idea/
1515

1616
*.swp
17-
globals.js
18-
globals.d.ts
17+

.npmignore

-1
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,3 @@ libpeerconnection.log
1919
npm-debug.log
2020
xmloutput*
2121
release.md
22-
globals.ts

exampleTypescript/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ npm install
4747

4848
## Protractor typings
4949

50-
To use Protractor types, you'll need to import `protractor/globals`. After this is imported, you should have autocompletion hints when typing.
50+
To use Protractor types, you'll need to import `protractor`. After this is imported, you should have autocompletion hints when typing.
5151

5252
```
53-
import {browser, element, by, By, $, $$, ExpectedConditions} from 'protractor/globals';
53+
import {browser, element, by, By, $, $$, ExpectedConditions} from 'protractor';
5454
```
5555

5656
Although the Protractor configuration file can be written in javascript, creating it in typescript will have some hints. These hints and the reference configuration can be found in `lib/config.ts`. Below we are importing the Config interface and applying that interface to the config variable:

exampleTypescript/angularPage.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// import {browser, element, by, By, $, $$, ExpectedConditions}
55
// from 'protractor/globals';
66
//
7-
import {browser, element, by} from 'protractor/globals';
7+
import {browser, element, by} from 'protractor';
88

99
export class AngularHomepage {
1010
nameInput = element(by.model('yourName'));

exampleTypescript/spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// from 'protractor/globals';
66
//
77
// The jasmine typings are brought in via DefinitelyTyped ambient typings.
8-
import {browser, element, by, By, $, $$, ExpectedConditions} from 'protractor/globals';
8+
import {browser, element, by, By, $, $$, ExpectedConditions} from 'protractor';
99

1010
describe('protractor with typescript typings', () => {
1111
beforeEach(() => {

globals.ts

-21
This file was deleted.

gulpfile.js

+2-7
Original file line numberDiff line numberDiff line change
@@ -83,19 +83,14 @@ gulp.task('tsc', function(done) {
8383
runSpawn(done, 'node', ['node_modules/typescript/bin/tsc']);
8484
});
8585

86-
gulp.task('tsc:globals', function(done) {
87-
runSpawn(done, 'node', ['node_modules/typescript/bin/tsc', '-d', 'globals.ts'],
88-
'ignore');
89-
});
90-
9186
gulp.task('prepublish', function(done) {
92-
runSequence('checkVersion', ['jshint', 'format'], 'tsc', 'tsc:globals',
87+
runSequence('checkVersion', ['jshint', 'format'], 'tsc',
9388
'built:copy', done);
9489
});
9590

9691
gulp.task('pretest', function(done) {
9792
runSequence('checkVersion',
98-
['webdriver:update', 'jshint', 'format'], 'tsc', 'tsc:globals',
93+
['webdriver:update', 'jshint', 'format'], 'tsc',
9994
'built:copy', done);
10095
});
10196

lib/index.d.ts

-7
This file was deleted.

lib/index.ts

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/// <reference path="../typings/index.d.ts" />
2+
3+
// TODO: we'd like to remove the triple-slash reference, but it's necessary
4+
// until definitely-typed is updated for selenium-webdriver.
5+
6+
import {ElementHelper, ProtractorBrowser} from './browser';
7+
import {ElementArrayFinder, ElementFinder} from './element';
8+
import {ProtractorExpectedConditions} from './expectedConditions';
9+
import {ProtractorBy} from './locators';
10+
import {Ptor} from './ptor';
11+
12+
// Re-export public types.
13+
export {ElementHelper, ProtractorBrowser} from './browser';
14+
export {Config} from './config';
15+
export {ElementArrayFinder, ElementFinder} from './element';
16+
export {ProtractorExpectedConditions} from './expectedConditions';
17+
export {ProtractorBy} from './locators';
18+
export {Ptor} from './ptor';
19+
20+
// Export API instances based on the global Protractor object.
21+
// We base this on NodeJS `global` because we do not want to mask
22+
// with a different instance of Protractor if the module is
23+
// installed both globally and locally.
24+
export let protractor: Ptor = (global as any)['protractor'];
25+
export let browser: ProtractorBrowser = protractor.browser;
26+
export let $: (search: string) => ElementFinder = protractor.$;
27+
export let $$: (search: string) => ElementArrayFinder = protractor.$$;
28+
export let element: ElementHelper = protractor.element;
29+
export let By: ProtractorBy = protractor.By;
30+
export let by: ProtractorBy = protractor.by;
31+
export let wrapDriver:
32+
(webdriver: any, baseUrl?: string, rootElement?: string,
33+
untrackOutstandingTimeouts?: boolean) => ProtractorBrowser =
34+
protractor.wrapDriver;
35+
export let ExpectedConditions: ProtractorExpectedConditions =
36+
protractor.ExpectedConditions;

spec/install/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ node_modules
22
typings
33
conf.js
44
typescript_spec.js
5+
npm-debug.log

spec/install/typescript_spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import {browser, by, By, element, $, $$, ExpectedConditions, protractor} from 'protractor/globals';
2-
import {ProtractorBrowser} from 'protractor';
1+
import {browser, by, By, element, $, $$, ExpectedConditions, protractor} from 'protractor';
2+
33
describe('typescript imports', () => {
44
it('should have global objects that match the protractor namespace', () => {
55
expect(protractor.browser === browser).toBeTruthy();

tsconfig.json

-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
"testapp",
2121
"website",
2222
"scripts",
23-
"globals.ts",
24-
"globals.d.ts",
2523
"exampleTypescript",
2624
"typings/globals",
2725
"spec"

0 commit comments

Comments
 (0)