diff --git a/e2e/_screenshot.js b/e2e/_screenshot.js deleted file mode 100644 index 335ad58a5d5f..000000000000 --- a/e2e/_screenshot.js +++ /dev/null @@ -1,98 +0,0 @@ -"use strict"; - -const path = require('path'); -const child_process = require('child_process'); -const mapnik = require('mapnik'); - -const SHA = process.env.TRAVIS_COMMIT; -const LFS_BASE_URL = 'https://media.githubusercontent.com/media/angular/material2'; - -/** - * Generates a screenshot from the current state of the Protractor test and compares it to the - * previous stored screenshot. If the screenshots do not match or if no existing screenshot is - * found, an error will be thrown. In both cases, the new screenshot will be stored so that it can - * be added to git. - */ -class Screenshot { - /** - * The filename used to store the screenshot - * @returns {string} - */ - get filename() { - return this.id - .toLowerCase() - .replace(/[ :\/]/g, '_') - .replace(/[^/a-z0-9_]+/g, '') - + '.screenshot.png'; - } - - /** - * The full path to the screenshot - * @returns {string} - */ - get path() { - return path.resolve(__dirname, '..', 'screenshots', this.filename); - } - - /** - * @param {string} id A unique identifier used for the screenshot - */ - constructor(id) { - this.id = id; - this.url = `${LFS_BASE_URL}/${SHA}/screenshots/${this.filename}`; - browser.takeScreenshot().then(png => this.storeScreenshot(png)); - } - - /** - * Stores a local copy of the screenshot for future comparison - * @param {string} png The base64-encoded screenshot generated from the current browser state - */ - storeScreenshot(png) { - console.info(`[STATUS] Generated new screenshot for "${this.id}"`); - this.png = mapnik.Image.fromBytes(new Buffer(png, 'base64')); - if (SHA) { - this.downloadFromGithub(); - } else { - this.compareScreenshots(); - } - } - - /** - * Since we are using `git-lfs`, screenshots are not necessarily available within our local - * directory. To get around this, we download the latest screenshot from Github. - */ - downloadFromGithub() { - console.info(`[STATUS] Downloading screenshot from Github: ${this.url} => ${this.path}`); - child_process.execSync(`curl ${this.url} > "${this.path}"`); - this.compareScreenshots(); - } - - /** - * Compares the generated screenshot to the existing screenshot. If it does not match, an error - * will be thrown. - */ - compareScreenshots() { - console.info(`[STATUS] Comparing screenshots`); - try { - let referenceScreenshot = mapnik.Image.open(this.path); - this.overwriteExistingScreenshot(); - if (referenceScreenshot.compare(this.png)) { - throw `screenshot "${this.id}" has changed.`; - } else { - console.info('[STATUS] Screenshot has not changed'); - } - } catch (e) { - console.info('[STATUS] Unable to manually load screenshot, skipping comparison'); - } - } - - /** - * Replaces the existing screenshot with the newly generated one. - */ - overwriteExistingScreenshot() { - console.info(`[STATUS] Saving new screenshot`); - this.png.save(this.path); - } -} - -module.exports = (id) => new Screenshot(id); \ No newline at end of file diff --git a/e2e/index.e2e.js b/e2e/index.e2e.js index e35e89e41291..a996617b7a10 100644 --- a/e2e/index.e2e.js +++ b/e2e/index.e2e.js @@ -1,5 +1,3 @@ -const screenshot = require('./_screenshot.js'); - describe('hello, protractor', function () { describe('index', function () { browser.get('/'); diff --git a/package.json b/package.json index 4109a4de647d..ae1566bcd647 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "tslint": "tslint -c tslint.json 'src/**/*.ts'", "typings": "typings install --ambient", "postinstall": "npm run typings", - "e2e": "protractor ./protractor.conf.js", + "e2e": "protractor test/protractor.conf.js", "inline-resources": "gulp inline-resources" }, "version": "2.0.0-alpha.1", @@ -27,8 +27,6 @@ "angular2": "2.0.0-beta.12", "es6-promise": "^3.0.2", "es6-shim": "^0.35.0", - "mapnik": "^3.5.2", - "protractor": "^3.1.1", "reflect-metadata": "0.1.2", "rxjs": "5.0.0-beta.2", "systemjs": "0.19.4", @@ -60,6 +58,7 @@ "karma-firefox-launcher": "^0.1.7", "karma-jasmine": "^0.3.6", "karma-sauce-launcher": "^0.2.14", + "protractor": "^3.1.1", "strip-ansi": "^3.0.0", "symlink-or-copy": "^1.0.1", "ts-node": "^0.5.5", diff --git a/protractor.conf.js b/protractor.conf.js deleted file mode 100644 index b42c5f3acceb..000000000000 --- a/protractor.conf.js +++ /dev/null @@ -1,15 +0,0 @@ -var key = require('./scripts/sauce/sauce_config.js'); - -exports.config = { - useAllAngular2AppRoots: true, - specs: [ './e2e/**/*.e2e.js' ], - baseUrl: 'http://localhost:4200', - sauceUser: process.env.SAUCE_USERNAME, - sauceKey: key, - capabilities: { - 'browserName': 'chrome', - 'tunnel-identifier': process.env.TRAVIS_JOB_NUMBER, - 'build': process.env.TRAVIS_JOB_NUMBER, - 'name': 'Material 2 E2E Tests' - } -}; diff --git a/test/protractor.conf.js b/test/protractor.conf.js new file mode 100644 index 000000000000..c48e62c29db4 --- /dev/null +++ b/test/protractor.conf.js @@ -0,0 +1,27 @@ +/** + * This file is Node ES6 and will not be translated to Dart. + */ +const path = require('path'); + +const E2E_BASE_URL = process.env['E2E_BASE_URL'] || 'http://localhost:4200'; +const config = { + useAllAngular2AppRoots: true, + specs: [ path.join(__dirname, '../e2e/**/*.e2e.js') ], + baseUrl: E2E_BASE_URL +}; + + +if (process.env['TRAVIS'] !== undefined) { + const key = require('../scripts/sauce/sauce_config'); + config.sauceUser = process.env['SAUCE_USERNAME']; + config.sauceKey = key; + config.capabilities = { + 'browserName': 'chrome', + 'tunnel-identifier': process.env['TRAVIS_JOB_NUMBER'], + 'build': process.env['TRAVIS_JOB_NUMBER'], + 'name': 'Material 2 E2E Tests' + }; +} + + +exports.config = config;