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

fix: refactor mocks to its own project #284

Conversation

yusinto
Copy link
Contributor

@yusinto yusinto commented Sep 25, 2023

Large pr but mostly trivial changes to import paths because mocks have been moved to its own private project @launchdarkly/private-js-mocks:

  • Refactored mocks to its own project @launchdarkly/private-js-mocks.
  • Better eslint rule for no-unused-vars to avoid disabling this rule sporadically.

@shortcut-integration
Copy link

This pull request has been linked to Shortcut Story #217814: Fix mocks and jest runtime dependency.

@yusinto yusinto marked this pull request as draft September 25, 2023 23:33
@louis-launchdarkly
Copy link
Contributor

It may not be fully ready for review, but creating a separate package and the change within it looks generally good to me.

packages/mocks/LICENSE Outdated Show resolved Hide resolved
@kinyoklion
Copy link
Member

Is this ready for review? I was added as a reviewer, but I do see it is draft.

@yusinto
Copy link
Contributor Author

yusinto commented Sep 26, 2023

Not ready yet I need to fix a broken test and fix a circular dependency scenario which I want to improve.

Comment on lines +14 to +17
'@typescript-eslint/no-unused-vars': [
'error',
{ ignoreRestSiblings: true, argsIgnorePattern: '^_', varsIgnorePattern: '^__' },
],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was concerned with increased usage of disabling of this rule and so this is a more sustainable practice going forward.

Comment on lines +26 to +31
'import/default': 'error',
'import/export': 'error',
'import/no-self-import': 'error',
'import/no-cycle': 'error',
'import/no-useless-path-segments': 'error',
'import/no-duplicates': 'error',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Additional sensible rules which are good to have.

@@ -1,4 +1,3 @@
export * from './diagnostics';
export * from './events';
export * from './stream';
export * as mocks from './mocks';
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 riddance.

@@ -12,7 +12,8 @@
"sourceMap": true,
"declaration": true,
"declarationMap": true, // enables importers to jump to source
"stripInternal": true
"stripInternal": true,
"composite": true
Copy link
Contributor Author

Choose a reason for hiding this comment

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

mocks need types from common. This composite allows common to be referred to in mocks so we can import common types.

Comment on lines +2 to +3
"name": "@launchdarkly/private-js-mocks",
"private": true,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

  • We are not publishing mocks to npm because it's internal use only.
  • I'm open to improving the name of this package. It's the best I can come up with right now.

@@ -10,6 +11,7 @@ export {
crypto,
logger,
hasher,
ContextDeduplicator,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There was a bug before this PR where this export was missing. This is to fix that bug.

"exclude": ["**/*.test.ts", "dist", "node_modules", "__tests__"],
"references": [
{
"path": "../common"
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 enables us to import types from common. Then on line 17 above, we add an alias so we can import common without relative paths to appease eslint.

Copy link
Member

Choose a reason for hiding this comment

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

So this means that mocks specifically will only work when checked out as a monorepo? Or will these things get bundled into the dist?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Mocks will only work when checked out as monorepo. There's no bundling to produce any bundles for mocks. The dist folder only contains tsc output without bundling and does not contain any common code.

Just to re-iterate, the mocks projects are only using types from common and nothing else.

@@ -25,7 +23,7 @@ import DataSourceUpdates from './data_sources/DataSourceUpdates';
import PollingProcessor from './data_sources/PollingProcessor';
import Requestor from './data_sources/Requestor';
import createDiagnosticsInitConfig from './diagnostics/createDiagnosticsInitConfig';
import { allAsync, allSeriesAsync } from './evaluation/collection';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

allSeriesAsync is removed because it was unused.

@@ -485,11 +481,9 @@ export default class LDClientImpl implements LDClient {
this.variationInternal(flagKey, context, defaultValue, eventFactory, cb);
}

private dataSourceErrorHandler(e: LDStreamingError | LDPollingError) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Relax the error type here to allow all kinds of errors to be handled. This allows mock errors to be handled.

@yusinto yusinto marked this pull request as ready for review September 27, 2023 21:17
@yusinto yusinto requested a review from kinyoklion September 27, 2023 21:17
Copy link
Member

@kinyoklion kinyoklion left a comment

Choose a reason for hiding this comment

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

This is probably all good, but I think we are going to need to make some packages to be sure.

@yusinto yusinto requested a review from kinyoklion October 2, 2023 18:31
@yusinto yusinto merged commit 2ada20d into yus/sc-208024/scaffold-js-common-in-js-core Oct 2, 2023
2 checks passed
@yusinto yusinto deleted the yus/sc-217814/fix-mocks-and-jest-runtime-dependency branch October 2, 2023 19:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants