-
Notifications
You must be signed in to change notification settings - Fork 6.8k
build: add test cases for update schematics #12473
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
build: add test cases for update schematics #12473
Conversation
What I plan to do in the future in regards to this PR:
|
@@ -0,0 +1,14 @@ | |||
import {CdkConnectedOverlay, CdkOverlayOrigin} from '@angular/cdk/overlay'; |
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 don't think "fixture" is the right word for this. I'd also like to keep the .ts
extension so that the files get the right syntax highlighting everywhere.
How about
schematics/update/test-cases/ts-class-name.before.ts
schematics/update/test-cases/ts-class-name.after.ts
Other possible pairs could be "input" / "output"
cc @hansl in case he has any ideas for 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.
input
and output
sounds better IMO. I'd even go with input
and expected_output
.
In regards to the extension. Technically it's not real valid TypeScript code because the imports are not valid, and just to mock the Material and CDK packages. I don't really care that much though.
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 like input
and expected_output
Even if the imports are red, I like having the syntax highlighting.
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.
That's reasonable. Will do the changes.
* will be used to verify the update schematic. | ||
*/ | ||
const fixturesDirectories = [ | ||
'angular_material/src/lib/schematics/update/tests/class-names', |
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.
Should this use a glob? Seems like it would be a pain to keep this up to date.
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 won't work for now because Bazel does not copy the files that are referenced in the data
attribute of the jasmine_node_test
rule. I'll add a TODO and revisit once we found a better solution.
src/lib/schematics/update/update.ts
Outdated
return () => console.log( | ||
'\nComplete! Please check the output above for any issues that were detected but could not' + | ||
' be automatically fixed.'); | ||
} | ||
|
||
/** Gets the first tsconfig path from possibile locations based on the history of the CLI. */ | ||
/** Gets the first tsconfig path from possible locations based on the history of the CLI. */ |
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 update this comment so that it says "Gets all tsconfig..." instead of the "Gets the first..."
src/lib/schematics/utils/testing.ts
Outdated
export function runPostScheduledTasks(runner: SchematicTestRunner, taskName: string) | ||
: Observable<void> { | ||
|
||
const host = runner.engine['_host'] as EngineHost<{}, {}>; |
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 you link here to the github issue for exposing these once you file it?
c38c72c
to
c2ec30a
Compare
@jelbourn Made the requested changes. Please have another look 😄 |
@@ -119,7 +119,7 @@ | |||
}, "src/+(lib|cdk|material-experimental|cdk-experimental)/**/!(*.spec).ts"], | |||
"require-license-banner": [ | |||
true, | |||
"src/+(lib|cdk|material-experimental|cdk-experimental|demo-app)/**/!(*.spec).ts" | |||
"src/+(lib|cdk|material-experimental|cdk-experimental|demo-app)/**/!(*.spec|*.fixture).ts" |
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.
Actually, I need to find a way to properly exclude the test cases here. Will work on that
@@ -0,0 +1,14 @@ | |||
import {ConnectedOverlayDirective, OverlayOrigin} from '@angular/cdk/overlay'; |
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.
Should we be including the version in here as well? E.g., this test case is based on v5, but that's not captured anywhere. I'm thinking we could do something like:
schematics/update/test-cases/v5/ts-class-name_input.ts
schematics/update/test-cases/v5/ts-class-name_expected_output.ts
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.
That's a good question. I'm not too sure yet -- I actually wouldn't differentiate between V5 and V6 because otherwise it wouldn't be really verifying how the tool will work in CLI projects that are on V5 and just run ng update
.
Also it kind of depends on how we handle the V5 and V6 data (e.g. whether we merge the data; or have separate rules; or separate schematics).
I'd personally vote for a follow-up. PR. The PR is already pretty big, includes lots of workarounds and is primarily about the infrastructure and ability to run such test cases.
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.
Ah, interesting. I had always assumed we would only run the v5 -> v6 rules when the user is on v5, and then the same for v6 -> v7 and so on. Now I realize, though, it's set up to run all of them all the time.
As far as correctness goes, I don't think it matters; the symbols from v5 should never come back, so the old rules would be a no-op. However, I would be slightly concerned that there would be a performance cost to running all of the rules for old versions (in making ng update
take longer). I'd want to try running them over an app or two to gauge the cost.
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.
Also cc @hansl for input
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.
That's true. The question is just how much code we'd need to duplicate in order to differentiate between an update from v5 or an update from v6.
Since we run the rules through the TslintFixTask
, we have no real way of telling the rules from the schematic, that the update starts with v5 or v6.
Surely there would be other ways, but not sure how much we gain from the extra effort. It's not like we have a lot of rules. From my investigations, all of them still run pretty fast.
--
Also, as far as I could tell, there is not really a way to identify the version of Material before the update because the CLI performs the npm
update before running the schematic.
(e.g. options are not passed to the migration schematics; see here)
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.
@crisbeto @mmalerba @josephperrott @vivian-hu do you have any opinions on file organization here?
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.
it wouldn't be really verifying how the tool will work in CLI projects that are on V5 and just run ng update.
The CLI will run all migrations between [from, to] (inclusive), in order. So you will run the v5 -> v6 migration, then whatever is after v6 (I would presume v6 -> v7 migration).
I need to get you off tslint asap. Or you need to get off of it yourself :) . It just complicates things.
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.
@hansl I see 😄 I didn't really integrate the TSLint rules into the schematics. At some point the reasoning for the TSLint rules in the initial standalone tool was that the rules could be run inside of Google. But not sure how relevant this is today.
What would you recommend for doing the update tool? Just using the TS API without TSLint?
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.
For now, that's unfortunately the best.
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.
@jelbourn I've just made the changes from this comment. As mentioned above, I see the point of having a v5
separation, if we have multiple entry-points for the migration schematics.
501cf44
to
68cb8fa
Compare
* Adds a way to test that the update schematics properly update a developer's application. * As a start, we test the `classNames` data for the V5 to V6 upgrade.
68cb8fa
to
69a3840
Compare
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. |
classNames
data for the V5 to V6 upgrade.