Skip to content

Commit f7a127c

Browse files
committed
fix(docs-infra): update app code to work with Ivy
This commit also enables more tests to be run on CI with Ivy.
1 parent add0d00 commit f7a127c

8 files changed

Lines changed: 152 additions & 138 deletions

File tree

.circleci/config.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,11 +292,21 @@ jobs:
292292

293293
test_aio_local_ivy:
294294
<<: *job_defaults
295+
docker:
296+
# Needed because the AIO tests and the PWA score test depend on Chrome being available.
297+
- image: *browsers_docker_image
295298
steps:
296299
- *attach_workspace
297300
- *init_environment
298301
# Build aio with Ivy (using local Angular packages)
299302
- run: yarn --cwd aio build-with-ivy --progress=false
303+
# Run PWA-score tests
304+
# (Run before unit and e2e tests, which destroy the `dist/` directory.)
305+
- run: yarn --cwd aio test-pwa-score-localhost $CI_AIO_MIN_PWA_SCORE
306+
# Run unit tests
307+
- run: yarn --cwd aio test --progress=false --watch=false
308+
# Run e2e tests
309+
- run: yarn --cwd aio e2e --configuration=ci
300310

301311
test_aio_tools:
302312
<<: *job_defaults

aio/scripts/switch-to-ivy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ function _main() {
3333
const oldTsConfigStr = readFileSync(tsConfigPath, 'utf8');
3434
const oldTsConfigObj = parse(oldTsConfigStr);
3535
const newTsConfigObj = extend(true, oldTsConfigObj, NG_COMPILER_OPTS);
36-
const newTsConfigStr = JSON.stringify(newTsConfigObj, null, 2);
36+
const newTsConfigStr = `${JSON.stringify(newTsConfigObj, null, 2)}\n`;
3737
console.log(`\nNew config: ${newTsConfigStr}`);
3838
writeFileSync(tsConfigPath, newTsConfigStr);
3939

aio/src/app/custom-elements/code/code-example.component.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ describe('CodeExampleComponent', () => {
2323
});
2424

2525
fixture = TestBed.createComponent(HostComponent);
26+
fixture.detectChanges();
27+
2628
hostComponent = fixture.componentInstance;
2729
codeExampleComponent = hostComponent.codeExampleComponent;
28-
29-
fixture.detectChanges();
3030
});
3131

3232
it('should be able to capture the code snippet provided in content', () => {

aio/src/app/custom-elements/code/code-tabs.component.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ describe('CodeTabsComponent', () => {
2323
});
2424

2525
fixture = TestBed.createComponent(HostComponent);
26+
fixture.detectChanges();
27+
2628
hostComponent = fixture.componentInstance;
2729
codeTabsComponent = hostComponent.codeTabsComponent;
28-
29-
fixture.detectChanges();
3030
});
3131

3232
it('should get correct tab info', () => {

aio/src/app/custom-elements/toc/toc.component.spec.ts

Lines changed: 132 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -63,178 +63,182 @@ describe('TocComponent', () => {
6363
expect(tocComponent.type).toEqual('None');
6464
});
6565

66-
it('should not display anything when no h2 or h3 TocItems', () => {
67-
tocService.tocList.next([tocItem('H1', 'h1')]);
68-
fixture.detectChanges();
69-
expect(tocComponentDe.children.length).toEqual(0);
70-
});
71-
72-
it('should update when the TocItems are updated', () => {
73-
tocService.tocList.next([tocItem('Heading A')]);
74-
fixture.detectChanges();
75-
expect(tocComponentDe.queryAll(By.css('li')).length).toBe(1);
76-
77-
tocService.tocList.next([tocItem('Heading A'), tocItem('Heading B'), tocItem('Heading C')]);
78-
fixture.detectChanges();
79-
expect(tocComponentDe.queryAll(By.css('li')).length).toBe(3);
80-
});
81-
82-
it('should only display H2 and H3 TocItems', () => {
83-
tocService.tocList.next([tocItem('Heading A', 'h1'), tocItem('Heading B'), tocItem('Heading C', 'h3')]);
84-
fixture.detectChanges();
85-
86-
const tocItems = tocComponentDe.queryAll(By.css('li'));
87-
const textContents = tocItems.map(item => item.nativeNode.textContent.trim());
66+
describe('(once the lifecycle hooks have run)', () => {
67+
beforeEach(() => fixture.detectChanges());
8868

89-
expect(tocItems.length).toBe(2);
90-
expect(textContents.find(text => text === 'Heading A')).toBeFalsy();
91-
expect(textContents.find(text => text === 'Heading B')).toBeTruthy();
92-
expect(textContents.find(text => text === 'Heading C')).toBeTruthy();
93-
expect(setPage().tocH1Heading).toBeFalsy();
94-
});
95-
96-
it('should stop listening for TocItems once destroyed', () => {
97-
tocService.tocList.next([tocItem('Heading A')]);
98-
fixture.detectChanges();
99-
expect(tocComponentDe.queryAll(By.css('li')).length).toBe(1);
100-
101-
tocComponent.ngOnDestroy();
102-
tocService.tocList.next([tocItem('Heading A', 'h1'), tocItem('Heading B'), tocItem('Heading C')]);
103-
fixture.detectChanges();
104-
expect(tocComponentDe.queryAll(By.css('li')).length).toBe(1);
105-
});
106-
107-
describe('when fewer than `maxPrimary` TocItems', () => {
108-
109-
beforeEach(() => {
110-
tocService.tocList.next([tocItem('Heading A'), tocItem('Heading B'), tocItem('Heading C'), tocItem('Heading D')]);
69+
it('should not display anything when no h2 or h3 TocItems', () => {
70+
tocService.tocList.next([tocItem('H1', 'h1')]);
11171
fixture.detectChanges();
112-
page = setPage();
72+
expect(tocComponentDe.children.length).toEqual(0);
11373
});
11474

115-
it('should have four displayed items', () => {
116-
expect(page.listItems.length).toEqual(4);
117-
});
118-
119-
it('should not have secondary items', () => {
120-
expect(tocComponent.type).toEqual('EmbeddedSimple');
121-
const aSecond = page.listItems.find(item => item.classes.secondary);
122-
expect(aSecond).toBeFalsy('should not find a secondary');
123-
});
124-
125-
it('should not display expando buttons', () => {
126-
expect(page.tocHeadingButtonEmbedded).toBeFalsy('top expand/collapse button');
127-
expect(page.tocMoreButton).toBeFalsy('bottom more button');
128-
});
129-
});
130-
131-
describe('when many TocItems', () => {
132-
let scrollToTopSpy: jasmine.Spy;
133-
134-
beforeEach(() => {
75+
it('should update when the TocItems are updated', () => {
76+
tocService.tocList.next([tocItem('Heading A')]);
13577
fixture.detectChanges();
136-
page = setPage();
137-
scrollToTopSpy = TestBed.get(ScrollService).scrollToTop;
138-
});
78+
expect(tocComponentDe.queryAll(By.css('li')).length).toBe(1);
13979

140-
it('should have more than 4 displayed items', () => {
141-
expect(page.listItems.length).toBeGreaterThan(4);
80+
tocService.tocList.next([tocItem('Heading A'), tocItem('Heading B'), tocItem('Heading C')]);
81+
fixture.detectChanges();
82+
expect(tocComponentDe.queryAll(By.css('li')).length).toBe(3);
14283
});
14384

144-
it('should not display the h1 item', () => {
145-
expect(page.listItems.find(item => item.classes.h1)).toBeFalsy('should not find h1 item');
146-
});
85+
it('should only display H2 and H3 TocItems', () => {
86+
tocService.tocList.next([tocItem('Heading A', 'h1'), tocItem('Heading B'), tocItem('Heading C', 'h3')]);
87+
fixture.detectChanges();
14788

148-
it('should be in "collapsed" (not expanded) state at the start', () => {
149-
expect(tocComponent.isCollapsed).toBeTruthy();
150-
});
89+
const tocItems = tocComponentDe.queryAll(By.css('li'));
90+
const textContents = tocItems.map(item => item.nativeNode.textContent.trim());
15191

152-
it('should have "collapsed" class at the start', () => {
153-
expect(tocComponentDe.children[0].classes.collapsed).toEqual(true);
92+
expect(tocItems.length).toBe(2);
93+
expect(textContents.find(text => text === 'Heading A')).toBeFalsy();
94+
expect(textContents.find(text => text === 'Heading B')).toBeTruthy();
95+
expect(textContents.find(text => text === 'Heading C')).toBeTruthy();
96+
expect(setPage().tocH1Heading).toBeFalsy();
15497
});
15598

156-
it('should display expando buttons', () => {
157-
expect(page.tocHeadingButtonEmbedded).toBeTruthy('top expand/collapse button');
158-
expect(page.tocMoreButton).toBeTruthy('bottom more button');
159-
});
160-
161-
it('should have secondary items', () => {
162-
expect(tocComponent.type).toEqual('EmbeddedExpandable');
163-
});
99+
it('should stop listening for TocItems once destroyed', () => {
100+
tocService.tocList.next([tocItem('Heading A')]);
101+
fixture.detectChanges();
102+
expect(tocComponentDe.queryAll(By.css('li')).length).toBe(1);
164103

165-
// CSS will hide items with the secondary class when collapsed
166-
it('should have secondary item with a secondary class', () => {
167-
const aSecondary = page.listItems.find(item => item.classes.secondary);
168-
expect(aSecondary).toBeTruthy('should find a secondary');
104+
tocComponent.ngOnDestroy();
105+
tocService.tocList.next([tocItem('Heading A', 'h1'), tocItem('Heading B'), tocItem('Heading C')]);
106+
fixture.detectChanges();
107+
expect(tocComponentDe.queryAll(By.css('li')).length).toBe(1);
169108
});
170109

171-
describe('after click tocHeading button', () => {
110+
describe('when fewer than `maxPrimary` TocItems', () => {
172111

173112
beforeEach(() => {
174-
page.tocHeadingButtonEmbedded.nativeElement.click();
113+
tocService.tocList.next([tocItem('Heading A'), tocItem('Heading B'), tocItem('Heading C'), tocItem('Heading D')]);
175114
fixture.detectChanges();
115+
page = setPage();
176116
});
177117

178-
it('should not be "collapsed"', () => {
179-
expect(tocComponent.isCollapsed).toEqual(false);
118+
it('should have four displayed items', () => {
119+
expect(page.listItems.length).toEqual(4);
180120
});
181121

182-
it('should not have "collapsed" class', () => {
183-
expect(tocComponentDe.children[0].classes.collapsed).toBeFalsy();
122+
it('should not have secondary items', () => {
123+
expect(tocComponent.type).toEqual('EmbeddedSimple');
124+
const aSecond = page.listItems.find(item => item.classes.secondary);
125+
expect(aSecond).toBeFalsy('should not find a secondary');
184126
});
185127

186-
it('should not scroll', () => {
187-
expect(scrollToTopSpy).not.toHaveBeenCalled();
128+
it('should not display expando buttons', () => {
129+
expect(page.tocHeadingButtonEmbedded).toBeFalsy('top expand/collapse button');
130+
expect(page.tocMoreButton).toBeFalsy('bottom more button');
188131
});
132+
});
133+
134+
describe('when many TocItems', () => {
135+
let scrollToTopSpy: jasmine.Spy;
189136

190-
it('should be "collapsed" after clicking again', () => {
191-
page.tocHeadingButtonEmbedded.nativeElement.click();
137+
beforeEach(() => {
192138
fixture.detectChanges();
193-
expect(tocComponent.isCollapsed).toEqual(true);
139+
page = setPage();
140+
scrollToTopSpy = TestBed.get(ScrollService).scrollToTop;
194141
});
195142

196-
it('should not scroll after clicking again', () => {
197-
page.tocHeadingButtonEmbedded.nativeElement.click();
198-
fixture.detectChanges();
199-
expect(scrollToTopSpy).not.toHaveBeenCalled();
143+
it('should have more than 4 displayed items', () => {
144+
expect(page.listItems.length).toBeGreaterThan(4);
200145
});
201-
});
202146

203-
describe('after click tocMore button', () => {
147+
it('should not display the h1 item', () => {
148+
expect(page.listItems.find(item => item.classes.h1)).toBeFalsy('should not find h1 item');
149+
});
204150

205-
beforeEach(() => {
206-
page.tocMoreButton.nativeElement.click();
207-
fixture.detectChanges();
151+
it('should be in "collapsed" (not expanded) state at the start', () => {
152+
expect(tocComponent.isCollapsed).toBeTruthy();
208153
});
209154

210-
it('should not be "collapsed"', () => {
211-
expect(tocComponent.isCollapsed).toEqual(false);
155+
it('should have "collapsed" class at the start', () => {
156+
expect(tocComponentDe.children[0].classes.collapsed).toEqual(true);
212157
});
213158

214-
it('should not have "collapsed" class', () => {
215-
expect(tocComponentDe.children[0].classes.collapsed).toBeFalsy();
159+
it('should display expando buttons', () => {
160+
expect(page.tocHeadingButtonEmbedded).toBeTruthy('top expand/collapse button');
161+
expect(page.tocMoreButton).toBeTruthy('bottom more button');
216162
});
217163

218-
it('should not scroll', () => {
219-
expect(scrollToTopSpy).not.toHaveBeenCalled();
164+
it('should have secondary items', () => {
165+
expect(tocComponent.type).toEqual('EmbeddedExpandable');
220166
});
221167

222-
it('should be "collapsed" after clicking again', () => {
223-
page.tocMoreButton.nativeElement.click();
224-
fixture.detectChanges();
225-
expect(tocComponent.isCollapsed).toEqual(true);
168+
// CSS will hide items with the secondary class when collapsed
169+
it('should have secondary item with a secondary class', () => {
170+
const aSecondary = page.listItems.find(item => item.classes.secondary);
171+
expect(aSecondary).toBeTruthy('should find a secondary');
226172
});
227173

228-
it('should be "collapsed" after clicking tocHeadingButton', () => {
229-
page.tocMoreButton.nativeElement.click();
230-
fixture.detectChanges();
231-
expect(tocComponent.isCollapsed).toEqual(true);
174+
describe('after click tocHeading button', () => {
175+
176+
beforeEach(() => {
177+
page.tocHeadingButtonEmbedded.nativeElement.click();
178+
fixture.detectChanges();
179+
});
180+
181+
it('should not be "collapsed"', () => {
182+
expect(tocComponent.isCollapsed).toEqual(false);
183+
});
184+
185+
it('should not have "collapsed" class', () => {
186+
expect(tocComponentDe.children[0].classes.collapsed).toBeFalsy();
187+
});
188+
189+
it('should not scroll', () => {
190+
expect(scrollToTopSpy).not.toHaveBeenCalled();
191+
});
192+
193+
it('should be "collapsed" after clicking again', () => {
194+
page.tocHeadingButtonEmbedded.nativeElement.click();
195+
fixture.detectChanges();
196+
expect(tocComponent.isCollapsed).toEqual(true);
197+
});
198+
199+
it('should not scroll after clicking again', () => {
200+
page.tocHeadingButtonEmbedded.nativeElement.click();
201+
fixture.detectChanges();
202+
expect(scrollToTopSpy).not.toHaveBeenCalled();
203+
});
232204
});
233205

234-
it('should scroll after clicking again', () => {
235-
page.tocMoreButton.nativeElement.click();
236-
fixture.detectChanges();
237-
expect(scrollToTopSpy).toHaveBeenCalled();
206+
describe('after click tocMore button', () => {
207+
208+
beforeEach(() => {
209+
page.tocMoreButton.nativeElement.click();
210+
fixture.detectChanges();
211+
});
212+
213+
it('should not be "collapsed"', () => {
214+
expect(tocComponent.isCollapsed).toEqual(false);
215+
});
216+
217+
it('should not have "collapsed" class', () => {
218+
expect(tocComponentDe.children[0].classes.collapsed).toBeFalsy();
219+
});
220+
221+
it('should not scroll', () => {
222+
expect(scrollToTopSpy).not.toHaveBeenCalled();
223+
});
224+
225+
it('should be "collapsed" after clicking again', () => {
226+
page.tocMoreButton.nativeElement.click();
227+
fixture.detectChanges();
228+
expect(tocComponent.isCollapsed).toEqual(true);
229+
});
230+
231+
it('should be "collapsed" after clicking tocHeadingButton', () => {
232+
page.tocMoreButton.nativeElement.click();
233+
fixture.detectChanges();
234+
expect(tocComponent.isCollapsed).toEqual(true);
235+
});
236+
237+
it('should scroll after clicking again', () => {
238+
page.tocMoreButton.nativeElement.click();
239+
fixture.detectChanges();
240+
expect(scrollToTopSpy).toHaveBeenCalled();
241+
});
238242
});
239243
});
240244
});

aio/src/app/search/search-box/search-box.component.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ describe('SearchBoxComponent', () => {
3838
it('should get the current search query from the location service',
3939
fakeAsync(inject([LocationService], (location: MockLocationService) => {
4040
location.search.and.returnValue({ search: 'initial search' });
41-
component.ngOnInit();
41+
component.ngAfterViewInit();
4242
expect(location.search).toHaveBeenCalled();
4343
tick(300);
4444
expect(host.searchHandler).toHaveBeenCalledWith('initial search');

0 commit comments

Comments
 (0)