Skip to content

Commit a233fdd

Browse files
Merge pull request #53 from angular/master
Update upstream
2 parents ca59d14 + 2939379 commit a233fdd

File tree

6 files changed

+106
-53
lines changed

6 files changed

+106
-53
lines changed

.travis.yml

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,6 @@ env:
1313
- DBUS_SESSION_BUS_ADDRESS=/dev/null
1414

1515

16-
matrix:
17-
allow_failures:
18-
- env: nightly
19-
- env: ng2
20-
- node_js: "7"
21-
- node_js: "8"
22-
23-
2416
matrix:
2517
fast_finish: true
2618
allow_failures:
@@ -40,12 +32,20 @@ matrix:
4032
env: test
4133
- node_js: "6"
4234
os: linux
43-
script: node tests/run_e2e.js "--glob=tests/build/**"
44-
env: build
35+
script: node tests/run_e2e.js "--ignore=**/tests/build/**" --nb-shards=4 --shard=0 --nosilent
36+
env: e2e-0
37+
- node_js: "6"
38+
os: linux
39+
script: node tests/run_e2e.js "--ignore=**/tests/build/**" --nb-shards=4 --shard=1 --nosilent
40+
env: e2e-1
41+
- node_js: "6"
42+
os: linux
43+
script: node tests/run_e2e.js "--ignore=**/tests/build/**" --nb-shards=4 --shard=2 --nosilent
44+
env: e2e-2
4545
- node_js: "6"
4646
os: linux
47-
script: travis_wait 120 node tests/run_e2e.js "--ignore=**/tests/build/**"
48-
env: e2e
47+
script: node tests/run_e2e.js "--ignore=**/tests/build/**" --nb-shards=4 --shard=3 --nosilent
48+
env: e2e-3
4949
- node_js: "6"
5050
os: linux
5151
script: node tests/run_e2e.js --eject "--glob=tests/build/**"
@@ -56,25 +56,34 @@ matrix:
5656
os: linux
5757
script: node tests/run_e2e.js --ng2 "--glob=tests/{build,test,misc}/**"
5858
env: ng2
59+
on:
60+
all_branches: true
5961
- node_js: "6"
6062
os: linux
6163
script: node tests/run_e2e.js "--nightly --glob=tests/{build,test,misc}/**"
6264
env: nightly
65+
on:
66+
all_branches: true
6367
- node_js: "7"
6468
os: linux
6569
script: node tests/run_e2e.js "--glob=tests/{build,test,misc}/**"
6670
env: node7
71+
on:
72+
all_branches: true
6773
- node_js: "8"
6874
os: linux
6975
script: node tests/run_e2e.js "--glob=tests/build/**"
7076
env: node8
77+
on:
78+
all_branches: true
7179

7280
- stage: deploy
7381
script: skip
7482
env: builds
7583
deploy:
7684
- provider: script
7785
script: node scripts/git-builds.js
86+
skip_cleanup: true
7887
on:
7988
all_branches: true
8089
- stage: deploy
@@ -83,6 +92,7 @@ matrix:
8392
deploy:
8493
- provider: script
8594
script: node scripts/publish/publish.js
95+
skip_cleanup: true
8696
on:
8797
tags: true
8898

packages/@angular/cli/plugins/named-lazy-chunks-webpack-plugin.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import * as webpack from 'webpack';
2-
2+
import { basename } from 'path';
3+
const AsyncDependenciesBlock = require('webpack/lib/AsyncDependenciesBlock');
4+
const ContextElementDependency = require('webpack/lib/dependencies/ContextElementDependency');
5+
const ImportDependency = require('webpack/lib/dependencies/ImportDependency');
36

47
// This just extends webpack.NamedChunksPlugin to prevent name collisions.
58
export class NamedLazyChunksWebpackPlugin extends webpack.NamedChunksPlugin {
@@ -22,15 +25,22 @@ export class NamedLazyChunksWebpackPlugin extends webpack.NamedChunksPlugin {
2225
return chunk.name;
2326
}
2427

25-
// Try to figure out if it's a lazy loaded route.
28+
// Try to figure out if it's a lazy loaded route or import().
2629
if (chunk.blocks
2730
&& chunk.blocks.length > 0
28-
&& chunk.blocks[0].dependencies
29-
&& chunk.blocks[0].dependencies.length > 0
30-
&& chunk.blocks[0].dependencies[0].lazyRouteChunkName
31+
&& chunk.blocks[0] instanceof AsyncDependenciesBlock
32+
&& chunk.blocks[0].dependencies.length === 1
33+
&& (chunk.blocks[0].dependencies[0] instanceof ContextElementDependency
34+
|| chunk.blocks[0].dependencies[0] instanceof ImportDependency)
3135
) {
32-
// lazyRouteChunkName was added by @ngtools/webpack.
33-
return getUniqueName(chunk.blocks[0].dependencies[0].lazyRouteChunkName);
36+
// Create chunkname from file request, stripping ngfactory and extension.
37+
const req = chunk.blocks[0].dependencies[0].request;
38+
const chunkName = basename(req).replace(/(\.ngfactory)?\.(js|ts)$/, '');
39+
if (!chunkName || chunkName === '') {
40+
// Bail out if something went wrong with the name.
41+
return null;
42+
}
43+
return getUniqueName(chunkName);
3444
}
3545

3646
return null;

packages/@ngtools/webpack/src/plugin.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -310,11 +310,7 @@ export class AotPlugin implements Tapable {
310310
.map((key) => {
311311
const value = this._lazyRoutes[key];
312312
if (value !== null) {
313-
const dep = new ContextElementDependency(value, key);
314-
// lazyRouteChunkName is used by webpack.NamedChunksPlugin to give the
315-
// lazy loaded chunk a name.
316-
dep.lazyRouteChunkName = path.basename(key, '.ts');
317-
return dep;
313+
return new ContextElementDependency(value, key);
318314
} else {
319315
return null;
320316
}

tests/e2e/tests/misc/lazy-module.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ export default function() {
2828
oldNumberOfFiles = currentNumberOfDistFiles;
2929

3030
if (!distFiles.includes('lazy.module.chunk.js')){
31-
throw new Error('The bundle for the lazy module did not have a name.');
31+
throw new Error('The chunk for the lazy module did not have a name.');
3232
}
3333
if (!distFiles.includes('lazy.module.0.chunk.js')){
34-
throw new Error('The bundle for the lazy module did not use a unique name.');
34+
throw new Error('The chunk for the lazy module did not use a unique name.');
3535
}
3636
})
3737
// verify System.import still works
@@ -43,11 +43,15 @@ export default function() {
4343
System.import('./lazy-' + lazyFile);
4444
`))
4545
.then(() => ng('build'))
46-
.then(() => readdirSync('dist').length)
47-
.then(currentNumberOfDistFiles => {
46+
.then(() => readdirSync('dist'))
47+
.then((distFiles) => {
48+
const currentNumberOfDistFiles = distFiles.length;
4849
if (oldNumberOfFiles >= currentNumberOfDistFiles) {
4950
throw new Error('A bundle for the lazy file was not created.');
5051
}
52+
if (!distFiles.includes('lazy-file.chunk.js')) {
53+
throw new Error('The chunk for the lazy file did not have a name.');
54+
}
5155
oldNumberOfFiles = currentNumberOfDistFiles;
5256
})
5357
// verify 'import *' syntax doesn't break lazy modules

tests/e2e/utils/process.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,12 @@ export function silentExecAndWaitForOutputToMatch(cmd: string, args: string[], m
139139

140140
let npmInstalledEject = false;
141141
export function ng(...args: string[]) {
142+
const argv = getGlobalVariable('argv');
143+
const maybeSilentNg = argv['nosilent'] ? noSilentNg : silentNg;
142144
if (['build', 'serve', 'test', 'e2e', 'xi18n'].indexOf(args[0]) != -1) {
143145
// If we have the --eject, use webpack for the test.
144-
const argv = getGlobalVariable('argv');
145146
if (args[0] == 'build' && argv.eject) {
146-
return silentNg('eject', ...args.slice(1), '--force')
147+
return maybeSilentNg('eject', ...args.slice(1), '--force')
147148
.then(() => {
148149
if (!npmInstalledEject) {
149150
npmInstalledEject = true;
@@ -153,14 +154,22 @@ export function ng(...args: string[]) {
153154
})
154155
.then(() => rimraf('dist'))
155156
.then(() => _exec({silent: true}, 'node_modules/.bin/webpack', []));
157+
} else if (args[0] == 'e2e') {
158+
// Wait 1 second before running any end-to-end test.
159+
return new Promise(resolve => setTimeout(resolve, 1000))
160+
.then(() => maybeSilentNg(...args));
156161
}
157162

158-
return silentNg(...args);
163+
return maybeSilentNg(...args);
159164
} else {
160-
return _exec({}, 'ng', args);
165+
return noSilentNg(...args);
161166
}
162167
}
163168

169+
export function noSilentNg(...args: string[]) {
170+
return _exec({}, 'ng', args);
171+
}
172+
164173
export function silentNg(...args: string[]) {
165174
return _exec({silent: true}, 'ng', args);
166175
}

tests/e2e_runner.ts

Lines changed: 45 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ Error.stackTraceLimit = Infinity;
2828
* --nobuild Skip building the packages. Use with --nolink and --reuse to quickly
2929
* rerun tests.
3030
* --nolink Skip linking your local @angular/cli directory. Can save a few seconds.
31+
* --nosilent Never silence ng commands.
3132
* --ng-sha=SHA Use a specific ng-sha. Similar to nightly but point to a master SHA instead
3233
* of using the latest.
3334
* --glob Run tests matching this glob pattern (relative to tests/e2e/).
@@ -36,11 +37,24 @@ Error.stackTraceLimit = Infinity;
3637
* --reuse=/path Use a path instead of create a new project. That project should have been
3738
* created, and npm installed. Ideally you want a project created by a previous
3839
* run of e2e.
40+
* --nb-shards Total number of shards that this is part of. Default is 2 if --shard is
41+
* passed in.
42+
* --shard Index of this processes' shard.
3943
* If unnamed flags are passed in, the list of tests will be filtered to include only those passed.
4044
*/
4145
const argv = minimist(process.argv.slice(2), {
42-
'boolean': ['debug', 'nolink', 'nightly', 'noproject', 'verbose', 'eject', 'appveyor'],
43-
'string': ['glob', 'ignore', 'reuse', 'ng-sha', ]
46+
'boolean': [
47+
'appveyor',
48+
'debug',
49+
'eject',
50+
'nightly',
51+
'nolink',
52+
'nosilent',
53+
'noproject',
54+
'verbose',
55+
],
56+
'string': ['glob', 'ignore', 'reuse', 'ng-sha', ],
57+
'number': ['nb-shards', 'shard']
4458
});
4559

4660

@@ -73,7 +87,6 @@ ConsoleLoggerStack.start(new IndentLogger('name'))
7387

7488
const testGlob = argv.glob || 'tests/**/*.ts';
7589
let currentFileName = null;
76-
let index = 0;
7790

7891
const e2eRoot = path.join(__dirname, 'e2e');
7992
const allSetups = glob.sync(path.join(e2eRoot, 'setup/**/*.ts'), { nodir: true })
@@ -83,20 +96,26 @@ const allTests = glob.sync(path.join(e2eRoot, testGlob), { nodir: true, ignore:
8396
.map(name => path.relative(e2eRoot, name))
8497
.sort();
8598

86-
const testsToRun = allSetups
87-
.concat(allTests
88-
.filter(name => {
89-
// Check for naming tests on command line.
90-
if (argv._.length == 0) {
91-
return true;
92-
}
99+
const shardId = ('shard' in argv) ? argv['shard'] : null;
100+
const nbShards = (shardId === null ? 1 : argv['nb-shards']) || 2;
101+
const tests = allTests
102+
.filter(name => {
103+
// Check for naming tests on command line.
104+
if (argv._.length == 0) {
105+
return true;
106+
}
107+
108+
return argv._.some(argName => {
109+
return path.join(process.cwd(), argName) == path.join(__dirname, 'e2e', name)
110+
|| argName == name
111+
|| argName == name.replace(/\.ts$/, '');
112+
});
113+
});
93114

94-
return argv._.some(argName => {
95-
return path.join(process.cwd(), argName) == path.join(__dirname, 'e2e', name)
96-
|| argName == name
97-
|| argName == name.replace(/\.ts$/, '');
98-
});
99-
}));
115+
// Remove tests that are not part of this shard.
116+
const shardedTests = tests
117+
.filter((name, i) => (shardId === null || (i % nbShards) == shardId));
118+
const testsToRun = allSetups.concat(shardedTests);
100119

101120

102121
/**
@@ -111,7 +130,7 @@ if (testsToRun.length == allTests.length) {
111130

112131
setGlobalVariable('argv', argv);
113132

114-
testsToRun.reduce((previous, relativeName) => {
133+
testsToRun.reduce((previous, relativeName, testIndex) => {
115134
// Make sure this is a windows compatible path.
116135
let absoluteName = path.join(e2eRoot, relativeName);
117136
if (/^win/.test(process.platform)) {
@@ -131,7 +150,7 @@ testsToRun.reduce((previous, relativeName) => {
131150
let clean = true;
132151
let previousDir = null;
133152
return Promise.resolve()
134-
.then(() => printHeader(currentFileName))
153+
.then(() => printHeader(currentFileName, testIndex))
135154
.then(() => previousDir = process.cwd())
136155
.then(() => ConsoleLoggerStack.push(currentFileName))
137156
.then(() => fn(() => clean = false))
@@ -196,9 +215,14 @@ function isTravis() {
196215
return process.env['TRAVIS'];
197216
}
198217

199-
function printHeader(testName) {
200-
const text = `${++index} of ${testsToRun.length}`;
201-
console.log(green(`Running "${bold(blue(testName))}" (${bold(white(text))})...`));
218+
function printHeader(testName: string, testIndex: number) {
219+
const text = `${testIndex + 1} of ${testsToRun.length}`;
220+
const fullIndex = (testIndex < allSetups.length ? testIndex
221+
: (testIndex - allSetups.length) * nbShards + shardId + allSetups.length) + 1;
222+
const length = tests.length + allSetups.length;
223+
const shard = shardId === null ? ''
224+
: yellow(` [${shardId}:${nbShards}]` + bold(` (${fullIndex}/${length})`));
225+
console.log(green(`Running "${bold(blue(testName))}" (${bold(white(text))}${shard})...`));
202226

203227
if (isTravis()) {
204228
console.log(`travis_fold:start:${encode(testName)}`);

0 commit comments

Comments
 (0)