Skip to content

Commit 6ed7cf1

Browse files
committed
[WIP] test(flex-layout): convert SSR test setup to Vitest
1 parent b328a24 commit 6ed7cf1

File tree

13 files changed

+76
-96
lines changed

13 files changed

+76
-96
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"build:universal-demo-app": "nx run universal-demo-app:build:production",
2525
"serve:universal-demo-app": "nx run universal-demo-app:serve-ssr",
2626
"test": "nx test @ngbracket/ngx-layout",
27-
"test:ssr": "webpack --config test/webpack-spec-ssr-bundle.js && jasmine --config=test/jasmine-ssr.json",
27+
"test:ssr": "nx test @ngbracket/ngx-layout --configuration=ssr",
2828
"test:watch": "vitest --watch --ui --project \"@ngbracket/ngx-layout\"",
2929
"lint": "stylelint projects/libs/**/*.scss --config=stylelint-config.json && tslint --project ./tsconfig.json --config tslint.json",
3030
"release": "pnpm build && pnpm stamp",

pnpm-lock.yaml

Lines changed: 18 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

projects/libs/flex-layout/flex/flex/flex.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1195,7 +1195,7 @@ describe('flex directive', () => {
11951195
// The parent flex-direction not found;
11961196
// A flex-direction should have been auto-injected to the parent...
11971197
// fallback to 'row' and set child width styles accordingly
1198-
expect(parent.nativeElement.getAttribute('style')).not.toContain(
1198+
expect(parent.nativeElement.getAttribute('style') ?? '').not.toContain(
11991199
'-webkit-flex-direction'
12001200
);
12011201
expectEl(element).toHaveInlineStyle({ 'min-width': '40px' }, styler);

projects/libs/flex-layout/flex/layout-gap/layout-gap.spec.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { isPlatformBrowser } from '@angular/common';
12
/**
23
* @license
34
* Copyright Google LLC All Rights Reserved.
@@ -234,7 +235,7 @@ describe('layout-gap directive', () => {
234235
nodes = queryFor(fixture, '[fxFlex]');
235236
expect(nodes.length).toEqual(3);
236237

237-
if (typeof MutationObserver !== 'undefined') {
238+
if (isPlatformBrowser(platformId) && typeof MutationObserver !== 'undefined') {
238239
expectEl(nodes[0]).toHaveInlineStyle({ 'margin-right': '13px' }, styler);
239240
expectEl(nodes[1]).toHaveInlineStyle({ 'margin-right': '13px' }, styler);
240241
expectEl(nodes[2]).not.toHaveInlineStyle(
@@ -271,7 +272,7 @@ describe('layout-gap directive', () => {
271272
nodes = queryFor(fixture, '[fxFlex]');
272273

273274
expect(nodes.length).toEqual(1);
274-
if (typeof MutationObserver !== 'undefined') {
275+
if (isPlatformBrowser(platformId) && typeof MutationObserver !== 'undefined') {
275276
expectEl(nodes[0]).not.toHaveInlineStyle(
276277
{ 'margin-right': '13px' },
277278
styler

projects/libs/flex-layout/flex/layout-gap/layout-gap.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Directionality } from '@angular/cdk/bidi';
2+
import { isPlatformBrowser } from '@angular/common';
23
import {
34
AfterContentInit,
45
Directive,
@@ -7,6 +8,7 @@ import {
78
Injectable,
89
NgZone,
910
OnDestroy,
11+
PLATFORM_ID,
1012
} from '@angular/core';
1113
import { LAYOUT_VALUES } from '@ngbracket/ngx-layout/_private-utils';
1214
import {
@@ -144,7 +146,8 @@ export class LayoutGapDirective
144146
protected directionality: Directionality,
145147
protected styleUtils: StyleUtils,
146148
styleBuilder: LayoutGapStyleBuilder,
147-
marshal: MediaMarshaller
149+
marshal: MediaMarshaller,
150+
@Inject(PLATFORM_ID) protected platformId: Object
148151
) {
149152
super(elRef, styleBuilder, styleUtils, marshal);
150153
const extraTriggers = [
@@ -264,7 +267,7 @@ export class LayoutGapDirective
264267

265268
protected buildChildObservable(): void {
266269
this.zone.runOutsideAngular(() => {
267-
if (typeof MutationObserver !== 'undefined') {
270+
if (isPlatformBrowser(this.platformId) && typeof MutationObserver !== 'undefined') {
268271
this.observer = new MutationObserver((mutations: MutationRecord[]) => {
269272
const validatedChanges = (it: MutationRecord): boolean => {
270273
return (

projects/libs/flex-layout/project.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@
2727
"outputs": ["{options.reportsDirectory}"],
2828
"options": {
2929
"reportsDirectory": "../../../coverage/projects/libs/flex-layout"
30+
},
31+
"configurations": {
32+
"ssr": {
33+
"config": "projects/libs/flex-layout/vite.config.ssr.mts",
34+
"reportsDirectory": "../../../coverage/ssr/projects/libs/flex-layout"
35+
}
3036
}
3137
}
3238
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import '@analogjs/vitest-angular/setup-zone';
2+
import '@testing-library/jest-dom/vitest';
3+
import './_private-utils/testing/custom-matchers';
4+
5+
import { getTestBed } from '@angular/core/testing';
6+
import {
7+
ServerTestingModule,
8+
platformServerTesting,
9+
} from '@angular/platform-server/testing';
10+
11+
getTestBed().initTestEnvironment(
12+
ServerTestingModule,
13+
platformServerTesting(),
14+
);

projects/libs/flex-layout/test.ssr.ts

Lines changed: 0 additions & 27 deletions
This file was deleted.

projects/libs/flex-layout/tsconfig.spec.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
]
1414
},
1515
"files": [
16-
"test-setup.ts"
16+
"test-setup.ts",
17+
"test-setup.ssr.ts"
1718
],
1819
"include": [
1920
"vite.config.ts",

projects/libs/flex-layout/tsconfig.spec.ssr.json

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)