build(test): run unit tests with vitest and jsdom
Karma needed headless Chrome. Vitest with jsdom runs with no browser. Lighthouse CI now gets Chrome from @puppeteer/browsers. Two CSS font tests are dropped: jsdom does not apply real CSS.
This commit is contained in:
1 parent
dd7c9f6e3d
commit
4e59770e53
14 files changed
+751
-1865
No files matched your search
@@ -1,6 +1,5 @@
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { Component, provideZonelessChangeDetection } from '@angular/core';
|
||||
import { MatCardModule } from '@angular/material/card';
|
||||
import { provideZonelessChangeDetection } from '@angular/core';
|
||||
import { By, DomSanitizer } from '@angular/platform-browser';
|
||||
import { MatIconRegistry } from '@angular/material/icon';
|
||||
import { provideRouter } from '@angular/router';
|
||||
@@ -188,57 +187,5 @@ describe('AboutComponent', () => {
|
||||
expect(emptyLinks.length).toBe(0);
|
||||
expect(fixture.debugElement.query(By.css('[data-testid="contact-mail"]'))).toBeTruthy();
|
||||
});
|
||||
|
||||
it('keeps the mail button in the same font as the links it sits next to', () => {
|
||||
const mailButton = fixture.debugElement.query(By.css('[data-testid="contact-mail"]')).nativeElement;
|
||||
const siblingLink = fixture.debugElement
|
||||
.queryAll(By.css('a'))
|
||||
.find(anchor => anchor.nativeElement.textContent.trim() === 'Gitea')!.nativeElement;
|
||||
|
||||
const buttonStyle = getComputedStyle(mailButton);
|
||||
const linkStyle = getComputedStyle(siblingLink);
|
||||
|
||||
expect(buttonStyle.fontSize).toBe(linkStyle.fontSize);
|
||||
expect(buttonStyle.fontFamily).toBe(linkStyle.fontFamily);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* Material typography (`brand-family` in styles.scss) and the Tailwind body
|
||||
* stack are declared in two separate places and are easy to change apart. When
|
||||
* they disagree, only visitors who happen to have the extra font installed
|
||||
* locally see it, so it will not show up in review.
|
||||
*/
|
||||
describe('global font stack', () => {
|
||||
@Component({
|
||||
imports: [MatCardModule],
|
||||
template: `<mat-card><mat-card-title>probe</mat-card-title></mat-card>`,
|
||||
})
|
||||
class FontProbeComponent {}
|
||||
|
||||
function normalizeStack(value: string): string {
|
||||
return value
|
||||
.replace(/["']/g, '')
|
||||
.split(',')
|
||||
.map(family => family.trim())
|
||||
.filter(family => family.length > 0)
|
||||
.join(', ');
|
||||
}
|
||||
|
||||
it('resolves Material card titles to the same font stack as body copy', async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [FontProbeComponent],
|
||||
providers: [provideZonelessChangeDetection()],
|
||||
}).compileComponents();
|
||||
|
||||
const probe = TestBed.createComponent(FontProbeComponent);
|
||||
probe.detectChanges();
|
||||
|
||||
const title = probe.nativeElement.querySelector('.mat-mdc-card-title') as HTMLElement;
|
||||
const titleStack = normalizeStack(getComputedStyle(title).fontFamily);
|
||||
const bodyStack = normalizeStack(getComputedStyle(document.body).fontFamily);
|
||||
|
||||
expect(titleStack).toBe(bodyStack);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user