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

chore(typescript): clean up file names and do not use export default #3114

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions lib/configParser.ts → lib/config_parser.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {resolve, dirname} from 'path';
import {sync} from 'glob';
import * as path from 'path';
import * as glob from 'glob';
import * as Logger from './logger';

// Coffee is required here to enable config files written in coffee-script.
Expand Down Expand Up @@ -41,7 +41,7 @@ export interface Config {
maxSessions?: number;
}

export default class ConfigParser {
export class ConfigParser {
private config_: Config;
constructor() {
// Default configuration.
Expand Down Expand Up @@ -82,12 +82,12 @@ export default class ConfigParser {

if (patterns) {
for (let fileName of patterns) {
let matches = sync(fileName, {cwd});
let matches = glob.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);
let resolvedPath = path.resolve(cwd, match);
resolvedFiles.push(resolvedPath);
}
}
Expand Down Expand Up @@ -139,7 +139,7 @@ export default class ConfigParser {
if (additionalConfig[name] &&
typeof additionalConfig[name] === 'string') {
additionalConfig[name] =
resolve(relativeTo, additionalConfig[name]);
path.resolve(relativeTo, additionalConfig[name]);
}
});

Expand All @@ -157,14 +157,14 @@ export default class ConfigParser {
if (!filename) {
return this;
}
let filePath = resolve(process.cwd(), filename);
let filePath = path.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);
fileConfig.configDir = path.dirname(filePath);
this.addConfig_(fileConfig, fileConfig.configDir);
} catch (e) {
Logger.error('failed loading configuration file ' + filename);
Expand Down
6 changes: 3 additions & 3 deletions lib/launcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
*/
'use strict';

var ConfigParser = require('./configParser').default,
TaskScheduler = require('./taskScheduler').default,
var ConfigParser = require('./config_parser').ConfigParser,
TaskScheduler = require('./task_scheduler').TaskScheduler,
helper = require('./util'),
log = require('./logger'),
q = require('q'),
TaskRunner = require('./taskRunner').default;
TaskRunner = require('./task_runner').TaskRunner;

var logPrefix = '[launcher]';
var RUNNERS_FAILED_EXIT_CODE = 100;
Expand Down
2 changes: 1 addition & 1 deletion lib/locators.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var util = require('util');
var webdriver = require('selenium-webdriver');

var clientSideScripts = require('./clientsidescripts.js');
var clientSideScripts = require('./clientsidescripts');

/**
* The Protractor Locators. These provide ways of finding elements in
Expand Down
2 changes: 1 addition & 1 deletion lib/logger.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Config} from './configParser';
import {Config} from './config_parser';

/**
* Utility functions for command line output logging from Protractor.
Expand Down
2 changes: 1 addition & 1 deletion lib/plugins.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var webdriver = require('selenium-webdriver'),
q = require('q'),
ConfigParser = require('./configParser').default,
ConfigParser = require('./config_parser').ConfigParser,
log = require('./logger');

var PROMISE_TYPE = {
Expand Down
50 changes: 25 additions & 25 deletions lib/protractor.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ var build$ = require('./element').build$;
var build$$ = require('./element').build$$;
var Plugins = require('./plugins');

var clientSideScripts = require('./clientsidescripts.js');
var clientSideScripts = require('./clientsidescripts');
var ProtractorBy = require('./locators.js').ProtractorBy;
var ExpectedConditions = require('./expectedConditions.js');
var ExpectedConditions = require('./expectedConditions');

// jshint browser: true
/* global angular */
Expand Down Expand Up @@ -96,10 +96,10 @@ var buildElementHelper = function(ptor) {
* @param {string=} opt_baseUrl A base URL to run get requests against.
* @param {string=} opt_rootElement Selector element that has an ng-app in
* scope.
* @param {boolean=} opt_untrackOutstandingTimeouts Whether Protractor should
* @param {boolean=} opt_untrackOutstandingTimeouts Whether Protractor should
* stop tracking outstanding $timeouts.
*/
var Protractor = function(webdriverInstance, opt_baseUrl, opt_rootElement,
var Protractor = function(webdriverInstance, opt_baseUrl, opt_rootElement,
opt_untrackOutstandingTimeouts) {
// These functions should delegate to the webdriver instance, but should
// wait for Angular to sync up before performing the action. This does not
Expand Down Expand Up @@ -215,18 +215,18 @@ var Protractor = function(webdriverInstance, opt_baseUrl, opt_rootElement,
// Safari accepts data urls, but SafariDriver fails after one is used.
// PhantomJS produces a "Detected a page unload event" if we use data urls
var browserName = caps.get('browserName');
if (browserName === 'internet explorer' ||
browserName === 'safari' ||
if (browserName === 'internet explorer' ||
browserName === 'safari' ||
browserName === 'phantomjs') {
self.resetUrl = 'about:blank';
}
});

/**
* If true, Protractor will track outstanding $timeouts and report them in the
* If true, Protractor will track outstanding $timeouts and report them in the
* error message if Protractor fails to synchronize with Angular in time.
* @private {boolean}
*/
*/
this.trackOutstandingTimeouts_ = !opt_untrackOutstandingTimeouts;

/**
Expand Down Expand Up @@ -416,7 +416,7 @@ Protractor.prototype.waitForAngular = function(opt_description) {
pendingTimeoutsPromise = webdriver.promise.fulfilled({});
}
var pendingHttpsPromise = self.executeScript_(
clientSideScripts.getPendingHttpRequests,
clientSideScripts.getPendingHttpRequests,
'Protractor.waitForAngular() - getting pending https' + description,
self.rootEl
);
Expand Down Expand Up @@ -565,7 +565,7 @@ Protractor.prototype.addBaseMockModules_ = function() {
if (!window.NG_PENDING_TIMEOUTS) {
window.NG_PENDING_TIMEOUTS = {};
}

var extendedTimeout = function() {
var args = Array.prototype.slice.call(arguments);
if (typeof(args[0]) !== 'function') {
Expand All @@ -577,12 +577,12 @@ Protractor.prototype.addBaseMockModules_ = function() {
window.NG_PENDING_TIMEOUTS[taskId] = fn.toString();
var wrappedFn = (function(taskId_) {
return function() {
delete window.NG_PENDING_TIMEOUTS[taskId_];
delete window.NG_PENDING_TIMEOUTS[taskId_];
return fn.apply(null, arguments);
};
})(taskId);
args[0] = wrappedFn;

var promise = $timeout.apply(null, args);
promise.ptorTaskId_ = taskId;
return promise;
Expand All @@ -591,15 +591,15 @@ Protractor.prototype.addBaseMockModules_ = function() {
extendedTimeout.cancel = function() {
var taskId_ = arguments[0] && arguments[0].ptorTaskId_;
if (taskId_) {
delete window.NG_PENDING_TIMEOUTS[taskId_];
delete window.NG_PENDING_TIMEOUTS[taskId_];
}
return $timeout.cancel.apply($timeout, arguments);
};

return extendedTimeout;
}]);
}]);
}
}
}, this.trackOutstandingTimeouts_);
};

Expand Down Expand Up @@ -833,14 +833,14 @@ Protractor.prototype.debugger = function() {
};

/**
* Validates that the port is free to use. This will only validate the first
* time it is called. The reason is that on subsequent calls, the port will
* Validates that the port is free to use. This will only validate the first
* time it is called. The reason is that on subsequent calls, the port will
* already be bound to the debugger, so it will not be available, but that is
* okay.
*
* @return {Promise<boolean>} A promise that becomes ready when the validation
* is done. The promise will resolve to a boolean which represents whether
* this is the first time that the debugger is called.
* this is the first time that the debugger is called.
*/
Protractor.prototype.validatePortAvailability_ = function(port) {
if (this.debuggerValidated_) {
Expand All @@ -853,7 +853,7 @@ Protractor.prototype.validatePortAvailability_ = function(port) {
// Resolve doneDeferred if port is available.
var net = require('net');
var tester = net.connect({port: port}, function() {
doneDeferred.reject('Port ' + port +
doneDeferred.reject('Port ' + port +
' is already in use. Please specify ' + 'another port to debug.');
});
tester.once('error', function (err) {
Expand All @@ -863,7 +863,7 @@ Protractor.prototype.validatePortAvailability_ = function(port) {
}).end();
} else {
doneDeferred.reject(
'Unexpected failure testing for port ' + port + ': ' +
'Unexpected failure testing for port ' + port + ': ' +
JSON.stringify(err));
}
});
Expand Down Expand Up @@ -1074,8 +1074,8 @@ Protractor.prototype.enterRepl = function(opt_debugPort) {
var onStartFn = function() {
log.puts();
log.puts('------- Element Explorer -------');
log.puts('Starting WebDriver debugger in a child process. Element ' +
'Explorer is still beta, please report issues at ' +
log.puts('Starting WebDriver debugger in a child process. Element ' +
'Explorer is still beta, please report issues at ' +
'github.com/angular/protractor');
log.puts();
log.puts('Type <tab> to see a list of locator strategies.');
Expand Down Expand Up @@ -1128,12 +1128,12 @@ Protractor.prototype.pause = function(opt_debugPort) {
*
* @param {webdriver.WebDriver} webdriver The configured webdriver instance.
* @param {string=} opt_baseUrl A URL to prepend to relative gets.
* @param {boolean=} opt_untrackOutstandingTimeouts Whether Protractor should
* @param {boolean=} opt_untrackOutstandingTimeouts Whether Protractor should
* stop tracking outstanding $timeouts.
* @return {Protractor}
*/
exports.wrapDriver = function(webdriver, opt_baseUrl, opt_rootElement,
exports.wrapDriver = function(webdriver, opt_baseUrl, opt_rootElement,
opt_untrackOutstandingTimeouts) {
return new Protractor(webdriver, opt_baseUrl, opt_rootElement,
return new Protractor(webdriver, opt_baseUrl, opt_rootElement,
opt_untrackOutstandingTimeouts);
};
2 changes: 1 addition & 1 deletion lib/runnerCli.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* requested by the launcher.
*/

var ConfigParser = require('./configParser').default;
var ConfigParser = require('./config_parser').ConfigParser;
var Runner = require('./runner');
var log = require('./logger');

Expand Down
12 changes: 6 additions & 6 deletions lib/taskLogger.ts → lib/task_logger.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {EOL} from 'os';
import * as os from 'os';
import * as Logger from './logger';

export default class TaskLogger {
export class TaskLogger {
private buffer: string = '';
private insertTag: boolean = true;

Expand All @@ -22,9 +22,9 @@ export default class TaskLogger {
* @private
*/
private logHeader_(): void {
let output = 'PID: ' + this.pid + EOL;
let output = 'PID: ' + this.pid + os.EOL;
if (this.task.specs.length === 1) {
output += 'Specs: ' + this.task.specs.toString() + EOL + EOL;
output += 'Specs: ' + this.task.specs.toString() + os.EOL + os.EOL;
}
this.log(output);
}
Expand All @@ -35,9 +35,9 @@ export default class TaskLogger {
public flush(): void {
if (this.buffer) {
// Flush buffer if nonempty
Logger.print(EOL + '------------------------------------' + EOL);
Logger.print(os.EOL + '------------------------------------' + os.EOL);
Logger.print(this.buffer);
Logger.print(EOL);
Logger.print(os.EOL);
this.buffer = '';
}
}
Expand Down
15 changes: 7 additions & 8 deletions lib/taskRunner.ts → lib/task_runner.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import {fork} from 'child_process';
import {EventEmitter} from 'events';
import {defer, Promise} from 'q';
import {inherits} from 'util';
import * as events from 'events';
import * as q from 'q';

import ConfigParser, {Config} from './configParser';
import {ConfigParser, Config} from './config_parser';
import * as Logger from './logger';
import TaskLogger from './taskLogger';
import {TaskLogger} from './task_logger';

export interface RunResults {
taskId: number;
Expand All @@ -16,7 +15,7 @@ export interface RunResults {
specResults: Array<any>;
}

export default class TaskRunner extends EventEmitter {
export class TaskRunner extends events.EventEmitter {
/**
* A runner for running a specified task (capabilities + specs).
* The TaskRunner can either run the task from the current process (via
Expand All @@ -42,7 +41,7 @@ export default class TaskRunner extends EventEmitter {
* result of the run:
* taskId, specs, capabilities, failedCount, exitCode, specResults
*/
public run(): Promise<any> {
public run(): q.Promise<any> {
let runResults: RunResults = {
taskId: this.task.taskId,
specs: this.task.specs,
Expand All @@ -54,7 +53,7 @@ export default class TaskRunner extends EventEmitter {
};

if (this.runInFork) {
let deferred = defer();
let deferred = q.defer();

let childProcess = fork(
__dirname + '/runnerCli.js', process.argv.slice(2),
Expand Down
5 changes: 2 additions & 3 deletions lib/taskScheduler.ts → lib/task_scheduler.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import ConfigParser, {Config} from './configParser';

import {ConfigParser, Config} from './config_parser';

export interface Task {
capabilities: any;
Expand All @@ -23,7 +22,7 @@ export class TaskQueue {
}
}

export default class TaskScheduler {
export class TaskScheduler {
taskQueues: Array<TaskQueue>;
rotationIndex: number;

Expand Down
2 changes: 1 addition & 1 deletion spec/unit/config_test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var ConfigParser = require('../../built/configParser').default;
var ConfigParser = require('../../built/config_parser').ConfigParser;
var path = require('path');

describe('the config parser', function() {
Expand Down
4 changes: 2 additions & 2 deletions spec/unit/taskScheduler_test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var TaskScheduler = require('../../built/taskScheduler').default;
var ConfigParser = require('../../built/configParser').default;
var TaskScheduler = require('../../built/task_scheduler').TaskScheduler;
var ConfigParser = require('../../built/config_parser').ConfigParser;

describe('the task scheduler', function() {

Expand Down