-
Notifications
You must be signed in to change notification settings - Fork 387
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
test: SSR E2E Test Scenarios (#17666) #17903
base: develop
Are you sure you want to change the base?
Conversation
Previous behavior: When `/products` endpoint returned a http error, the code broke in [this line](https://github.com/SAP/spartacus/blob/ed1e1a78c488b1e1214491ffa736612287f8cf70/projects/core/src/product/store/effects/product.effect.ts#L77), complaining that `this` is undefined. Fix: Preserve the context of `this` which was lost in [this line](https://github.com/SAP/spartacus/blob/ed1e1a78c488b1e1214491ffa736612287f8cf70/projects/core/src/product/store/effects/product.effect.ts#L52) The problem was revealed only after we implemented [CXSPA-2251](https://jira.tools.sap/browse/CXSPA-2251) where we referenced `this` by adding `this.logger` to the method `ProductEffects.productLoadEffect` fixes https://jira.tools.sap/browse/CXSPA-3902
Co-authored-by: Krzysztof Platis <[email protected]> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Krzysztof Platis <[email protected]> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
# Conflicts: # projects/core/src/product/store/actions/product-references.action.ts # projects/core/src/product/store/actions/product-reviews.action.ts # projects/core/src/product/store/effects/product-reviews.effect.ts # projects/core/src/state/utils/entity-loader/entity-loader.action.ts
This pull request introduces methodologies for integrating multiple error interceptors that manage errors within the Server-Side Rendering (SSR) framework. This architectural augmentation preserves backward compatibility, mitigating any potential disruptions for end-users upon the incorporation of new error interceptors into the system. With the introduction of this enhancement, it becomes easier for users to include new error interceptors, giving them the flexibility to determine the order in which these interceptors are applied within the system. This priority setting allows users to control how these interceptors operate and influence the workflow of the system. The order is: High priority Normal or no priority Low priority Preserves the original order within a group of interceptors with the same priority.
export async function sendRequest(path: string) { | ||
return new Promise((resolve, reject) => { | ||
const req = http.get({ ...REQUEST_OPTIONS, path }, (res: any) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's allow for injecting extra Spartacus config chunk, by passing it via a special cookie.
We already have a mechanism for this (implemented in Spartacus TestConfigModule
) and it's already used in our Cypress E2E tests. Let's just use it here as well.
The cookie name is cxConfigE2E
and the Spartacus TestConfigModule
reads it and injects
the config passed via the cookie into Spartacus global config.
Beloww a snippet of code to pass a the cxConfig as an extra cookie:
NOTE: btw. I've changed the signature of the function's argument from path:string
to object {path:string, cxConfig?: Config}
export async function sendRequest(path: string) { | |
return new Promise((resolve, reject) => { | |
const req = http.get({ ...REQUEST_OPTIONS, path }, (res: any) => { | |
import { Config } from '@spartacus/core'; | |
/* ... */ | |
export async function sendRequest({ | |
path, | |
cxConfig | |
}: { | |
path: string, | |
cxConfig?: Config | |
}) { | |
return new Promise((resolve, reject) => { | |
const req = http.get({ | |
...REQUEST_OPTIONS, | |
path, | |
headers: { | |
Cookie: buildCxConfigCookie(cxConfig) | |
}, (res: any) => { |
and let's add a function:
/**
* Builds a cookie string with key 'cxConfigE2E' and the given `cxConfig`
* object as a value that is stringified and URI-encoded.
*
* Note: `TestConfigModule` of Spartacus will read this cookie
* and inject the passed config chunk into Spartacus global config.
*/
function buildCxConfigE2ECookie(cxConfig?: object): string {
if(!cxConfig) {
return {};
}
const cookieKey = 'cxConfigE2E';
const cookieValue = encodeURIComponent(JSON.stringify(cxConfig));
return `${cookieKey}=${cookieValue}`
}
No description provided.