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

[FSSDK-10882] ProjectConfigManager SSR support #965

Merged

Conversation

junaed-optimizely
Copy link
Contributor

Summary

This PR makes the ProjectConfigManager SSR compatible

Test plan

  • Existing mock has been updated to adjust with the config manager
  • New testcases have been added for coverage

Issues

@coveralls
Copy link

coveralls commented Nov 18, 2024

Coverage Status

coverage: 88.81% (-0.06%) from 88.866%
when pulling 3777312 on junaed/fssdk-10882-project-config-ssr-support
into 9e37f00 on master.

@junaed-optimizely junaed-optimizely marked this pull request as ready for review November 20, 2024 10:56
@junaed-optimizely junaed-optimizely requested a review from a team as a code owner November 20, 2024 10:56
@@ -54,6 +55,7 @@ export class ProjectConfigManagerImpl extends BaseService implements ProjectConf
public datafileManager?: DatafileManager;
private eventEmitter: EventEmitter<{ update: ProjectConfig }> = new EventEmitter();
private logger?: LoggerFacade;
private isSsr?: boolean;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of optional boolean, we can use a boolean with default false

private isSsr = false;

* @param {Boolean} isSsr
* @returns {void}
*/
setSsr(isSsr?: boolean): void {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we use boolean parameter instead of optional boolean?

@@ -79,6 +81,11 @@ export class ProjectConfigManagerImpl extends BaseService implements ProjectConf
return;
}

if(this.isSsr) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if isSsr is true no datafile is provided, but only a datafileManager is provided, then onRunning() will wait indefinitely cause we are dropping the datafile. We can move this condition before the previous if on line 78 and update the message inside for isSsr case

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also can we add a test that if isSsr is provided without a datafile, onRunning() is rejected?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I have missed that edge case. Thanks for pointing it out..

@@ -146,6 +146,7 @@ export default class Optimizely implements Client {
this.updateOdpSettings();
});

this.projectConfigManager.setSsr(config.isSsr)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add a test that isSsr is passed to the projectConfigManager?

Please do this in a new lib/optimizely/index.spec.ts file instead of the old js test file. We will eventually get rid of the whole js test file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. I did not know about that change.

@@ -88,6 +89,22 @@ describe('optimizelyFactory', function() {
assert.equal(optlyInstance.clientVersion, '5.3.4');
});

it('should create an instance of optimizely with ssr flag, project config must be available', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you please add the test in a new index.node.spec.ts file instead? We want to get rid of all JS tests. We will only update existing tests in these old tests file and will add all new tests in new ts test files.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't be required anymore due to the new index.spec.ts coverage

Copy link
Contributor

@raju-opti raju-opti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@junaed-optimizely junaed-optimizely merged commit 6930199 into master Nov 22, 2024
8 of 14 checks passed
@junaed-optimizely junaed-optimizely deleted the junaed/fssdk-10882-project-config-ssr-support branch November 22, 2024 16:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants