This repository was archived by the owner on Jul 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(typescript): adding typescript to protractor
Converting a 3 files over to typescript. Adding an `npm prepublish` step that will use gulp to download the typings, transpile the files with tscto the built/ directory and copy the rest of the javascript files from lib/ to the built/ folder. Also adding scripts to package.json for `npm run tsc` and `npm run tsc:w` for transpiling help.
Showing
26 changed files
with
434 additions
and
385 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Language: JavaScript | ||
BasedOnStyle: Google | ||
ColumnLimit: 80 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,52 @@ | ||
'use strict'; | ||
|
||
var gulp = require('gulp'); | ||
var clangFormat = require('clang-format'); | ||
var gulpFormat = require('gulp-clang-format'); | ||
var runSequence = require('run-sequence'); | ||
var spawnSync = require('child_process').spawnSync; | ||
var spawn = require('child_process').spawn; | ||
|
||
var runSpawn = function(done, task, opt_arg) { | ||
var child = spawn(task, opt_arg, {stdio: 'inherit'}); | ||
child.on('close', function() { | ||
done(); | ||
}); | ||
}; | ||
|
||
gulp.task('built:copy', function() { | ||
var srcFiles = ['lib/**/*']; | ||
var dist = 'built/'; | ||
return gulp.src(srcFiles).pipe(gulp.dest(dist)); | ||
return gulp.src(['lib/**/*','!lib/**/*.ts']) | ||
.pipe(gulp.dest('built/')); | ||
}); | ||
|
||
gulp.task('webdriver:update', function(done) { | ||
runSpawn(done, 'bin/webdriver-manager', ['update']); | ||
}); | ||
|
||
gulp.task('jslint', function(done) { | ||
runSpawn(done, './node_modules/.bin/jshint', ['lib','spec', 'scripts']); | ||
}); | ||
|
||
gulp.task('clang', function() { | ||
return gulp.src(['lib/**/*.ts']) | ||
.pipe(gulpFormat.checkFormat('file', clangFormat)) | ||
.on('warning', function(e) { | ||
console.log(e); | ||
}); | ||
}); | ||
|
||
gulp.task('typings', function(done) { | ||
runSpawn(done, 'node_modules/.bin/typings', ['install']); | ||
}); | ||
|
||
gulp.task('webdriver:update', function() { | ||
var child = spawnSync('bin/webdriver-manager', ['update']); | ||
if (child.stdout != null) { | ||
console.log(child.stdout.toString()); | ||
} | ||
if (child.status !== 0) { | ||
throw new Error('webdriver-manager update: child error'); | ||
} | ||
gulp.task('tsc', function(done) { | ||
runSpawn(done, 'node_modules/typescript/bin/tsc'); | ||
}); | ||
|
||
gulp.task('jslint', function() { | ||
var child = spawnSync('./node_modules/.bin/jshint', ['lib','spec', 'scripts']); | ||
if (child != null && child.stdout != null ) { | ||
console.log(child.stdout.toString()); | ||
} | ||
if (child.status !== 0) { | ||
throw new Error('jslint: child error'); | ||
} | ||
gulp.task('prepublish', function(done) { | ||
runSequence(['typings', 'jslint', 'clang'],'tsc', 'built:copy', done); | ||
}); | ||
|
||
gulp.task('pretest', function() { | ||
gulp.task('pretest', function(done) { | ||
runSequence( | ||
['webdriver:update', 'jslint'], | ||
'built:copy' | ||
); | ||
['webdriver:update', 'typings', 'jslint', 'clang'], 'tsc', 'built:copy', done); | ||
}); | ||
gulp.task('prepublish', ['built:copy']); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,239 @@ | ||
import {resolve, dirname} from 'path'; | ||
import {sync} from 'glob'; | ||
import * as Logger from './logger'; | ||
|
||
// Coffee is required here to enable config files written in coffee-script. | ||
try { | ||
require('coffee-script').register(); | ||
} catch (e) { | ||
// Intentionally blank - ignore if coffee-script is not available. | ||
} | ||
|
||
// LiveScript is required here to enable config files written in LiveScript. | ||
try { | ||
require('LiveScript'); | ||
} catch (e) { | ||
// Intentionally blank - ignore if LiveScript is not available. | ||
} | ||
|
||
export interface Config { | ||
specs: Array<string>; | ||
multiCapabilities: Array<any>; | ||
rootElement: string; | ||
allScriptsTimeout: number; | ||
getPageTimeout: number; | ||
params: any; | ||
framework: string; | ||
jasmineNodeOpts: {showColors: boolean; defaultTimeoutInterval: number;}; | ||
seleniumArgs: Array<any>; | ||
seleniumSessionId?: string; | ||
mochaOpts: {ui: string; reporter: string;}; | ||
chromeDriver?: string; | ||
configDir: string; | ||
plugins: Array<any>; | ||
skipSourceMapSupport: boolean; | ||
suite?: string; | ||
suites?: any; | ||
troubleshoot?: boolean; | ||
} | ||
|
||
export default class ConfigParser { | ||
private config_: Config; | ||
constructor() { | ||
// Default configuration. | ||
this.config_ = { | ||
specs: [], | ||
multiCapabilities: [], | ||
rootElement: 'body', | ||
allScriptsTimeout: 11000, | ||
getPageTimeout: 10000, | ||
params: {}, | ||
framework: 'jasmine', | ||
jasmineNodeOpts: {showColors: true, defaultTimeoutInterval: (30 * 1000)}, | ||
seleniumArgs: [], | ||
mochaOpts: {ui: 'bdd', reporter: 'list'}, | ||
configDir: './', | ||
plugins: [], | ||
skipSourceMapSupport: false, | ||
}; | ||
} | ||
|
||
/** | ||
* Resolve a list of file patterns into a list of individual file paths. | ||
* | ||
* @param {Array.<string> | string} patterns | ||
* @param {=boolean} opt_omitWarnings Whether to omit did not match warnings | ||
* @param {=string} opt_relativeTo Path to resolve patterns against | ||
* | ||
* @return {Array} The resolved file paths. | ||
*/ | ||
public static resolveFilePatterns( | ||
patterns: Array<string>| string, opt_omitWarnings?: boolean, | ||
opt_relativeTo?: string): Array<string> { | ||
let resolvedFiles: Array<string> = []; | ||
let cwd = opt_relativeTo || process.cwd(); | ||
|
||
patterns = (typeof patterns === 'string') ? [patterns] : patterns; | ||
|
||
if (patterns) { | ||
for (let fileName of patterns) { | ||
let matches = sync(fileName, {cwd}); | ||
if (!matches.length && !opt_omitWarnings) { | ||
Logger.warn('pattern ' + fileName + ' did not match any files.'); | ||
} | ||
for (let match of matches) { | ||
let resolvedPath = resolve(cwd, match); | ||
resolvedFiles.push(resolvedPath); | ||
} | ||
} | ||
} | ||
return resolvedFiles; | ||
} | ||
|
||
/** | ||
* Returns only the specs that should run currently based on `config.suite` | ||
* | ||
* @return {Array} An array of globs locating the spec files | ||
*/ | ||
static getSpecs(config: Config): Array<string> { | ||
let specs: Array<string> = []; | ||
if (config.suite) { | ||
config.suite.split(',').forEach((suite) => { | ||
let suiteList = config.suites[suite]; | ||
if (suiteList == null) { | ||
throw new Error('Unknown test suite: ' + suite); | ||
} | ||
union(specs, makeArray(suiteList)); | ||
}); | ||
return specs; | ||
} | ||
|
||
if (config.specs.length > 0) { | ||
return config.specs; | ||
} | ||
|
||
Object.keys(config.suites || {}).forEach((suite) => { | ||
union(specs, makeArray(config.suites[suite])); | ||
}); | ||
return specs; | ||
} | ||
|
||
/** | ||
* Add the options in the parameter config to this runner instance. | ||
* | ||
* @private | ||
* @param {Object} additionalConfig | ||
* @param {string} relativeTo the file path to resolve paths against | ||
*/ | ||
private addConfig_(additionalConfig: any, relativeTo: string): void { | ||
// All filepaths should be kept relative to the current config location. | ||
// This will not affect absolute paths. | ||
['seleniumServerJar', 'chromeDriver', 'onPrepare', 'firefoxPath', | ||
'frameworkPath'] | ||
.forEach((name) => { | ||
if (additionalConfig[name] && | ||
typeof additionalConfig[name] === 'string') { | ||
additionalConfig[name] = | ||
resolve(relativeTo, additionalConfig[name]); | ||
} | ||
}); | ||
|
||
merge_(this.config_, additionalConfig); | ||
} | ||
|
||
/** | ||
* Public function specialized towards merging in a file's config | ||
* | ||
* @public | ||
* @param {String} filename | ||
*/ | ||
public addFileConfig(filename: string): ConfigParser { | ||
try { | ||
if (!filename) { | ||
return this; | ||
} | ||
let filePath = resolve(process.cwd(), filename); | ||
let fileConfig = require(filePath).config; | ||
if (!fileConfig) { | ||
Logger.error( | ||
'configuration file ' + filename + ' did not export a config ' + | ||
'object'); | ||
} | ||
fileConfig.configDir = dirname(filePath); | ||
this.addConfig_(fileConfig, fileConfig.configDir); | ||
} catch (e) { | ||
Logger.error('failed loading configuration file ' + filename); | ||
throw e; | ||
} | ||
return this; | ||
} | ||
|
||
/** | ||
* Public function specialized towards merging in config from argv | ||
* | ||
* @public | ||
* @param {Object} argv | ||
*/ | ||
public addConfig(argv: any): ConfigParser { | ||
this.addConfig_(argv, process.cwd()); | ||
return this; | ||
} | ||
|
||
/** | ||
* Public getter for the final, computed config object | ||
* | ||
* @public | ||
* @return {Object} config | ||
*/ | ||
public getConfig(): Config { return this.config_; } | ||
} | ||
|
||
/** | ||
* Merge config objects together. | ||
* | ||
* @private | ||
* @param {Object} into | ||
* @param {Object} from | ||
* | ||
* @return {Object} The 'into' config. | ||
*/ | ||
let merge_ = function(into: any, from: any): any { | ||
for (let key in from) { | ||
if (into[key] instanceof Object && !(into[key] instanceof Array) && | ||
!(into[key] instanceof Function)) { | ||
merge_(into[key], from[key]); | ||
} else { | ||
// console.log(from[key].toString()); | ||
into[key] = from[key]; | ||
} | ||
} | ||
return into; | ||
}; | ||
|
||
/** | ||
* Returns the item if it's an array or puts the item in an array | ||
* if it was not one already. | ||
*/ | ||
let makeArray = function(item: any): any { | ||
return Array.isArray(item) ? item : [item]; | ||
}; | ||
|
||
/** | ||
* Adds to an array all the elements in another array without adding any | ||
* duplicates | ||
* | ||
* @param {Array<string>} dest The array to add to | ||
* @param {Array<string>} src The array to copy from | ||
*/ | ||
let union = function(dest: Array<string>, src: Array<string>): void { | ||
let elems: any = {}; | ||
for (let key in dest) { | ||
elems[dest[key]] = true; | ||
} | ||
for (let key in src) { | ||
if (!elems[src[key]]) { | ||
dest.push(src[key]); | ||
elems[src[key]] = true; | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import {Promise, when} from 'q'; | ||
import {resolve} from 'path'; | ||
|
||
let STACK_SUBSTRINGS_TO_FILTER = [ | ||
'node_modules/jasmine/', 'node_modules/selenium-webdriver', 'at Module.', | ||
'at Object.Module.', 'at Function.Module', '(timers.js:', | ||
'jasminewd2/index.js', 'protractor/lib/' | ||
]; | ||
|
||
|
||
/** | ||
* Utility function that filters a stack trace to be more readable. It removes | ||
* Jasmine test frames and webdriver promise resolution. | ||
* @param {string} text Original stack trace. | ||
* @return {string} | ||
*/ | ||
export function filterStackTrace(text: string): string { | ||
if (!text) { | ||
return text; | ||
} | ||
let lines = text.split(/\n/).filter((line) => { | ||
for (let filter of STACK_SUBSTRINGS_TO_FILTER) { | ||
if (line.indexOf(filter) !== -1) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
}); | ||
return lines.join('\n'); | ||
} | ||
|
||
/** | ||
* Internal helper for abstraction of polymorphic filenameOrFn properties. | ||
* @param {object} filenameOrFn The filename or function that we will execute. | ||
* @param {Array.<object>}} args The args to pass into filenameOrFn. | ||
* @return {q.Promise} A promise that will resolve when filenameOrFn completes. | ||
*/ | ||
export function runFilenameOrFn_( | ||
configDir: string, filenameOrFn: any, args: Array<any>): Promise<any> { | ||
return Promise((resolvePromise) => { | ||
if (filenameOrFn && | ||
!(typeof filenameOrFn === 'string' || | ||
typeof filenameOrFn === 'function')) { | ||
throw 'filenameOrFn must be a string or function'; | ||
} | ||
|
||
if (typeof filenameOrFn === 'string') { | ||
filenameOrFn = require(resolve(configDir, filenameOrFn)); | ||
} | ||
if (typeof filenameOrFn === 'function') { | ||
let results = when(filenameOrFn.apply(null, args), null, (err) => { | ||
err.stack = exports.filterStackTrace(err.stack); | ||
throw err; | ||
}); | ||
resolvePromise(results); | ||
} else { | ||
resolvePromise(undefined); | ||
} | ||
}); | ||
} | ||
|
||
/** | ||
* Joins two logs of test results, each following the format of <framework>.run | ||
* @param {object} log1 | ||
* @param {object} log2 | ||
* @return {object} The joined log | ||
*/ | ||
export function joinTestLogs(log1: any, log2: any): any { | ||
return { | ||
failedCount: log1.failedCount + log2.failedCount, | ||
specResults: (log1.specResults || []).concat(log2.specResults || []) | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es5", | ||
"module": "commonjs", | ||
"moduleResolution": "node", | ||
"sourceMap": false, | ||
"declaration": true, | ||
"removeComments": false, | ||
"noImplicitAny": false, | ||
"outDir": "built/" | ||
}, | ||
"exclude": [ | ||
"built", | ||
"node_modules", | ||
"testapp", | ||
"typings/browser", | ||
"typings/browser.d.ts", | ||
"typings/main" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"ambientDependencies": { | ||
"Q": "github:DefinitelyTyped/DefinitelyTyped/q/Q.d.ts#717a5fdb079f8dd7c19f1b22f7f656dd990f0ccf", | ||
"node": "github:DefinitelyTyped/DefinitelyTyped/node/node.d.ts#c2939250ec2d1ecdc82fce62afb9354dd14909ea", | ||
"glob": "github:DefinitelyTyped/DefinitelyTyped/glob/glob.d.ts#c2939250ec2d1ecdc82fce62afb9354dd14909ea", | ||
"minimatch": "github:DefinitelyTyped/DefinitelyTyped/minimatch/minimatch.d.ts#c2939250ec2d1ecdc82fce62afb9354dd14909ea" | ||
} | ||
} |