angular/packages/platform-server/test
Alan Agius 1035b47d0b test(platform-server): fix issue with ngServerMode when focusing fit tests (#58538)
This commit addresses a problem with tests that use the `fit` function to focus on individual test cases. While these tests run successfully in the full suite, they fail when focused individually using `fit`.

The issue lies in the behavior of `withEventReply` and other hydration-related functions (i.e., `provideX`, `withX`). These functions return platform-specific providers based on the `ngServerMode` setting, causing inconsistencies between server and browser environments. As a result, provider instances cannot be reused across server and browser applications.

**Example of problematic code:**
```ts
const hydrationFeatures = [withEventReply()];
const html = await ssr(SimpleComponent, { hydrationFeatures });
// Expected behavior ...

const appRef = await prepareEnvironmentAndHydrate(doc, html, SimpleComponent, {
  hydrationFeatures,
});
// Expected behavior ...
```

**Solution:**
To address this, we define `hydrationFeatures` as a function instead of a static array. This ensures that a new instance of `withEventReply` is created separately for each environment, eliminating platform-specific mismatches between server and browser contexts:

```typescript
const hydrationFeatures = () => [withEventReply()];  // Define as a function
const html = await ssr(SimpleComponent, { hydrationFeatures: hydrationFeatures() });
// Expected behavior ...

const appRef = await prepareEnvironmentAndHydrate(doc, html, SimpleComponent, {
  hydrationFeatures: hydrationFeatures(),
});
// Expected behavior ...
```

PR Close #58538
2024-11-07 14:29:59 +00:00
..
BUILD.bazel refactor(core): restructure hydration test files (#58196) 2024-10-14 14:26:26 -07:00
dom_utils.ts test(platform-server): fix issue with ngServerMode when focusing fit tests (#58538) 2024-11-07 14:29:59 +00:00
event_replay_spec.ts test(platform-server): fix issue with ngServerMode when focusing fit tests (#58538) 2024-11-07 14:29:59 +00:00
full_app_hydration_spec.ts test(platform-server): fix issue with ngServerMode when focusing fit tests (#58538) 2024-11-07 14:29:59 +00:00
hydration_utils.ts test(platform-server): fix issue with ngServerMode when focusing fit tests (#58538) 2024-11-07 14:29:59 +00:00
incremental_hydration_spec.ts test(platform-server): fix issue with ngServerMode when focusing fit tests (#58538) 2024-11-07 14:29:59 +00:00
integration_spec.ts refactor(core): introduce ngServerMode as global (#58386) 2024-10-30 10:13:28 -07:00
transfer_state_spec.ts refactor(core): Migrate all packages with the explicit-standalone-flag schematic. (#58160) 2024-10-14 14:58:57 +00:00