Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(new): include routing in spec and inline template when called with --routing #3252

Merged
merged 3 commits into from
Dec 1, 2016

Conversation

Meligy
Copy link
Contributor

@Meligy Meligy commented Nov 23, 2016

Closes #3331

This is kind-of missed work from #2794.

In that other PR, we prevented a browser error that happens when a user just runs:

ng new sample --routing
cd sample
ng serve

This works great now after #2794 was cherry picked.
However, there were 2 missing items:

  • ng test fails
    Because the app.component has <router-outlet>, but the test does not import a routing module
  • The browser error still comes if you use --inline-template with ng new --routing
    Because we only fixed app.component.html, but not the actual template in app.component.ts

This PR addresses these 2 issues.

Tests

I am really keen to add some tests to this PR.
Acceptance tests are not applicable here because they only check created files not file content, and I could not find any E2E tests for ng new that I could use for inspiration, or I could extend to cover this scenario.

Update: Thanks Hans for guidance. Tests were added.

@Meligy Meligy force-pushed the fix/new-routing-inline-spec branch 2 times, most recently from d0e7918 to da5823e Compare November 23, 2016 14:05
@Meligy Meligy changed the title fix(ng new): include routing in spec and inline component template when using --routing flag fix(new): include routing in spec and inline template when called with --routing Nov 23, 2016
Copy link
Contributor

@hansl hansl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just one nit to add.

TestBed.configureTestingModule({<% if (routing) { %>
imports: [
RouterTestingModule
],<% } %>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While we're fixing this, can you add a compileComponents call in here as well?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks.

@hansl
Copy link
Contributor

hansl commented Nov 23, 2016

Oh and before I forget, seems like we missed this because we're missing an e2e test. Could you add one?

@Meligy
Copy link
Contributor Author

Meligy commented Nov 25, 2016

@hansl I attempted to add an e2e test for ng new. It's very hard because all e2e tests share a parent project that's a special variation of ng new. Let me know what you think of it.

@Meligy Meligy force-pushed the fix/new-routing-inline-spec branch 2 times, most recently from 2bea7bc to 06f85cb Compare November 25, 2016 18:27
@Meligy
Copy link
Contributor Author

Meligy commented Nov 25, 2016

I made the test specific for ng new --routing, since just ng new is kinda tested in all the tests (because it's called in setup. I say kinda because it's with specific non-default arguments but still). Also, this makes it more relevant to what the PR addresses.

Copy link
Contributor

@hansl hansl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some more comments.

@@ -57,6 +57,27 @@ export function createDir(path: string) {
_recursiveMkDir(path);
}

export function deleteDir(path: string) {
return Promise.resolve()
.then(() => _recursiveRmDir(path));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use rimraf here (it's already in the dependencies, documentation here: https://github.com/isaacs/rimraf).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually we don't need it to make this e2e test, so let's just kill it :)

TestBed.configureTestingModule({<% if (routing) { %>
imports: [
RouterTestingModule
],<% } %>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks.

const parentTestProjectDir = process.cwd();
const ngNewProjectName = 'new-test-project';

return Promise.resolve()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You seem to overly complicate how this test could work. Why not:

return return Promise.resolve()
  .then(() => process.chdir(getGlobalVariable('tmp-root')))
  .then(() => ng('new', 'routing-project', '--routing'))
  .then(() => process.chdir(path.join('routing-project')))
  .then(() => ng('test', '--single-run'));

The only thing missing would be to chdir back to the directory we were in before this test, but really e2e_runner should take care of that (and I'm going to do a PR for it).

We already work off a temporary directory, there's no need to clean up after yourself :) This is by design.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#3287 will fix the chdir.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You keep showing me awesome gems. I didn't realise the getGlobalVariable() before!

Will update tomorrow or today if I have time.

@Meligy
Copy link
Contributor Author

Meligy commented Nov 27, 2016

@hansl I just made the change. The build will fail though until we get #3287.

@Meligy Meligy force-pushed the fix/new-routing-inline-spec branch 2 times, most recently from 27a3651 to d9afc7e Compare December 1, 2016 00:04
@Meligy Meligy force-pushed the fix/new-routing-inline-spec branch from d9afc7e to f09f06c Compare December 1, 2016 04:50
@Meligy
Copy link
Contributor Author

Meligy commented Dec 1, 2016

Aaand we finally got a green build!

@hansl do you think this PR can be merged now? Anything else you'd think is needed?
Thanks heaps :)

@hansl
Copy link
Contributor

hansl commented Dec 1, 2016

LGTM! Thanks!

@hansl hansl merged commit 53ab4df into angular:master Dec 1, 2016
MRHarrison pushed a commit to MRHarrison/angular-cli that referenced this pull request Feb 9, 2017
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 12, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

'router-outlet' is not a known element
3 participants