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

Commit

Permalink
deps(latest): upgrade to the gulp and typescript (#5089)
Browse files Browse the repository at this point in the history
* deps(latest): upgrade to the gulp and typescript

- add in @types/loglevel and @types/yargs for webdriver-manager
- upgrade tslint clean up for tslint
- use latest gulp 4 and remove run sequence since this feature is
supported by gulp
- remove compile to es5
  • Loading branch information
cnishina committed Mar 23, 2019
1 parent 2def202 commit 509f1b2
Show file tree
Hide file tree
Showing 11 changed files with 3,366 additions and 970 deletions.
98 changes: 41 additions & 57 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,29 @@
'use strict';

var gulp = require('gulp');
var clangFormat = require('clang-format');
var gulpFormat = require('gulp-clang-format');
var runSequence = require('run-sequence');
var spawn = require('child_process').spawn;
var spawnSync = require('child_process').spawnSync;
var tslint = require('gulp-tslint');
var fs = require('fs');
var path = require('path');
var glob = require('glob');
var semver = require('semver');

var runSpawn = function(done, task, opt_arg, opt_io) {
const gulp = require('gulp');
const format = require('gulp-clang-format');
const clangFormat = require('clang-format');
const spawn = require('child_process').spawn;
const tslint = require('gulp-tslint');
const fs = require('fs');
const path = require('path');
const semver = require('semver');

const runSpawn = (done, task, opt_arg, opt_io) => {
opt_arg = typeof opt_arg !== 'undefined' ? opt_arg : [];
var stdio = 'inherit';
const stdio = 'inherit';
if (opt_io === 'ignore') {
stdio = 'ignore';
}
var child = spawn(task, opt_arg, {stdio: stdio});
var running = false;
child.on('close', function() {
const child = spawn(task, opt_arg, {stdio: stdio});
let running = false;
child.on('close', () => {
if (!running) {
running = true;
done();
}
});
child.on('error', function() {
child.on('error', () => {
if (!running) {
console.error('gulp encountered a child error');
running = true;
Expand All @@ -35,21 +32,25 @@ var runSpawn = function(done, task, opt_arg, opt_io) {
});
};

gulp.task('tslint', function() {
gulp.task('tslint', () => {
return gulp.src(['lib/**/*.ts', 'spec/**/*.ts', '!spec/install/**/*.ts'])
.pipe(tslint()).pipe(tslint.report());
.pipe(tslint())
.pipe(tslint.report());
});

gulp.task('lint', function(done) {
runSequence('tslint', 'format:enforce', done);
gulp.task('format:enforce', () => {
return gulp.src(['lib/**/*.ts'])
.pipe(format.checkFormat('file', clangFormat, {verbose: true, fail: true}));
});

gulp.task('lint', gulp.series('tslint', 'format:enforce'));

// prevent contributors from using the wrong version of node
gulp.task('checkVersion', function(done) {
gulp.task('checkVersion', (done) => {
// read minimum node on package.json
var packageJson = JSON.parse(fs.readFileSync(path.resolve('package.json')));
var protractorVersion = packageJson.version;
var nodeVersion = packageJson.engines.node;
const packageJson = JSON.parse(fs.readFileSync(path.resolve('package.json')));
const protractorVersion = packageJson.version;
const nodeVersion = packageJson.engines.node;

if (semver.satisfies(process.version, nodeVersion)) {
done();
Expand All @@ -59,52 +60,35 @@ gulp.task('checkVersion', function(done) {
}
});

gulp.task('built:copy', function() {
gulp.task('built:copy', () => {
return gulp.src(['lib/**/*.js'])
.pipe(gulp.dest('built/'));
});

gulp.task('webdriver:update', function(done) {
gulp.task('webdriver:update', (done) => {
runSpawn(done, 'node', ['bin/webdriver-manager', 'update']);
});

gulp.task('format:enforce', function() {
var format = require('gulp-clang-format');
var clangFormat = require('clang-format');
return gulp.src(['lib/**/*.ts']).pipe(
format.checkFormat('file', clangFormat, {verbose: true, fail: true}));
});

gulp.task('format', function() {
var format = require('gulp-clang-format');
var clangFormat = require('clang-format');
return gulp.src(['lib/**/*.ts'], { base: '.' }).pipe(
format.format('file', clangFormat)).pipe(gulp.dest('.'));
gulp.task('format', () => {
return gulp.src(['lib/**/*.ts'], { base: '.' })
.pipe(format.format('file', clangFormat))
.pipe(gulp.dest('.'));
});

gulp.task('tsc', function(done) {
gulp.task('tsc', (done) => {
runSpawn(done, 'node', ['node_modules/typescript/bin/tsc']);
});

gulp.task('tsc:spec', function(done) {
gulp.task('tsc:spec', (done) => {
runSpawn(done, 'node', ['node_modules/typescript/bin/tsc', '-p', 'ts_spec_config.json']);
});

gulp.task('tsc:es5', function(done) {
runSpawn(done, './scripts/compile_to_es5.sh');
});

gulp.task('compile_to_es5', function(done) {
runSequence('checkVersion', 'tsc:es5', 'built:copy', done);
});
gulp.task('prepublish', gulp.series('checkVersion', 'tsc', 'built:copy'));

gulp.task('prepublish', function(done) {
runSequence('checkVersion', 'tsc', 'built:copy', done);
});
gulp.task('pretest', gulp.series(
'checkVersion',
gulp.parallel('webdriver:update', 'tslint', 'format'),
'tsc', 'built:copy', 'tsc:spec'));

gulp.task('pretest', function(done) {
runSequence('checkVersion',
['webdriver:update', 'tslint', 'format'], 'tsc', 'built:copy', 'tsc:spec', done);
});
gulp.task('default', gulp.series('prepublish'));

gulp.task('default',['prepublish']);
6 changes: 3 additions & 3 deletions lib/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ function ptorMixin(to: any, from: any, fnName: string, setupFn?: Function) {
}
return run();
};
};
}

export interface ElementHelper extends Function {
(locator: Locator): ElementFinder;
Expand All @@ -96,7 +96,7 @@ function buildElementHelper(browser: ProtractorBrowser): ElementHelper {
};

return element;
};
}

/**
* @alias browser
Expand Down Expand Up @@ -725,7 +725,7 @@ export class ProtractorBrowser extends AbstractExtendedWebDriver {
*/
getRegisteredMockModules(): Array<string|Function> {
return this.mockModules_.map(module => module.script);
};
}

/**
* Add the base mock modules used for all Protractor tests.
Expand Down
2 changes: 1 addition & 1 deletion lib/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ function processFilePatterns_(list: string): Array<string> {
return list.split(',').map(function(spec) {
return path.resolve(process.cwd(), spec);
});
};
}

if (argv.specs) {
argv.specs = processFilePatterns_(<string>argv.specs);
Expand Down
4 changes: 2 additions & 2 deletions lib/driverProviders/driverProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export abstract class DriverProvider {
* Default update job method.
* @return a promise
*/
async updateJob(update: any): Promise<any>{};
async updateJob(update: any): Promise<any> {}

/**
* Default setup environment method, common to all driver providers.
Expand All @@ -106,7 +106,7 @@ export abstract class DriverProvider {
if (this.config_.useBlockingProxy && !this.config_.blockingProxyUrl) {
await this.bpRunner.start();
}
};
}

/**
* Set up environment specific to a particular driver provider. Overridden
Expand Down
4 changes: 2 additions & 2 deletions lib/element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ export class ElementArrayFinder extends WebdriverWebElement {
*/
first(): ElementFinder {
return this.get(0);
};
}

/**
* Get the last matching element for the ElementArrayFinder. This does not
Expand Down Expand Up @@ -643,7 +643,7 @@ export class ElementArrayFinder extends WebdriverWebElement {
return await mapResult;
});
return Promise.all(list);
};
}

/**
* Apply a reduce function against an accumulator and every element found
Expand Down
4 changes: 2 additions & 2 deletions lib/expectedConditions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import {falseIfMissing, passBoolean} from './util';
* @constructor
*/
export class ProtractorExpectedConditions {
constructor(public browser: ProtractorBrowser){};
constructor(public browser: ProtractorBrowser) {}

/**
* Negates the result of a promise.
Expand Down Expand Up @@ -351,7 +351,7 @@ export class ProtractorExpectedConditions {
*/
presenceOf(elementFinder: ElementFinder): Function {
return elementFinder.isPresent.bind(elementFinder);
};
}

/**
* An expectation for checking that an element is not attached to the DOM
Expand Down
18 changes: 9 additions & 9 deletions lib/locators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export class ProtractorBy extends WebdriverBy {
}
};
};
};
}

/**
* Find an element by text binding. Does a partial match, so any elements
Expand Down Expand Up @@ -143,7 +143,7 @@ export class ProtractorBy extends WebdriverBy {
return 'by.binding("' + bindingDescriptor + '")';
}
};
};
}

/**
* Find an element by exact binding.
Expand Down Expand Up @@ -177,7 +177,7 @@ export class ProtractorBy extends WebdriverBy {
return 'by.exactBinding("' + bindingDescriptor + '")';
}
};
};
}

/**
* Find an element by ng-model expression.
Expand Down Expand Up @@ -207,7 +207,7 @@ export class ProtractorBy extends WebdriverBy {
return 'by.model("' + model + '")';
}
};
};
}

/**
* Find a button by text.
Expand All @@ -234,7 +234,7 @@ export class ProtractorBy extends WebdriverBy {
return 'by.buttonText("' + searchText + '")';
}
};
};
}

/**
* Find a button by partial text.
Expand All @@ -261,7 +261,7 @@ export class ProtractorBy extends WebdriverBy {
return 'by.partialButtonText("' + searchText + '")';
}
};
};
}

// Generate either by.repeater or by.exactRepeater
private byRepeaterInner(exact: boolean, repeatDescriptor: string): ProtractorLocator {
Expand Down Expand Up @@ -448,7 +448,7 @@ export class ProtractorBy extends WebdriverBy {
return 'by.cssContainingText("' + cssSelector + '", "' + searchText + '")';
}
};
};
}

/**
* Find an element by ng-options expression.
Expand Down Expand Up @@ -482,7 +482,7 @@ export class ProtractorBy extends WebdriverBy {
return 'by.option("' + optionsDescriptor + '")';
}
};
};
}

/**
* Find an element by css selector within the Shadow DOM.
Expand All @@ -509,5 +509,5 @@ export class ProtractorBy extends WebdriverBy {
// TODO(julie): syntax will change from /deep/ to >>> at some point.
// When that is supported, switch it here.
return By.css('* /deep/ ' + selector);
};
}
}
6 changes: 3 additions & 3 deletions lib/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ export class Plugins {
this.pluginObjs.push(pluginObj);
});
}
};
}

/**
* Adds properties to a plugin's object
Expand Down Expand Up @@ -398,7 +398,7 @@ export class Plugins {
this.printPluginResults(results.specResults);
this.resultsReported = true;
return results;
};
}

/**
* Returns true if any loaded plugin has skipAngularStability enabled.
Expand All @@ -408,7 +408,7 @@ export class Plugins {
skipAngularStability() {
const result = this.pluginObjs.some(pluginObj => pluginObj.skipAngularStability);
return result;
};
}

/**
* @see docs/plugins.md#writing-plugins for information on these functions
Expand Down
Loading

0 comments on commit 509f1b2

Please sign in to comment.