Skip to content

Commit 5775ee7

Browse files
authored
chore: Scaffold jest mock project. (#483)
As part of the mentorship program, @professorice and I have been working on the react-native mock library. This PR is to scaffold the jest mock library in js-core, so we can work on the react-native mock library and also other jest mocks in the future. ```sh # The new jest package lives here packages/tooling/jest ```
1 parent 6b69fde commit 5775ee7

File tree

17 files changed

+269
-1
lines changed

17 files changed

+269
-1
lines changed

.github/workflows/jest.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: tooling/jest
2+
3+
on:
4+
push:
5+
branches: [main, 'feat/**']
6+
paths-ignore:
7+
- '**.md' #Do not need to run CI for markdown changes.
8+
pull_request:
9+
branches: [main, 'feat/**']
10+
paths-ignore:
11+
- '**.md'
12+
13+
jobs:
14+
build-test-jest:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v4
18+
- uses: actions/setup-node@v4
19+
- id: shared
20+
name: Shared CI Steps
21+
uses: ./actions/ci
22+
with:
23+
workspace_name: '@launchdarkly/jest'
24+
workspace_path: packages/tooling/jest

.github/workflows/manual-publish.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ on:
3030
- packages/store/node-server-sdk-redis
3131
- packages/store/node-server-sdk-dynamodb
3232
- packages/telemetry/node-server-sdk-otel
33+
- packages/tooling/jest
3334
prerelease:
3435
description: 'Is this a prerelease. If so, then the latest tag will not be updated in npm.'
3536
type: boolean

.github/workflows/release-please.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ jobs:
2222
package-node-server-sdk-redis-release: ${{ steps.release.outputs['packages/store/node-server-sdk-redis--release_created'] }}
2323
package-node-server-sdk-dynamodb-release: ${{ steps.release.outputs['packages/store/node-server-sdk-dynamodb--release_created'] }}
2424
package-node-server-sdk-otel-release: ${{ steps.release.outputs['packages/telemetry/node-server-sdk-otel--release_created'] }}
25+
package-tooling-jest-release: ${{ steps.release.outputs['packages/tooling/jest--release_created'] }}
2526
steps:
2627
- uses: googleapis/release-please-action@v4
2728
id: release
@@ -313,3 +314,24 @@ jobs:
313314
with:
314315
workspace_path: packages/telemetry/node-server-sdk-otel
315316
aws_assume_role: ${{ vars.AWS_ROLE_ARN }}
317+
318+
release-tooling-jest:
319+
runs-on: ubuntu-latest
320+
needs: ['release-please']
321+
permissions:
322+
id-token: write
323+
contents: write
324+
# HACK: jest is not ready for release yet.
325+
if: false #${{ needs.release-please.outputs.package-tooling-jest-release == 'true' }}
326+
steps:
327+
- uses: actions/checkout@v4
328+
- uses: actions/setup-node@v4
329+
with:
330+
node-version: 20.x
331+
registry-url: 'https://registry.npmjs.org'
332+
- id: release-tooling-jest
333+
name: Full release of packages/tooling/jest
334+
uses: ./actions/full-release
335+
with:
336+
workspace_path: packages/tooling/jest
337+
aws_assume_role: ${{ vars.AWS_ROLE_ARN }}

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
"packages/sdk/akamai-edgekv/example",
2020
"packages/store/node-server-sdk-redis",
2121
"packages/store/node-server-sdk-dynamodb",
22-
"packages/telemetry/node-server-sdk-otel"
22+
"packages/telemetry/node-server-sdk-otel",
23+
"packages/tooling/jest"
2324
],
2425
"private": true,
2526
"scripts": {

packages/tooling/jest/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Changelog
2+
3+
All notable changes to the LaunchDarkly Jest package will be documented in this file. This project adheres to [Semantic Versioning](https://semver.org).

packages/tooling/jest/LICENSE

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Copyright 2024 Catamorphic, Co.
2+
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.

packages/tooling/jest/README.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# LaunchDarkly Jest
2+
3+
[![NPM][jest-npm-badge]][jest-npm-link]
4+
[![Actions Status][jest-ci-badge]][jest-ci]
5+
[![Documentation][jest-ghp-badge]][jest-ghp-link]
6+
[![NPM][jest-dm-badge]][jest-npm-link]
7+
[![NPM][jest-dt-badge]][jest-npm-link]
8+
9+
> [!CAUTION]
10+
> This library is a beta version and should not be considered ready for production use while this message is visible.
11+
12+
> **Easily unit test LaunchDarkly applications with jest** :clap:
13+
14+
For more information, see the [complete reference guide for unit testing](https://docs.launchdarkly.com/guides/sdk/unit-tests).
15+
16+
## Installation
17+
18+
```shell
19+
# npm
20+
npm i @launchdarkly/jest --save-dev
21+
22+
# yarn
23+
yarn add -D @launchdarkly/jest
24+
```
25+
26+
Then in `jest.config.js` add `@launchdarkly/jest/{framework}` to setupFiles:
27+
28+
```js
29+
// jest.config.js
30+
module.exports = {
31+
// for react
32+
setupFiles: ['@launchdarkly/jest/react'],
33+
34+
// for react-native
35+
setupFiles: ['@launchdarkly/jest/react-native'],
36+
};
37+
```
38+
39+
## Quickstart
40+
41+
TODO:
42+
43+
## Developing this package
44+
45+
```shell
46+
# at js-core repo root
47+
yarn && yarn build && cd packages/tooling/jest
48+
49+
# run tests
50+
yarn test
51+
```
52+
53+
## Verifying SDK build provenance with the SLSA framework
54+
55+
LaunchDarkly uses the [SLSA framework](https://slsa.dev/spec/v1.0/about) (Supply-chain Levels for Software Artifacts) to help developers make their supply chain more secure by ensuring the authenticity and build integrity of our published SDK packages. To learn more, see the [provenance guide](PROVENANCE.md).
56+
57+
## About LaunchDarkly
58+
59+
- 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:
60+
- 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.
61+
- 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?).
62+
- 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.
63+
- 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).
64+
- Disable parts of your application to facilitate maintenance, without taking everything offline.
65+
- LaunchDarkly provides feature flag SDKs for a wide variety of languages and technologies. Read [our documentation](https://docs.launchdarkly.com/sdk) for a complete list.
66+
- Explore LaunchDarkly
67+
- [launchdarkly.com](https://www.launchdarkly.com/ 'LaunchDarkly Main Website') for more information
68+
- [docs.launchdarkly.com](https://docs.launchdarkly.com/ 'LaunchDarkly Documentation') for our documentation and SDK reference guides
69+
- [apidocs.launchdarkly.com](https://apidocs.launchdarkly.com/ 'LaunchDarkly API Documentation') for our API documentation
70+
- [blog.launchdarkly.com](https://blog.launchdarkly.com/ 'LaunchDarkly Blog Documentation') for the latest product updates
71+
72+
[jest-ci-badge]: https://github.com/launchdarkly/js-core/actions/workflows/jest.yml/badge.svg
73+
[jest-ci]: https://github.com/launchdarkly/js-core/actions/workflows/jest.yml
74+
[jest-npm-badge]: https://img.shields.io/npm/v/@launchdarkly/jest.svg?style=flat-square
75+
[jest-npm-link]: https://www.npmjs.com/package/@launchdarkly/jest
76+
[jest-ghp-badge]: https://img.shields.io/static/v1?label=GitHub+Pages&message=API+reference&color=00add8
77+
[jest-ghp-link]: https://launchdarkly.github.io/js-core/packages/tooling/jest/docs/
78+
[jest-dm-badge]: https://img.shields.io/npm/dm/@launchdarkly/jest.svg?style=flat-square
79+
[jest-dt-badge]: https://img.shields.io/npm/dt/@launchdarkly/jest.svg?style=flat-square
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"transform": { "^.+\\.ts?$": "ts-jest" },
3+
"testMatch": ["**/*.test.ts?(x)"],
4+
"testPathIgnorePatterns": ["node_modules", "example", "dist"],
5+
"modulePathIgnorePatterns": ["dist"],
6+
"testEnvironment": "node",
7+
"moduleFileExtensions": ["ts", "tsx", "js", "jsx", "json", "node"],
8+
"collectCoverageFrom": ["src/**/*.ts"]
9+
}

packages/tooling/jest/package.json

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
{
2+
"name": "@launchdarkly/jest",
3+
"version": "0.0.1",
4+
"description": "Easily unit test LaunchDarkly feature flagged components with jest",
5+
"homepage": "https://github.com/launchdarkly/js-core/tree/main/packages/tooling/jest",
6+
"repository": {
7+
"type": "git",
8+
"url": "https://github.com/launchdarkly/js-core.git"
9+
},
10+
"license": "Apache-2.0",
11+
"packageManager": "[email protected]",
12+
"keywords": [
13+
"launchdarkly",
14+
"jest",
15+
"mock",
16+
"unit",
17+
"test"
18+
],
19+
"type": "module",
20+
"exports": {
21+
"./react-native": {
22+
"types": "./dist/src/react-native/index.d.ts",
23+
"default": "./dist/src/react-native/index.js"
24+
},
25+
"./react": {
26+
"types": "./dist/src/react/index.d.ts",
27+
"default": "./dist/src/react/index.js"
28+
}
29+
},
30+
"files": [
31+
"dist"
32+
],
33+
"scripts": {
34+
"clean": "rimraf dist",
35+
"build": "yarn clean && tsc",
36+
"tsw": "yarn tsc --watch",
37+
"start": "rimraf dist && yarn tsw",
38+
"lint": "eslint . --ext .ts",
39+
"prettier": "prettier --write '**/*.@(js|ts|tsx|json|css)' --ignore-path ../../../.prettierignore",
40+
"test": "NODE_OPTIONS=\"--experimental-vm-modules --no-warnings\" jest --ci --runInBand",
41+
"coverage": "yarn test --coverage",
42+
"check": "yarn prettier && yarn lint && yarn build && yarn test"
43+
},
44+
"devDependencies": {
45+
"@trivago/prettier-plugin-sort-imports": "^4.1.1",
46+
"@types/jest": "^29.5.0",
47+
"@typescript-eslint/eslint-plugin": "^6.20.0",
48+
"@typescript-eslint/parser": "^6.20.0",
49+
"eslint": "^8.45.0",
50+
"eslint-config-airbnb-base": "^15.0.0",
51+
"eslint-config-airbnb-typescript": "^17.1.0",
52+
"eslint-config-prettier": "^8.8.0",
53+
"eslint-plugin-import": "^2.27.5",
54+
"eslint-plugin-jest": "^27.6.3",
55+
"eslint-plugin-prettier": "^5.0.0",
56+
"jest": "^29.5.0",
57+
"miniflare": "^2.13.0",
58+
"prettier": "^3.0.0",
59+
"rimraf": "^5.0.1",
60+
"ts-jest": "^29.1.0",
61+
"typedoc": "0.25.0",
62+
"typescript": "5.1.6"
63+
}
64+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
describe('react-native', () => {
2+
test.todo('Add react-native tests');
3+
});

0 commit comments

Comments
 (0)