Skip to content

Commit c395f2d

Browse files
filipesilvaDanny Blue
authored and
Danny Blue
committed
fix(test): correctly report packages spec failures (angular#2238)
1 parent ff8241b commit c395f2d

9 files changed

+14
-13
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"build": "node ./scripts/publish/build.js",
1313
"build:patch": "node ./scripts/patch.js",
1414
"build:packages": "for PKG in packages/*; do echo Building $PKG...; tsc -p $PKG; done",
15-
"test": "npm run test:packages && npm run test:cli",
15+
"test": "npm-run-all -c test:packages test:cli",
1616
"e2e": "npm run test:e2e",
1717
"e2e:nightly": "node tests/e2e_runner.js --nightly",
1818
"mobile_test": "mocha tests/e2e/e2e_workflow.spec.js",

packages/ast-tools/src/ast-utils.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,8 @@ function _addSymbolToNgModuleMetadata(ngModulePath: string, metadataField: strin
222222
position = node.getEnd();
223223
// Get the indentation of the last element, if any.
224224
const text = node.getFullText(source);
225-
if (text.startsWith('\n')) {
226-
toInsert = `,${text.match(/^\n(\r?)\s+/)[0]}${metadataField}: [${symbolName}]`;
225+
if (text.match('^\r?\r?\n')) {
226+
toInsert = `,${text.match(/^\r?\n\s+/)[0]}${metadataField}: [${symbolName}]`;
227227
} else {
228228
toInsert = `, ${metadataField}: [${symbolName}]`;
229229
}
@@ -235,8 +235,8 @@ function _addSymbolToNgModuleMetadata(ngModulePath: string, metadataField: strin
235235
} else {
236236
// Get the indentation of the last element, if any.
237237
const text = node.getFullText(source);
238-
if (text.startsWith('\n')) {
239-
toInsert = `,${text.match(/^\n(\r?)\s+/)[0]}${symbolName}`;
238+
if (text.match(/^\r?\n/)) {
239+
toInsert = `,${text.match(/^\r?\n(\r?)\s+/)[0]}${symbolName}`;
240240
} else {
241241
toInsert = `, ${symbolName}`;
242242
}

packages/ast-tools/src/route-utils.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ export default [\n { path: 'new-route', component: NewRouteComponent }\n];`);
293293
`\nexport default [\n` +
294294
` { path: 'home', component: HomeComponent,\n` +
295295
` children: [\n` +
296-
` { path: 'about/:id', component: AboutComponent } ` +
296+
` { path: 'about/:id', component: AboutComponent }` +
297297
`\n ]\n }\n];`);
298298
});
299299
});

packages/ast-tools/src/route-utils.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -416,11 +416,11 @@ function addChildPath (parentObject: ts.Node, pathOptions: any, route: string) {
416416
if (childrenNode.length !== 0) {
417417
// add to beginning of children array
418418
pos = childrenNode[0].getChildAt(2).getChildAt(1).pos; // open bracket
419-
newContent = `\n${spaces}${content}, `;
419+
newContent = `\n${spaces}${content},`;
420420
} else {
421421
// no children array, add one
422422
pos = parentObject.getChildAt(2).pos; // close brace
423-
newContent = `,\n${spaces.substring(2)}children: [\n${spaces}${content} ` +
423+
newContent = `,\n${spaces.substring(2)}children: [\n${spaces}${content}` +
424424
`\n${spaces.substring(2)}]\n${spaces.substring(5)}`;
425425
}
426426
return {newContent: newContent, pos: pos};

scripts/run-packages-spec.js

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ const projectBaseDir = path.join(__dirname, '../packages');
1414
const jasmine = new Jasmine({ projectBaseDir: projectBaseDir });
1515
jasmine.loadConfig({});
1616
jasmine.addReporter(new JasmineSpecReporter());
17+
// Manually set exit code (needed with custom reporters)
18+
jasmine.onComplete((success) => process.exitCode = !success);
1719

1820
// Run the tests.
1921
const allTests =

tests/acceptance/generate-class.spec.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ describe('Acceptance: ng generate class', function () {
1717
after(conf.restore);
1818

1919
beforeEach(function () {
20+
this.timeout(10000);
2021
return tmp.setup('./tmp').then(function () {
2122
process.chdir('./tmp');
2223
}).then(function () {
@@ -25,8 +26,6 @@ describe('Acceptance: ng generate class', function () {
2526
});
2627

2728
afterEach(function () {
28-
this.timeout(10000);
29-
3029
return tmp.teardown('./tmp');
3130
});
3231

tests/acceptance/generate-component.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ describe('Acceptance: ng generate component', function () {
4343
.then(content => {
4444
// Expect that the app.module contains a reference to my-comp and its import.
4545
expect(content).matches(/import.*MyCompComponent.*from '.\/my-comp\/my-comp.component';/);
46-
expect(content).matches(/declarations:\s*\[[^\]]+?,\n\s+MyCompComponent\n/m);
46+
expect(content).matches(/declarations:\s*\[[^\]]+?,\r?\n\s+MyCompComponent\r?\n/m);
4747
});
4848
});
4949

tests/acceptance/generate-directive.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ describe('Acceptance: ng generate directive', function () {
5151
.then(() => readFile(appModulePath, 'utf-8'))
5252
.then(content => {
5353
expect(content).matches(/import.*\bMyDirDirective\b.*from '.\/my-dir\/my-dir.directive';/);
54-
expect(content).matches(/declarations:\s*\[[^\]]+?,\n\s+MyDirDirective\n/m);
54+
expect(content).matches(/declarations:\s*\[[^\]]+?,\r?\n\s+MyDirDirective\r?\n/m);
5555
});
5656
});
5757

tests/acceptance/generate-pipe.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ describe('Acceptance: ng generate pipe', function () {
4444
.then(() => readFile(appModulePath, 'utf-8'))
4545
.then(content => {
4646
expect(content).matches(/import.*\bMyPipePipe\b.*from '.\/my-pipe.pipe';/);
47-
expect(content).matches(/declarations:\s*\[[^\]]+?,\n\s+MyPipePipe\n/m);
47+
expect(content).matches(/declarations:\s*\[[^\]]+?,\r?\n\s+MyPipePipe\r?\n/m);
4848
});
4949
});
5050

0 commit comments

Comments
 (0)