11import { task } from 'gulp' ;
2- import { join } from 'path' ;
3- import { ngcBuildTask , copyTask , execNodeTask , serverTask } from '../util/task_helpers' ;
4- import { copySync } from 'fs-extra' ;
52import { buildConfig , sequenceTask , triggerLivereload , watchFiles } from 'material2-build-tools' ;
3+ import { join } from 'path' ;
4+ import { copyTask , execNodeTask , ngcBuildTask , serverTask } from '../util/task_helpers' ;
65
76// There are no type definitions available for these imports.
87const gulpConnect = require ( 'gulp-connect' ) ;
98
109const { outputDir, packagesDir, projectDir} = buildConfig ;
1110
12- /** Path to the directory where all releases are created. */
13- const releasesDir = join ( outputDir , 'releases' ) ;
14-
1511const appDir = join ( packagesDir , 'e2e-app' ) ;
1612const e2eTestDir = join ( projectDir , 'e2e' ) ;
17- const outDir = join ( outputDir , 'packages' , 'e2e-app' ) ;
1813
19- const PROTRACTOR_CONFIG_PATH = join ( projectDir , 'test/protractor.conf.js' ) ;
20- const tsconfigPath = join ( outDir , 'tsconfig-build.json' ) ;
14+ /**
15+ * The output of the e2e app will preserve the directory structure because otherwise NGC is not
16+ * able to generate factory files for the release output and node modules.
17+ */
18+ const outDir = join ( outputDir , 'src/e2e-app' ) ;
2119
22- /** Glob that matches all files that need to be copied to the output folder. */
23- const assetsGlob = join ( appDir , '**/*.+(html|css| json|ts) ' ) ;
20+ const PROTRACTOR_CONFIG_PATH = join ( projectDir , 'test/protractor.conf.js' ) ;
21+ const tsconfigPath = join ( appDir , 'tsconfig-build. json' ) ;
2422
2523/** Builds and serves the e2e-app and runs protractor once the e2e-app is ready. */
2624task ( 'e2e' , sequenceTask (
@@ -68,12 +66,11 @@ task('e2e-app:build', sequenceTask(
6866 'material-moment-adapter:build-release' ,
6967 'material-examples:build-release'
7068 ] ,
71- [ 'e2e-app:copy-release' , 'e2e-app:copy-assets' ] ,
72- 'e2e-app:build-ts'
69+ [ 'e2e-app:copy-index-html' , 'e2e-app:build-ts' ]
7370) ) ;
7471
75- /** Task that copies all required assets to the output folder . */
76- task ( 'e2e-app:copy-assets ' , copyTask ( assetsGlob , outDir ) ) ;
72+ /** Task that copies the e2e-app index HTML file to the output. */
73+ task ( 'e2e-app:copy-index-html ' , copyTask ( join ( appDir , 'index.html' ) , outDir ) ) ;
7774
7875/** Task that builds the TypeScript sources. Those are compiled inside of the dist folder. */
7976task ( 'e2e-app:build-ts' , ngcBuildTask ( tsconfigPath ) ) ;
@@ -84,13 +81,31 @@ task(':watch:e2eapp', () => {
8481} ) ;
8582
8683/** Ensures that protractor and webdriver are set up to run. */
87- task ( ':test:protractor:setup' , execNodeTask ( 'protractor' , 'webdriver-manager' , [ 'update' ] ) ) ;
84+ task ( ':test:protractor:setup' , execNodeTask (
85+ // Disable download of the gecko selenium driver because otherwise the webdriver
86+ // manager queries GitHub for the latest version and will result in rate limit failures.
87+ 'protractor' , 'webdriver-manager' , [ 'update' , '--gecko' , 'false' ] ) ) ;
8888
8989/** Runs protractor tests (assumes that server is already running. */
9090task ( ':test:protractor' , execNodeTask ( 'protractor' , [ PROTRACTOR_CONFIG_PATH ] ) ) ;
9191
92- /** Starts up the e2e app server. */
93- task ( ':serve:e2eapp' , serverTask ( outDir , false ) ) ;
92+ /** Starts up the e2e app server and rewrites the HTTP requests to properly work with AOT. */
93+ task ( ':serve:e2eapp' , serverTask ( outDir , false , [
94+ // Rewrite each request for .ngfactory files which are outside of the e2e-app to the **actual**
95+ // path. This is necessary because NGC cannot generate factory files for the node modules
96+ // and release output. If we work around it by adding multiple root directories, the directory
97+ // structure would be messed up, so we need to go this way for now (until Ivy).
98+ { from : '^/((?:dist|node_modules)/.*\.ngfactory\.js)$' , to : '/dist/$1' } ,
99+ // Rewrite the node_modules/ and dist/ folder to the real paths. Otherwise we would need
100+ // to copy the required modules to the serve output. If dist/ is explicitly requested, we
101+ // should redirect to the actual dist path because by default we fall back to the e2e output.
102+ { from : '^/node_modules/(.*)$' , to : '/node_modules/$1' } ,
103+ { from : '^/dist/(.*)$' , to : '/dist/$1' } ,
104+ // Rewrite every path that doesn't point to a specific file to the e2e output.
105+ // This is necessary for Angular's routing using the HTML5 History API.
106+ { from : '^/[^.]+$' , to : `/dist/src/e2e-app/index.html` } ,
107+ { from : '^(.*)$' , to : `/dist/src/e2e-app/$1` } ,
108+ ] ) ) ;
94109
95110/** Terminates the e2e app server */
96111task ( ':serve:e2eapp:stop' , gulpConnect . serverClose ) ;
@@ -103,14 +118,3 @@ task('serve:e2eapp', sequenceTask('e2e-app:build', ':serve:e2eapp'));
103118 * This should only be used when running e2e tests locally.
104119 */
105120task ( 'serve:e2eapp:watch' , [ 'serve:e2eapp' , 'material:watch' , ':watch:e2eapp' ] ) ;
106-
107- // As a workaround for https://github.com/angular/angular/issues/12249, we need to
108- // copy the Material and CDK ESM output inside of the demo-app output.
109- task ( 'e2e-app:copy-release' , ( ) => {
110- copySync ( join ( releasesDir , 'cdk' ) , join ( outDir , 'cdk' ) ) ;
111- copySync ( join ( releasesDir , 'material' ) , join ( outDir , 'material' ) ) ;
112- copySync ( join ( releasesDir , 'cdk-experimental' ) , join ( outDir , 'cdk-experimental' ) ) ;
113- copySync ( join ( releasesDir , 'material-experimental' ) , join ( outDir , 'material-experimental' ) ) ;
114- copySync ( join ( releasesDir , 'material-examples' ) , join ( outDir , 'material-examples' ) ) ;
115- copySync ( join ( releasesDir , 'material-moment-adapter' ) , join ( outDir , 'material-moment-adapter' ) ) ;
116- } ) ;
0 commit comments