Schematics: Unit testing a rule that uses mergeWith/apply fails due to missing context
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Anfängerfreundlichkeit
- 35/100
- Issue-Typ
- Bug
- Klarheit
- Muss geklärt werden
- Aktivitätsstatus
- Veraltet
- Tech-Stack
- angular, typescript
Rechercherichtung
Beginne mit der verknüpften minimalen Reproduktion und dem Unit-Test, der callRule, mergeWith und apply verwendet. Verfolge den gemeldeten Fehler durch file-system-engine-host-base.js und den Einstiegspunkt schematics url.js und achte dabei auf den weggelassenen partialContext. Die Umsetzung sollte den erforderlichen Kontext herstellen und entweder den Test bestehen lassen oder den fehlenden Kontext eindeutig melden.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Addendum
In creating the test case I've realised that I'm not passing a partialContext to callRule, so it is definitely missing context, however, it is not at all clear what context is necessary for mergeWith to succeed and the error does not indicate that context is actually missing.
Happy for this to be marked as a question instead. Guidance on how to provide the context and what context to provide would be amazingly useful.
🐞 Bug report
Description
Using callRule to unit test rules within a schematic fails when it comes to rules which return mergeWith
🔬 Minimal Reproduction
See: https://github.com/jdpearce/schematics-apply-problem
Given a rule which applies template files to the tree, this unit test will fail with TypeError: Cannot read property 'path' of undefined:
describe('applyTemplateFiles Rule', () => {
let tree: UnitTestTree;
beforeEach(async () => {
tree = new UnitTestTree(Tree.empty());
});
it('should apply the files to the tree', async () => {
const schema = {};
tree = (await callRule(applyTemplateFiles(schema), tree)) as UnitTestTree;
expect(tree.files).toEqual(jasmine.arrayContaining(['/libs/destination/test.txt']));
});
});
🔥 Exception or Error
Failures:
1) applyTemplateFiles Rule should apply the files to the tree
Message:
TypeError: Cannot read property 'path' of undefined
Stack:
at <Jasmine>
at ./apply-problem/node_modules/@angular-devkit/schematics/tools/file-system-engine-host-base.js:216:96
at ./tmp/apply-problem/node_modules/@angular-devkit/schematics/src/rules/url.js:13:73
at Object.callSource (./tmp/apply-problem/node_modules/@angular-devkit/schematics/src/rules/call.js:55:20)
at ./tmp/apply-problem/node_modules/@angular-devkit/schematics/src/rules/base.js:45:60
at Object.callSource (./tmp/apply-problem/node_modules/@angular-devkit/schematics/src/rules/call.js:55:20)
at ./tmp/apply-problem/node_modules/@angular-devkit/schematics/src/rules/base.js:53:23
at MergeMapSubscriber.project (./tmp/apply-problem/node_modules/@angular-devkit/schematics/src/rules/call.js:74:24)
at MergeMapSubscriber._tryNext (./tmp/apply-problem/node_modules/rxjs/internal/operators/mergeMap.js:69:27)
at MergeMapSubscriber._next (./tmp/apply-problem/node_modules/rxjs/internal/operators/mergeMap.js:59:18)
at MergeMapSubscriber.Subscriber.next (./tmp/apply-problem/node_modules/rxjs/internal/Subscriber.js:66:18)
2 specs, 1 failure
🌍 Your Environment
"@angular-devkit/core": "^9.0.6",
"@angular-devkit/schematics": "^9.0.6",
"@types/jasmine": "^3.3.9",
"@types/node": "^8.0.31",
"jasmine": "^3.3.1",
"typescript": "~3.5.3"
- Vorherrschende Sprache
- TypeScript
- Sterne
- 27k
- Forks
- 11.8k
- Ø Merge
- 16 Std. 35 Min.
- Gemergte PRs (30 T.)
- 176
Beitragsleitfaden
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus angular/angular-cli
-
area: @angular/build gemini-triaged
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 74/100
angular/angular-cli#33955 ·
-
area: @angular/cli gemini-triaged
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
angular/angular-cli#33055 · 1 Kommentar · 3 Reaktionen ·
-
unit-test: with --coverage, a setup file's hooks reach only the first spec file of each worker Offenarea: @angular/build gemini-triaged
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 72/100
angular/angular-cli#34137 ·
-
angular/build:library area: @angular/build gemini-triaged
angular/angular-cli#34131 · 1 zugewiesene Person ·
-
angular/build:library area: @angular/build gemini-triaged
angular/angular-cli#34130 · 1 zugewiesene Person ·
Alle Issues in angular/angular-cli
Ähnliche Issues
-
enhancement
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 70/100
dennys-bd/agent-hive#184 ·
-
Add: hunch Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 74/100
AbdelStark/awesome-typesafe#104 ·
-
ai-observability bug team/ai-observability
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
vicharanashala/fln#563 ·