-
Notifications
You must be signed in to change notification settings - Fork 19
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
fix: refactor mocks to its own project #284
Conversation
…c-217814/fix-mocks-and-jest-runtime-dependency
…orcing no-unused-vars.
This pull request has been linked to Shortcut Story #217814: Fix mocks and jest runtime dependency. |
It may not be fully ready for review, but creating a separate package and the change within it looks generally good to me. |
Is this ready for review? I was added as a reviewer, but I do see it is draft. |
Not ready yet I need to fix a broken test and fix a circular dependency scenario which I want to improve. |
'@typescript-eslint/no-unused-vars': [ | ||
'error', | ||
{ ignoreRestSiblings: true, argsIgnorePattern: '^_', varsIgnorePattern: '^__' }, | ||
], |
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.
I was concerned with increased usage of disabling of this rule and so this is a more sustainable practice going forward.
'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', |
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.
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'; |
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.
Good riddance.
@@ -12,7 +12,8 @@ | |||
"sourceMap": true, | |||
"declaration": true, | |||
"declarationMap": true, // enables importers to jump to source | |||
"stripInternal": true | |||
"stripInternal": true, | |||
"composite": true |
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.
mocks
need types from common
. This composite
allows common
to be referred to in mocks
so we can import common types.
"name": "@launchdarkly/private-js-mocks", | ||
"private": true, |
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.
- 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, |
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.
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" |
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.
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.
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.
So this means that mocks specifically will only work when checked out as a monorepo? Or will these things get bundled into the dist?
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.
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'; |
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.
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) { |
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.
Relax the error type here to allow all kinds of errors to be handled. This allows mock errors to be handled.
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.
This is probably all good, but I think we are going to need to make some packages to be sure.
2ada20d
into
yus/sc-208024/scaffold-js-common-in-js-core
Large pr but mostly trivial changes to import paths because mocks have been moved to its own private project
@launchdarkly/private-js-mocks
:@launchdarkly/private-js-mocks
.no-unused-vars
to avoid disabling this rule sporadically.