-
Notifications
You must be signed in to change notification settings - Fork 12k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(e2e): use protractor api (#4527)
Uses existing Protractor API to run it directly instead of using `npm run e2e`. Also adds support for the following flags: `--serve`, `--config`, `--specs`, `--element-explorer`, `--webdriver-update`. Fix #4256 Fix #4478 BREAKING CHANGE: `ng e2e` no longer needs `ng serve` to be running.
- Loading branch information
1 parent
6e3186d
commit 8d2d93a
Showing
12 changed files
with
187 additions
and
78 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
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 |
---|---|---|
@@ -1,26 +1,50 @@ | ||
import * as url from 'url'; | ||
|
||
import { E2eTaskOptions } from '../commands/e2e'; | ||
import { requireProjectModule } from '../utilities/require-project-module'; | ||
const Task = require('../ember-cli/lib/models/task'); | ||
import * as chalk from 'chalk'; | ||
import {exec} from 'child_process'; | ||
|
||
|
||
export const E2eTask = Task.extend({ | ||
run: function () { | ||
const ui = this.ui; | ||
let exitCode = 0; | ||
|
||
return new Promise((resolve) => { | ||
exec(`npm run e2e -- ${this.project.ngConfig.config.e2e.protractor.config}`, | ||
(err: NodeJS.ErrnoException, stdout: string, stderr: string) => { | ||
ui.writeLine(stdout); | ||
if (err) { | ||
ui.writeLine(stderr); | ||
ui.writeLine(chalk.red('Some end-to-end tests failed, see above.')); | ||
exitCode = 1; | ||
} else { | ||
ui.writeLine(chalk.green('All end-to-end tests pass.')); | ||
} | ||
resolve(exitCode); | ||
run: function (e2eTaskOptions: E2eTaskOptions) { | ||
const projectRoot = this.project.root; | ||
const protractorLauncher = requireProjectModule(projectRoot, 'protractor/built/launcher'); | ||
|
||
return new Promise(function () { | ||
let promise = Promise.resolve(); | ||
let additionalProtractorConfig: any = { | ||
elementExplorer: e2eTaskOptions.elementExplorer | ||
}; | ||
|
||
// use serve url as override for protractors baseUrl | ||
if (e2eTaskOptions.serve) { | ||
additionalProtractorConfig.baseUrl = url.format({ | ||
protocol: e2eTaskOptions.ssl ? 'https' : 'http', | ||
hostname: e2eTaskOptions.host, | ||
port: e2eTaskOptions.port.toString() | ||
}); | ||
} | ||
|
||
if (e2eTaskOptions.specs.length !== 0) { | ||
additionalProtractorConfig['specs'] = e2eTaskOptions.specs; | ||
} | ||
|
||
if (e2eTaskOptions.webdriverUpdate) { | ||
// webdriver-manager can only be accessed via a deep import from within | ||
// protractor/node_modules. A double deep import if you will. | ||
const webdriverUpdate = requireProjectModule(projectRoot, | ||
'protractor/node_modules/webdriver-manager/built/lib/cmds/update'); | ||
// run `webdriver-manager update --standalone false --gecko false --quiet` | ||
promise = promise.then(() => webdriverUpdate.program.run({ | ||
standalone: false, | ||
gecko: false, | ||
quiet: true | ||
})); | ||
} | ||
|
||
// Don't call resolve(), protractor will manage exiting the process itself | ||
return promise.then(() => | ||
protractorLauncher.init(e2eTaskOptions.config, additionalProtractorConfig)); | ||
}); | ||
} | ||
}); |
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 |
---|---|---|
@@ -1,8 +1,6 @@ | ||
import * as path from 'path'; | ||
const resolve = require('resolve'); | ||
|
||
// require dependencies within the target project | ||
export function requireDependency(root: string, moduleName: string) { | ||
const packageJson = require(path.join(root, 'node_modules', moduleName, 'package.json')); | ||
const main = path.normalize(packageJson.main); | ||
return require(path.join(root, 'node_modules', moduleName, main)); | ||
export function requireProjectModule(root: string, moduleName: string) { | ||
return require(resolve.sync(moduleName, { basedir: root })); | ||
} |
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
Oops, something went wrong.