From 4dcea96b6d2a75dc332874b583fe5e61e8c105a7 Mon Sep 17 00:00:00 2001 From: Foxandxss Date: Fri, 10 Jun 2016 13:50:16 +0200 Subject: [PATCH] chore: better protractor task closes #1641 --- gulpfile.js | 25 +++++++++++-------- .../_examples/cli-quickstart/ts/.gitignore | 1 + .../cli-quickstart/ts/example-config.json | 4 +++ .../cli-quickstart/ts/src/tsconfig.json | 22 ++++++++++++++++ public/docs/_examples/package.json | 2 +- public/docs/_examples/webpack/e2e-spec.ts | 18 +++++++++++++ .../_examples/webpack/ts/example-config.json | 4 +++ 7 files changed, 64 insertions(+), 12 deletions(-) create mode 100644 public/docs/_examples/cli-quickstart/ts/src/tsconfig.json create mode 100644 public/docs/_examples/webpack/e2e-spec.ts diff --git a/gulpfile.js b/gulpfile.js index 2adac97a80..980767129e 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -89,6 +89,8 @@ var _exampleProtractorBoilerplateFiles = [ 'tsconfig.json' ]; +var _exampleConfigFilename = 'example-config.json'; + /** * Run Protractor End-to-End Specs for Doc Samples * Alias for 'run-e2e-tests' @@ -221,18 +223,19 @@ function findAndRunE2eTests(filter, outputFile) { // fileName; then shut down the example. All protractor output is appended // to the outputFile. function runE2eTsTests(appDir, outputFile) { - // spawn tasks to start the app - var appBuildSpawnInfo; - var appRunSpawnInfo; - - if (fs.existsSync(path.join(appDir, 'angular-cli.json'))) { - appBuildSpawnInfo = spawnExt('npm', ['run', 'build:cli'], { cwd: appDir }); - appRunSpawnInfo = spawnExt('npm', ['run', 'http-server:cli', '--', '-s'], { cwd: appDir }); - } else { - appBuildSpawnInfo = spawnExt('npm',['run','tsc'], { cwd: appDir }); - appRunSpawnInfo = spawnExt('npm',['run','http-server:e2e', '--', '-s' ], { cwd: appDir }); + // Grab protractor configuration or defaults to systemjs config. + try { + var exampleConfig = fs.readJsonSync(`${appDir}/${_exampleConfigFilename}`); + } catch (e) { + exampleConfig = { + build: 'tsc', + run: 'http-server:e2e' + }; } + var appBuildSpawnInfo = spawnExt('npm', ['run', exampleConfig.build], { cwd: appDir }); + var appRunSpawnInfo = spawnExt('npm', ['run', exampleConfig.run, '--', '-s'], { cwd: appDir }); + return runProtractor(appBuildSpawnInfo.promise, appDir, appRunSpawnInfo, outputFile); } @@ -841,7 +844,7 @@ function getTypingsPaths(basePath) { function getExamplePaths(basePath, includeBase) { // includeBase defaults to false - return getPaths(basePath, "example-config.json", includeBase) + return getPaths(basePath, _exampleConfigFilename, includeBase) } function getDartExampleWebPaths(basePath) { diff --git a/public/docs/_examples/cli-quickstart/ts/.gitignore b/public/docs/_examples/cli-quickstart/ts/.gitignore index 766f37285b..5df0fe5dc6 100644 --- a/public/docs/_examples/cli-quickstart/ts/.gitignore +++ b/public/docs/_examples/cli-quickstart/ts/.gitignore @@ -36,3 +36,4 @@ Thumbs.db !config/karma.conf.js !config/protractor.conf.js !src/typings.d.ts +!src/tsconfig.json diff --git a/public/docs/_examples/cli-quickstart/ts/example-config.json b/public/docs/_examples/cli-quickstart/ts/example-config.json index e69de29bb2..528f7bd081 100644 --- a/public/docs/_examples/cli-quickstart/ts/example-config.json +++ b/public/docs/_examples/cli-quickstart/ts/example-config.json @@ -0,0 +1,4 @@ +{ + "build": "build:cli", + "run": "http-server:cli" +} diff --git a/public/docs/_examples/cli-quickstart/ts/src/tsconfig.json b/public/docs/_examples/cli-quickstart/ts/src/tsconfig.json new file mode 100644 index 0000000000..7dbff17dfa --- /dev/null +++ b/public/docs/_examples/cli-quickstart/ts/src/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compileOnSave": false, + "compilerOptions": { + "declaration": false, + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "module": "commonjs", + "moduleResolution": "node", + "noEmitOnError": true, + "noImplicitAny": false, + "outDir": "../dist/", + "rootDir": ".", + "sourceMap": true, + "target": "es5", + "inlineSources": true + }, + + "files": [ + "main.ts", + "typings.d.ts" + ] +} diff --git a/public/docs/_examples/package.json b/public/docs/_examples/package.json index f72f1f53e8..7c67a39ac2 100644 --- a/public/docs/_examples/package.json +++ b/public/docs/_examples/package.json @@ -18,7 +18,7 @@ "webdriver:update": "webdriver-manager update", "start:webpack": "webpack-dev-server --inline --progress --port 8080", "test:webpack": "karma start karma.webpack.conf.js", - "build:webpack": "rimraf dist && webpack --config config/webpack.prod.js --progress --profile --bail", + "build:webpack": "rimraf dist && webpack --config config/webpack.prod.js --bail", "build:cli": "ng build" }, "keywords": [], diff --git a/public/docs/_examples/webpack/e2e-spec.ts b/public/docs/_examples/webpack/e2e-spec.ts new file mode 100644 index 0000000000..8e706597f5 --- /dev/null +++ b/public/docs/_examples/webpack/e2e-spec.ts @@ -0,0 +1,18 @@ +/// +describe('QuickStart E2E Tests', function () { + + let expectedMsg = 'Hello from Angular 2 App with Webpack'; + + beforeEach(function () { + browser.get(''); + }); + + it(`should display: ${expectedMsg}`, function () { + expect(element(by.css('h1')).getText()).toEqual(expectedMsg); + }); + + it('should display an image', function () { + expect(element(by.css('img')).isPresent()).toBe(true); + }); + +}); diff --git a/public/docs/_examples/webpack/ts/example-config.json b/public/docs/_examples/webpack/ts/example-config.json index e69de29bb2..9e587f892f 100644 --- a/public/docs/_examples/webpack/ts/example-config.json +++ b/public/docs/_examples/webpack/ts/example-config.json @@ -0,0 +1,4 @@ +{ + "build": "build:webpack", + "run": "http-server:cli" +}