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

fb-emulation #272

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
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
31 changes: 0 additions & 31 deletions firebase.function.json

This file was deleted.

27 changes: 27 additions & 0 deletions firebase.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
"emulators": {
"hosting": {
"port": 4202
},
"functions": {
"port": 4402
}
},
"hosting": {
Expand Down Expand Up @@ -85,5 +88,29 @@
"function": "ssr"
}
]
},
"functions": {
"source": ".",
"ignore": [
" **/.*",
"**/node_modules/**",
"**/tmp/**",
"**/tooling/**",
"**/LICENSE",
"**/CONTRIBUTING.md",
"**/README.md",
"**/commitlint.config.js",
"**/database.rules.json",
"**/firebase-debug.log",
"**/firebase.function.json",
"**/firebase.json",
"**/jest.config.ts",
"**/jest.preset.js",
"**/migrations.json",
"**/nx.json",
"**/tsconfig.json",
"**/ui-debug.log",
"**/wrangler.toml"
]
}
}
29 changes: 6 additions & 23 deletions projects/firebase-function/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,35 +1,18 @@
{
"extends": [
"../../.eslintrc.json"
],
"ignorePatterns": [
"!**/*"
],
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": [
"*.ts",
"*.tsx",
"*.js",
"*.jsx"
],
"extends": [
"plugin:unicorn/recommended"
],
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"extends": [],
"rules": {}
},
{
"files": [
"*.ts",
"*.tsx"
],
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": [
"*.js",
"*.jsx"
],
"files": ["*.js", "*.jsx"],
"rules": {}
}
]
Expand Down
4 changes: 1 addition & 3 deletions projects/firebase-function/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,7 @@
"emulate": {
"executor": "nx:run-commands",
"options": {
"commands": [
"npx firebase --project=angular-movies --config=firebase.function.json emulators:start"
],
"commands": ["npx firebase emulators:start --project=angular-movies"],
"parallel": false
}
},
Expand Down
3 changes: 0 additions & 3 deletions projects/firebase-function/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ declare const __non_webpack_require__: NodeRequire;
// '__non_webpack_require__' is a proxy to Node 'require'

// tslint:disable-next-line:no-require-imports no-var-requires
// eslint-disable-next-line unicorn/prefer-module
const ssrApp = __non_webpack_require__('./main').app(); // NOTE: leave this as require() since this file is built dynamically by Angular CLI webpack
/* Hack end */

Expand All @@ -17,5 +16,3 @@ export const ssr = functions
'4GB' /* 4096MB memory function will run at currently fastest - 4.8 GHz CPU ( https://cloud.google.com/functions/pricing) */,
})
.https.onRequest(ssrApp);


11 changes: 5 additions & 6 deletions projects/firebase-function/tooling/utils.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import {mkdirSync, WriteFileOptions, writeFileSync} from "node:fs";
import {dirname} from "node:path";
import { mkdirSync, WriteFileOptions, writeFileSync } from 'node:fs';
import { dirname } from 'node:path';

export function getLog(verbose: boolean = false) {
return (...logs: any[]) => {
if (verbose) {
console.log(...logs);
}
}
};
}

export function getArgv(propertyName: string): string {
Expand All @@ -18,13 +18,12 @@ export function getArgv(propertyName: string): string {
);
}

// eslint-disable-next-line unicorn/no-object-as-default-parameter
export function writeFileSyncRecursive(
filename: string,
content: string,
options?: WriteFileOptions
): void {
const options_ = options || {encoding: 'utf8'};
mkdirSync(dirname(filename), {recursive: true});
const options_ = options || { encoding: 'utf8' };
mkdirSync(dirname(filename), { recursive: true });
writeFileSync(filename, content, options_);
}
61 changes: 57 additions & 4 deletions projects/firebase-function/user-flows/ci-flow.uf.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
import {UserFlowContext, UserFlowInteractionsFn, UserFlowOptions, UserFlowProvider,} from '@push-based/user-flow';
import {MovieListPageUFO} from '../../movies-user-flows/src';
import { getLhConfig } from '../../movies-user-flows/src/internals/test-sets';

import {
UserFlowContext,
UserFlowInteractionsFn,
UserFlowOptions,
UserFlowProvider,
} from '@push-based/user-flow';
import {
mergeBudgets,
MovieDetailPageUFO,
MovieListPageUFO,
SidebarUFO,
} from '../../movies-user-flows/src';

import Budget from 'lighthouse/types/lhr/budget';
// eslint-disable-next-line @typescript-eslint/no-var-requires
const angularBudgets: Budget[] = require('../../movies/testing/budgets/angular.budgets.json');
// eslint-disable-next-line @typescript-eslint/no-var-requires
const generalTimingBudget: Budget[] = require('../../movies/testing/budgets/general-timing.budgets.json');
// eslint-disable-next-line @typescript-eslint/no-var-requires
const movieListBudgets: Budget[] = require('../../movies/testing/budgets/movie-list.budgets.json');

const flowOptions: UserFlowOptions = {
name: 'Firebase Function Emulation',
Expand All @@ -8,14 +28,47 @@ const flowOptions: UserFlowOptions = {
const interactions: UserFlowInteractionsFn = async (
context: UserFlowContext
): Promise<any> => {
const {flow, collectOptions} = context;
const { flow, collectOptions } = context;
const url = `${collectOptions.url}/list/category/popular`;
const sidebar = new SidebarUFO(context);
const movieListPage = new MovieListPageUFO(context);
const topRatedName = 'topRated';
const movieDetailPage = new MovieDetailPageUFO(context);

const cfg = mergeBudgets([
angularBudgets,
generalTimingBudget,
movieListBudgets,
]);
await flow.navigate(url, {
stepName: '🧭 Initial navigation',
config: getLhConfig(cfg),
});
await flow.snapshot({
stepName: '✔ Initial navigation done',
});
await flow.startTimespan({
stepName: '🧭 Navigate to popular',
});

await sidebar.clickSideMenuBtn();
await sidebar.navigateToCategory(topRatedName);
await movieListPage.awaitLCPContent();
await flow.endTimespan();
await flow.snapshot({
stepName: '✔ Navigation to popular done',
});
await flow.startTimespan({
stepName: '🧭 Navigate to detail page',
});
await movieListPage.awaitHeadingContent();

await movieListPage.navigateToDetail();
await movieDetailPage.awaitAllContent();
await flow.endTimespan();
await flow.snapshot({
stepName: '✔ Navigation to detail done',
});

return;
};

Expand Down
2 changes: 1 addition & 1 deletion projects/movies/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@
"executor": "nx:run-commands",
"options": {
"commands": [
"firebase emulators:start --only hosting --project angular-movies"
"npx firebase emulators:start --only hosting --project angular-movies"
],
"parallel": false
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LetDirective } from '@rx-angular/template/let';
import { RxLet } from '@rx-angular/template/let';
import {
ChangeDetectionStrategy,
Component,
Expand All @@ -8,10 +8,11 @@ import {
} from '@angular/core';
import { ListDetailAdapter } from '../list-detail-page.adapter';
import { DOCUMENT } from '@angular/common';

// TODO
@Component({
standalone: true,
imports: [LetDirective],
imports: [RxLet],
selector: 'ct-list-share',
templateUrl: './list-share.component.html',
styleUrls: ['./list-share.component.scss'],
Expand Down
9 changes: 4 additions & 5 deletions projects/movies/src/app/routes.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {Routes} from '@angular/router';
// import { RouteISRConfig } from 'ngx-isr';
import { Routes } from '@angular/router';

export const ROUTES: Routes = [
/**
Expand All @@ -10,7 +9,7 @@ export const ROUTES: Routes = [
*
* E.g.:
*
* _Bad_
* _Bad_ (multiple routs for the same component)
* {
* path: 'list-category/:category',
* loadComponent: import('list.component')
Expand All @@ -20,7 +19,7 @@ export const ROUTES: Routes = [
* loadComponent: import('list.component')
* }
*
* _Good_
* _Good_ (multiple params instead of routs for the same component)
* {
* path: 'list/:type/:identifier',
* loadComponent: import('list.component')
Expand All @@ -43,7 +42,7 @@ export const ROUTES: Routes = [
loadChildren: () =>
import(
'./pages/account-feature/list-detail-page/list-detail-page.routes'
),
),
},
{
path: 'detail/person/:identifier',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
declare const ngDevMode: boolean;

export function waitForElementTiming(
identifiers: string[],
config: {
timeout: number;
} = { timeout: 5000 }
): Promise<void> {
return new Promise<void>((resolve, reject) => {
const { timeout } = config;
const timeoutId = setTimeout(() => {
if (ngDevMode)
console.log(`waitForElementTiming timed out after ${timeout}ms`);
resolve();
}, timeout);
try {
const performanceObserver = new PerformanceObserver((l) => {
if (identifiers.length > 0 && l.getEntries().length) {
const observedIdentifiers = l
.getEntries()
.map((entry) => (entry as any).identifier as string)

Check warning on line 21 in projects/movies/src/app/shared/cdk/element-timing/wait-for-element-timing.ts

View workflow job for this annotation

GitHub Actions / ci

Unexpected any. Specify a different type
.filter((i) => identifiers.includes(i));
if (ngDevMode && observedIdentifiers.length)
console.log('Observed Elements: ', observedIdentifiers);
// remove found identifiers
identifiers = identifiers.filter(
(i) => !observedIdentifiers.includes(i)
);
// If all identifiers are found
if (identifiers.length === 0) {
if (ngDevMode) console.log('All elements observed');
// cleanup
clearTimeout(timeoutId);
performanceObserver.disconnect();
resolve();
}
}
});
// performanceObserver.observe({type: 'largest-contentful-paint', buffered: true});
performanceObserver.observe({ type: 'element', buffered: true });
} catch (e) {
console.log('waitForElementTiming failed');
reject(e);
}
});
}
Loading
Loading