-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
Conversation
* 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
1ad1075
to
e86f53f
Compare
src/lib/schematics/BUILD.bazel
Outdated
srcs = glob(["**/*.ts"], exclude=["**/*.spec.ts", "**/files/**/*"]), | ||
tsconfig = ":tsconfig.json", | ||
) | ||
|
||
ts_library( |
There was a problem hiding this comment.
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
?
src/lib/schematics/BUILD.bazel
Outdated
|
||
ts_library( | ||
name = "schematics", | ||
module_name = "@angular/material/schematics", |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
testonly = True
src/lib/schematics/collection.json
Outdated
"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 |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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'; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
@jelbourn Done. Made the requested changes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
@schematics/angular
which is always present (we can assume that).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)@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)