Skip to content

Commit

Permalink
chore: Scaffold jest mock project. (#483)
Browse files Browse the repository at this point in the history
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
```
  • Loading branch information
yusinto authored Jun 20, 2024
1 parent 6b69fde commit 5775ee7
Show file tree
Hide file tree
Showing 17 changed files with 269 additions and 1 deletion.
24 changes: 24 additions & 0 deletions .github/workflows/jest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: tooling/jest

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-jest:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- id: shared
name: Shared CI Steps
uses: ./actions/ci
with:
workspace_name: '@launchdarkly/jest'
workspace_path: packages/tooling/jest
1 change: 1 addition & 0 deletions .github/workflows/manual-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ on:
- packages/store/node-server-sdk-redis
- packages/store/node-server-sdk-dynamodb
- packages/telemetry/node-server-sdk-otel
- packages/tooling/jest
prerelease:
description: 'Is this a prerelease. If so, then the latest tag will not be updated in npm.'
type: boolean
Expand Down
22 changes: 22 additions & 0 deletions .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ jobs:
package-node-server-sdk-redis-release: ${{ steps.release.outputs['packages/store/node-server-sdk-redis--release_created'] }}
package-node-server-sdk-dynamodb-release: ${{ steps.release.outputs['packages/store/node-server-sdk-dynamodb--release_created'] }}
package-node-server-sdk-otel-release: ${{ steps.release.outputs['packages/telemetry/node-server-sdk-otel--release_created'] }}
package-tooling-jest-release: ${{ steps.release.outputs['packages/tooling/jest--release_created'] }}
steps:
- uses: googleapis/release-please-action@v4
id: release
Expand Down Expand Up @@ -313,3 +314,24 @@ jobs:
with:
workspace_path: packages/telemetry/node-server-sdk-otel
aws_assume_role: ${{ vars.AWS_ROLE_ARN }}

release-tooling-jest:
runs-on: ubuntu-latest
needs: ['release-please']
permissions:
id-token: write
contents: write
# HACK: jest is not ready for release yet.
if: false #${{ needs.release-please.outputs.package-tooling-jest-release == 'true' }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20.x
registry-url: 'https://registry.npmjs.org'
- id: release-tooling-jest
name: Full release of packages/tooling/jest
uses: ./actions/full-release
with:
workspace_path: packages/tooling/jest
aws_assume_role: ${{ vars.AWS_ROLE_ARN }}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"packages/sdk/akamai-edgekv/example",
"packages/store/node-server-sdk-redis",
"packages/store/node-server-sdk-dynamodb",
"packages/telemetry/node-server-sdk-otel"
"packages/telemetry/node-server-sdk-otel",
"packages/tooling/jest"
],
"private": true,
"scripts": {
Expand Down
3 changes: 3 additions & 0 deletions packages/tooling/jest/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Changelog

All notable changes to the LaunchDarkly Jest package will be documented in this file. This project adheres to [Semantic Versioning](https://semver.org).
13 changes: 13 additions & 0 deletions packages/tooling/jest/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Copyright 2024 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.
79 changes: 79 additions & 0 deletions packages/tooling/jest/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# LaunchDarkly Jest

[![NPM][jest-npm-badge]][jest-npm-link]
[![Actions Status][jest-ci-badge]][jest-ci]
[![Documentation][jest-ghp-badge]][jest-ghp-link]
[![NPM][jest-dm-badge]][jest-npm-link]
[![NPM][jest-dt-badge]][jest-npm-link]

> [!CAUTION]
> This library is a beta version and should not be considered ready for production use while this message is visible.
> **Easily unit test LaunchDarkly applications with jest** :clap:
For more information, see the [complete reference guide for unit testing](https://docs.launchdarkly.com/guides/sdk/unit-tests).

## Installation

```shell
# npm
npm i @launchdarkly/jest --save-dev

# yarn
yarn add -D @launchdarkly/jest
```

Then in `jest.config.js` add `@launchdarkly/jest/{framework}` to setupFiles:

```js
// jest.config.js
module.exports = {
// for react
setupFiles: ['@launchdarkly/jest/react'],

// for react-native
setupFiles: ['@launchdarkly/jest/react-native'],
};
```

## Quickstart

TODO:

## Developing this package

```shell
# at js-core repo root
yarn && yarn build && cd packages/tooling/jest

# run tests
yarn test
```

## Verifying SDK build provenance with the SLSA framework

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).

## 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. Read [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

[jest-ci-badge]: https://github.com/launchdarkly/js-core/actions/workflows/jest.yml/badge.svg
[jest-ci]: https://github.com/launchdarkly/js-core/actions/workflows/jest.yml
[jest-npm-badge]: https://img.shields.io/npm/v/@launchdarkly/jest.svg?style=flat-square
[jest-npm-link]: https://www.npmjs.com/package/@launchdarkly/jest
[jest-ghp-badge]: https://img.shields.io/static/v1?label=GitHub+Pages&message=API+reference&color=00add8
[jest-ghp-link]: https://launchdarkly.github.io/js-core/packages/tooling/jest/docs/
[jest-dm-badge]: https://img.shields.io/npm/dm/@launchdarkly/jest.svg?style=flat-square
[jest-dt-badge]: https://img.shields.io/npm/dt/@launchdarkly/jest.svg?style=flat-square
9 changes: 9 additions & 0 deletions packages/tooling/jest/jest.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"transform": { "^.+\\.ts?$": "ts-jest" },
"testMatch": ["**/*.test.ts?(x)"],
"testPathIgnorePatterns": ["node_modules", "example", "dist"],
"modulePathIgnorePatterns": ["dist"],
"testEnvironment": "node",
"moduleFileExtensions": ["ts", "tsx", "js", "jsx", "json", "node"],
"collectCoverageFrom": ["src/**/*.ts"]
}
64 changes: 64 additions & 0 deletions packages/tooling/jest/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{
"name": "@launchdarkly/jest",
"version": "0.0.1",
"description": "Easily unit test LaunchDarkly feature flagged components with jest",
"homepage": "https://github.com/launchdarkly/js-core/tree/main/packages/tooling/jest",
"repository": {
"type": "git",
"url": "https://github.com/launchdarkly/js-core.git"
},
"license": "Apache-2.0",
"packageManager": "[email protected]",
"keywords": [
"launchdarkly",
"jest",
"mock",
"unit",
"test"
],
"type": "module",
"exports": {
"./react-native": {
"types": "./dist/src/react-native/index.d.ts",
"default": "./dist/src/react-native/index.js"
},
"./react": {
"types": "./dist/src/react/index.d.ts",
"default": "./dist/src/react/index.js"
}
},
"files": [
"dist"
],
"scripts": {
"clean": "rimraf dist",
"build": "yarn clean && tsc",
"tsw": "yarn tsc --watch",
"start": "rimraf dist && yarn tsw",
"lint": "eslint . --ext .ts",
"prettier": "prettier --write '**/*.@(js|ts|tsx|json|css)' --ignore-path ../../../.prettierignore",
"test": "NODE_OPTIONS=\"--experimental-vm-modules --no-warnings\" jest --ci --runInBand",
"coverage": "yarn test --coverage",
"check": "yarn prettier && yarn lint && yarn build && yarn test"
},
"devDependencies": {
"@trivago/prettier-plugin-sort-imports": "^4.1.1",
"@types/jest": "^29.5.0",
"@typescript-eslint/eslint-plugin": "^6.20.0",
"@typescript-eslint/parser": "^6.20.0",
"eslint": "^8.45.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-airbnb-typescript": "^17.1.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-jest": "^27.6.3",
"eslint-plugin-prettier": "^5.0.0",
"jest": "^29.5.0",
"miniflare": "^2.13.0",
"prettier": "^3.0.0",
"rimraf": "^5.0.1",
"ts-jest": "^29.1.0",
"typedoc": "0.25.0",
"typescript": "5.1.6"
}
}
3 changes: 3 additions & 0 deletions packages/tooling/jest/src/react-native/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
describe('react-native', () => {
test.todo('Add react-native tests');
});
3 changes: 3 additions & 0 deletions packages/tooling/jest/src/react-native/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
jest.mock('@launchdarkly/react-client-sdk', () => {
// TODO:
});
3 changes: 3 additions & 0 deletions packages/tooling/jest/src/react/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
jest.mock('@launchdarkly/react-native-client-sdk', () => {
// TODO:
});
5 changes: 5 additions & 0 deletions packages/tooling/jest/tsconfig.eslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"extends": "./tsconfig.json",
"include": ["/**/*.ts"],
"exclude": ["node_modules"]
}
23 changes: 23 additions & 0 deletions packages/tooling/jest/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"declaration": true,
"declarationMap": true,
"lib": ["es6"],
"module": "ES6",
"moduleResolution": "node",
"noImplicitOverride": true,
"outDir": "dist",
"resolveJsonModule": true,
// Uses "." so it can load package.json.
"rootDir": ".",
"skipLibCheck": true,
// enables importers to jump to source
"sourceMap": true,
"strict": true,
"stripInternal": true,
"target": "ES2017",
"types": ["jest", "node"]
},
"exclude": ["**/*.test.ts", "dist", "node_modules", "__tests__", "example"]
}
7 changes: 7 additions & 0 deletions packages/tooling/jest/tsconfig.ref.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "./tsconfig.json",
"include": ["src/**/*", "package.json"],
"compilerOptions": {
"composite": true
}
}
5 changes: 5 additions & 0 deletions packages/tooling/jest/typedoc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"extends": ["../../../typedoc.base.json"],
"entryPoints": ["src/react-native/index.ts", "src/react/index.ts"],
"out": "docs"
}
3 changes: 3 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@
},
{
"path": "./packages/telemetry/node-server-sdk-otel/tsconfig.ref.json"
},
{
"path": "./packages/tooling/jest/tsconfig.ref.json"
}
]
}

0 comments on commit 5775ee7

Please sign in to comment.