Skip to content
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

ci: any playwright test should fail on any uncaught SSR error #7081

Merged
merged 1 commit into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .github/workflows/e2e-playwright.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- run: npx tsc -p tsconfig.playwright.json

- name: Building demo-app of git-branch without cache
run: npx nx prerender demo
run: npm run build:ssr

- name: Upload cache / ${{ env.CACHE_DIST_KEY }}
uses: actions/cache/[email protected]
Expand Down Expand Up @@ -52,7 +52,9 @@ jobs:
key: ${{ env.CACHE_DIST_KEY }}

- name: Serve ${{ env.DIST }} in background
run: npx nx serve-compiled demo --path ${{ env.DIST }} --port ${{ env.NG_SERVER_PORT }}
run: |
PORT=${{ env.NG_SERVER_PORT }} node dist/demo/server/main.js --ci & sleep 5
curl -X GET -I -f "http://localhost:${{ env.NG_SERVER_PORT }}"

- name: Run screenshot tests on ${{ env.DIST }}
run: npx nx e2e demo-playwright -- --update-snapshots --shard=${{ matrix.shardIndex }}/${{ matrix.shardTotal }}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"start:coalescing": "nx serve demo -c coalescing",
"start:shadow": "nx serve demo -c shadow",
"start:host": "nx serve demo --open --host 0.0.0.0 --disable-host-check",
"build:ssr": "nx build demo && nx run demo:server:production",
"build:ssr": "nx build demo --baseHref=/ && nx run demo:server:production",
"prerender": "nx run demo:prerender",
"test": "nx run-many --target test --all --output-style=stream --parallel=1",
"test:e2e": "nx e2e-ui demo-cypress",
Expand Down
10 changes: 10 additions & 0 deletions projects/demo/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ import express from 'express';

import bootstrap from './src/main.server';

/**
* TODO: drop it after update to @ng-web-apis/[email protected]
* @see https://github.com/taiga-family/ng-web-apis/pull/350
*/
global.ResizeObserver = class {
public observe(): void {}
public unobserve(): void {}
public disconnect(): void {}
};

declare const __non_webpack_require__: NodeRequire;
const mainModule = __non_webpack_require__.main;
const moduleFilename = mainModule?.filename || '';
Expand Down
16 changes: 15 additions & 1 deletion projects/demo/src/main.server.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,31 @@
import type {ApplicationRef} from '@angular/core';
import {importProvidersFrom, mergeApplicationConfig} from '@angular/core';
import {ErrorHandler, importProvidersFrom, mergeApplicationConfig} from '@angular/core';
import {bootstrapApplication} from '@angular/platform-browser';
import {provideServerRendering, ServerModule} from '@angular/platform-server';
import {RESIZE_OBSERVER_SUPPORT} from '@ng-web-apis/resize-observer';
import {UNIVERSAL_PROVIDERS} from '@ng-web-apis/universal';

import {AppComponent} from './modules/app/app.component';
import {config} from './modules/app/app.config';
import {ServerErrorHandler} from './modules/app/server-error-handler';

const serverConfig = mergeApplicationConfig(config, {
providers: [
importProvidersFrom(ServerModule),
provideServerRendering(),
UNIVERSAL_PROVIDERS,
{
provide: ErrorHandler,
useClass: ServerErrorHandler,
},
/**
* TODO: drop it after update to @ng-web-apis/[email protected]
* @see https://github.com/taiga-family/ng-web-apis/pull/350
*/
{
provide: RESIZE_OBSERVER_SUPPORT,
useValue: true,
},
],
});

Expand Down
33 changes: 33 additions & 0 deletions projects/demo/src/modules/app/server-error-handler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import type {ErrorHandler} from '@angular/core';
import {Injectable} from '@angular/core';
import {hasFlag} from 'scripts/shared/argv.utils';

// TODO
const KNOWN_ISSUES: string[] = [
'requestAnimationFrame is not defined', // hljs
/**
* TODO: drop it after update to @ng-web-apis/[email protected]
* @see https://github.com/taiga-family/ng-web-apis/pull/350
*/
'ResizeObserver is not supported in your browser',
// TODO: drop all `Failed to parse URL from` errors after deletion of tui-svg component
'TypeError: Failed to parse URL from assets/icons/android.svg',
'TypeError: Failed to parse URL from assets/icons/ios.svg',
];

@Injectable()
export class ServerErrorHandler implements ErrorHandler {
public handleError(error: Error | string): void {
const errorMessage = (typeof error === 'string' ? error : error.message) || '';

if (KNOWN_ISSUES.some(issue => errorMessage.includes(issue))) {
return;
}

console.error(errorMessage);

if (hasFlag('--ci')) {
process.exit(1);
}
}
}
Loading