Skip to content

build(schematics): test schematics properly #12410

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

Merged
merged 3 commits into from
Jul 29, 2018

Conversation

devversion
Copy link
Member

  • Previously, the spec files that have been pushed to the repository, didn't run at all, or were outdated. This PR updates the tests and also enables most of them (as much as possible).
  • Sets up the Bazel test rules (with a few needed workarounds) in order to test the schematics
  • Removed devkit utils that can be used from @schematics/angular which is always present (we can assume that)
  • Moved data .json files into TypeScript files (in order to workaround a bazel typescript issue; and to allow separation for v6 and v7 data at some point)
  • Updates and fixes schematics to properly work within the latest Angular CLI version

@jelbourn Unfortunately this PR turned out bigger than I expected.. but most of the changes are just moving the .json files to .ts (no actual data change).

Moving the .json files to .ts is something I don't feel too strong about.. but I consider running the tests as very important for now (because that would be the best way for me to verify the update schematics)

(Rel: bazelbuild/rules_typescript#154)

@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Jul 27, 2018
* Previously, the spec files that have been pushed to the repository, didn't run at all, or were outdated. This PR updates the tests and also enables most of them (as much as possible).
* Sets up the Bazel test rules (with a few needed workarounds) in order to test the schematics
* Removed devkit utils that can be used from `@schematics/angular` which is **always present** (we can assume that)
* Moved data `.json` files into TypeScript files (in order to workaround a bazel typescript issue; and to allow separation for v6 and v7 data at some point)
* Updates and fixes schematics to properly work within the latest Angular CLI version
@devversion devversion force-pushed the build/schematic-tests branch from 1ad1075 to e86f53f Compare July 27, 2018 19:48
srcs = glob(["**/*.ts"], exclude=["**/*.spec.ts", "**/files/**/*"]),
tsconfig = ":tsconfig.json",
)

ts_library(
Copy link
Member

Choose a reason for hiding this comment

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

Move this under # Testing rules?


ts_library(
name = "schematics",
module_name = "@angular/material/schematics",
Copy link
Member

Choose a reason for hiding this comment

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

I remember needing to add this for something... can you confirm that //src/lib:npm_package still outputs the right thing without this?

Copy link
Member Author

Choose a reason for hiding this comment

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

Can confirm that this seems to be necessary in order to have more reasonable AMD module names .

Also found an issue with the TS rules within Windows: bazelbuild/rules_typescript#239

name = "schematics_test_sources",
srcs = glob(["**/*.spec.ts"], exclude=["**/files/**/*"]),
deps = [":schematics"],
tsconfig = ":tsconfig.json",
Copy link
Member

Choose a reason for hiding this comment

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

This should also have testonly = True

srcs = ["collection.json"],
outs = ["test-collection.json"],
cmd = "cp $< $@",
output_to_bindir = True,
Copy link
Member

Choose a reason for hiding this comment

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

testonly = True

srcs = ["migration.json"],
outs = ["test-migration.json"],
cmd = "cp $< $@",
output_to_bindir = True,
Copy link
Member

Choose a reason for hiding this comment

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

testonly = True

"aliases": ["material-table"]
},
// Creates toolbar and navigation components
"nav": {
"description": "Create a component with a responsive sidenav for navigation",
"factory": "./nav/index",
"schema": "./nav/schema.json",
"aliases": [ "material-nav", "materialNav" ]
// TODO(paul): re-add `materialNav` alias if we have the latest schematics version that
Copy link
Member

Choose a reason for hiding this comment

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

Could you use devversion in TODOs instead of paul?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure. Wasn't really sure if devversion is more ambiguous than paul.

};

beforeEach(() => {
runner = new SchematicTestRunner('schematics', collectionPath);
});

it('should create dashboard files and add them to module', () => {
// Temporarily disabled because @angular-devkit/schematics does not properly resolve
// the files that should be copied to the project.
Copy link
Member

Choose a reason for hiding this comment

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

Is there a link to an issue?

Copy link
Member Author

@devversion devversion Jul 27, 2018

Choose a reason for hiding this comment

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

Not that I know of. And I'm not sure whether this is actually something the CLI project needs to resolve just in favor of Bazel testing. It might just also depend on bazelbuild/rules_typescript#154

import {getWorkspace} from './config';
import {parseName} from './parse-name';
import {validateName} from './validation';
import {Schema as ComponentOptions} from '@schematics/angular/component/schema';
Copy link
Member

Choose a reason for hiding this comment

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

Is everything under devkit-utils still copied exactly from the devkit source?

Copy link
Member Author

Choose a reason for hiding this comment

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

Our devkit-utils have been removed in favor of the same devkit utils that can be just imported. This also makes upgrades to more recent Angular CLI versions way more maintainable.

Copy link
Member

Choose a reason for hiding this comment

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

What I mean, though, is that formerly everything under devkit-utils was copied verbatim. If we're not copying anything any more, I'd like to drop that directory in favor of one or more directories that are more specifically named.

Copy link
Member Author

@devversion devversion Jul 27, 2018

Choose a reason for hiding this comment

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

I see. I'd prefer having another cleanup-run in a follow-up. This PR is mostly about the testing, and switching to the latest devkit utils was just a necessary step in order to work with 6.0.0
Some things were outdated; so I just did the switch

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, that sounds good to me

@devversion
Copy link
Member Author

@jelbourn Done. Made the requested changes.

Copy link
Member

@jelbourn jelbourn left a comment

Choose a reason for hiding this comment

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

LGTM

@jelbourn jelbourn added pr: lgtm action: merge The PR is ready for merge by the caretaker labels Jul 27, 2018
@mmalerba mmalerba merged commit 5963d14 into angular:master Jul 29, 2018
@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 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants