-
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
Changes from all commits
18edb54
5139935
1fff2a3
483c0f4
b51c3e6
741010e
c3564ca
32430c4
16535b9
aa4b314
8509fe2
f15a336
14ba531
cc4cac4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,10 @@ module.exports = { | |
ignorePatterns: ['**/dist/**', '**/vercel/examples/**'], | ||
rules: { | ||
'@typescript-eslint/lines-between-class-members': 'off', | ||
'@typescript-eslint/no-unused-vars': [ | ||
'error', | ||
{ ignoreRestSiblings: true, argsIgnorePattern: '^_', varsIgnorePattern: '^__' }, | ||
], | ||
'prettier/prettier': ['error'], | ||
'class-methods-use-this': 'off', | ||
'import/no-extraneous-dependencies': [ | ||
|
@@ -19,5 +23,11 @@ module.exports = { | |
devDependencies: ['**/jest*.ts', '**/*.test.ts', '**/rollup.config.ts'], | ||
}, | ||
], | ||
'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', | ||
Comment on lines
+26
to
+31
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Additional sensible rules which are good to have. |
||
}, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
name: sdk/cloudflare | ||
|
||
on: | ||
push: | ||
branches: [main, 'feat/**'] | ||
paths-ignore: | ||
- '**.md' #Do not need to run CI for markdown changes. | ||
pull_request: | ||
branches: [main, 'feat/**'] | ||
paths-ignore: | ||
- '**.md' | ||
|
||
jobs: | ||
build-test-mocks: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-node@v3 | ||
- id: shared | ||
name: Shared CI Steps | ||
uses: ./actions/ci | ||
with: | ||
workspace_name: '@launchdarkly/private-js-mocks' | ||
workspace_path: packages/shared/mocks |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,8 @@ | ||
/* eslint-disable @typescript-eslint/no-unused-vars */ | ||
// eslint-disable-next-line import/prefer-default-export | ||
export const createCallbacks = () => ({ | ||
onError: (err: Error) => {}, | ||
onFailed: (err: Error) => {}, | ||
onError: (_err: Error) => {}, | ||
onFailed: (_err: Error) => {}, | ||
onReady: () => {}, | ||
onUpdate: (key: string) => {}, | ||
onUpdate: (_key: string) => {}, | ||
hasEventListeners: () => false, | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. Good riddance. |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
}, | ||
"exclude": ["**/*.test.ts", "dist", "node_modules", "__tests__"] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Changelog | ||
|
||
All notable changes to `@launchdarkly/private-js-mocks` will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org). |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Copyright 2023 Catamorphic, Co. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# LaunchDarkly SDK JavaScript Mocks | ||
|
||
[![Actions Status][mocks-ci-badge]][mocks-ci] | ||
|
||
**Internal use only.** | ||
|
||
This project contains JavaScript mocks that are consumed in unit tests in client-side and server-side JavaScript SDKs. | ||
|
||
## Contributing | ||
|
||
See [Contributing](../shared/CONTRIBUTING.md). | ||
|
||
## About LaunchDarkly | ||
|
||
- LaunchDarkly is a continuous delivery platform that provides feature flags as a service and allows developers to iterate quickly and safely. We allow you to easily flag your features and manage them from the LaunchDarkly dashboard. With LaunchDarkly, you can: | ||
- Roll out a new feature to a subset of your users (like a group of users who opt-in to a beta tester group), gathering feedback and bug reports from real-world use cases. | ||
- Gradually roll out a feature to an increasing percentage of users, and track the effect that the feature has on key metrics (for instance, how likely is a user to complete a purchase if they have feature A versus feature B?). | ||
- Turn off a feature that you realize is causing performance problems in production, without needing to re-deploy, or even restart the application with a changed configuration file. | ||
- Grant access to certain features based on user attributes, like payment plan (eg: users on the ‘gold’ plan get access to more features than users in the ‘silver’ plan). Disable parts of your application to facilitate maintenance, without taking everything offline. | ||
- LaunchDarkly provides feature flag SDKs for a wide variety of languages and technologies. Check out [our documentation](https://docs.launchdarkly.com/sdk) for a complete list. | ||
- Explore LaunchDarkly | ||
- [launchdarkly.com](https://www.launchdarkly.com/ 'LaunchDarkly Main Website') for more information | ||
- [docs.launchdarkly.com](https://docs.launchdarkly.com/ 'LaunchDarkly Documentation') for our documentation and SDK reference guides | ||
- [apidocs.launchdarkly.com](https://apidocs.launchdarkly.com/ 'LaunchDarkly API Documentation') for our API documentation | ||
- [blog.launchdarkly.com](https://blog.launchdarkly.com/ 'LaunchDarkly Blog Documentation') for the latest product updates | ||
|
||
[mocks-ci-badge]: https://github.com/launchdarkly/js-core/actions/workflows/mocks.yml/badge.svg | ||
[mocks-ci]: https://github.com/launchdarkly/js-core/actions/workflows/mocks.yml |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module.exports = { | ||
transform: { '^.+\\.ts?$': 'ts-jest' }, | ||
testMatch: ['**/*.test.ts?(x)'], | ||
testEnvironment: 'node', | ||
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'], | ||
collectCoverageFrom: ['src/**/*.ts'], | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
{ | ||
"name": "@launchdarkly/private-js-mocks", | ||
"private": true, | ||
Comment on lines
+2
to
+3
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
"version": "0.0.1", | ||
"type": "commonjs", | ||
"main": "./dist/index.js", | ||
"types": "./dist/index.d.ts", | ||
"homepage": "https://github.com/launchdarkly/js-core/tree/main/packages/shared/common", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/launchdarkly/js-core.git" | ||
}, | ||
"description": "LaunchDarkly SDK for JavaScript - mocks", | ||
"files": [ | ||
"dist" | ||
], | ||
"keywords": [ | ||
"mocks", | ||
"unit", | ||
"tests", | ||
"launchdarkly", | ||
"js", | ||
"client" | ||
], | ||
"scripts": { | ||
"test": "", | ||
"build": "npx tsc", | ||
"clean": "npx tsc --build --clean", | ||
"lint": "npx eslint --ext .ts", | ||
"lint:fix": "yarn run lint -- --fix" | ||
}, | ||
"license": "Apache-2.0", | ||
"devDependencies": { | ||
"@trivago/prettier-plugin-sort-imports": "^4.2.0", | ||
"@types/jest": "^29.5.5", | ||
"@typescript-eslint/eslint-plugin": "^6.7.3", | ||
"@typescript-eslint/parser": "^6.7.3", | ||
"eslint": "^8.50.0", | ||
"eslint-config-airbnb-base": "^15.0.0", | ||
"eslint-config-airbnb-typescript": "^17.1.0", | ||
"eslint-config-prettier": "^9.0.0", | ||
"eslint-plugin-import": "^2.28.1", | ||
"eslint-plugin-prettier": "^5.0.0", | ||
"jest": "^29.7.0", | ||
"launchdarkly-js-test-helpers": "^2.2.0", | ||
"prettier": "^3.0.3", | ||
"ts-jest": "^29.0.5", | ||
"typescript": "^5.2.2" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import type { ClientContext } from '@common'; | ||
|
||
import platform from './platform'; | ||
|
||
const clientContext: ClientContext = { | ||
basicConfiguration: { | ||
sdkKey: 'testSdkKey', | ||
serviceEndpoints: { events: '', polling: '', streaming: 'https://mockstream.ld.com' }, | ||
}, | ||
platform, | ||
}; | ||
|
||
export default clientContext; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import clientContext from './clientContext'; | ||
import ContextDeduplicator from './contextDeduplicator'; | ||
import { crypto, hasher } from './hasher'; | ||
import logger from './logger'; | ||
import basicPlatform from './platform'; | ||
|
@@ -10,6 +11,7 @@ export { | |
crypto, | ||
logger, | ||
hasher, | ||
ContextDeduplicator, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
MockStreamingProcessor, | ||
setupMockStreamingProcessor, | ||
}; |
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.