Skip to content

Commit 1bbe6fb

Browse files
authored
docs: add README for jest-create-cache-key-function package (#12492)
1 parent fc3d034 commit 1bbe6fb

2 files changed

Lines changed: 46 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
- `[expect]` [**BREAKING**] Snapshot matcher types are moved to `@jest/expect` ([#12404](https://github.com/facebook/jest/pull/12404))
7070
- `[jest-cli]` Update `yargs` to v17 ([#12357](https://github.com/facebook/jest/pull/12357))
7171
- `[jest-config]` [**BREAKING**] Remove `getTestEnvironment` export ([#12353](https://github.com/facebook/jest/pull/12353))
72+
- `[jest-create-cache-key-function]` Added README.md file with basic usage instructions ([#12492](https://github.com/facebook/jest/pull/12492))
7273
- `[@jest/core]` Use `index.ts` instead of `jest.ts` as main export ([#12329](https://github.com/facebook/jest/pull/12329))
7374
- `[jest-environment-jsdom]` [**BREAKING**] Migrate to ESM ([#12340](https://github.com/facebook/jest/pull/12340))
7475
- `[jest-environment-node]` [**BREAKING**] Migrate to ESM ([#12340](https://github.com/facebook/jest/pull/12340))
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# jest-create-cache-key-function
2+
3+
This module creates a function which is used for generating cache keys used by code transformers in Jest.
4+
5+
## Install
6+
7+
```sh
8+
$ npm install --save-dev @jest/create-cache-key-function
9+
```
10+
11+
## API
12+
13+
### `createCacheKey(files?: Array<string>, values?: Array<String>): GetCacheKeyFunction`
14+
15+
Get a function that can generate cache keys using source code, provided files and provided values.
16+
17+
#### Parameters
18+
19+
- `files`: [Optional] Array of absolute paths to files whose code should be accounted for when generating cache key
20+
- `values`: [Optional] Array of string values that should be accounted for when generating cache key
21+
22+
**Note:**
23+
24+
The source code for your test is already taken into account when generating the cache key. The `files` array should be used to provide files that are not directly related to your code such as external configuration files.
25+
26+
## Usage
27+
28+
Here is some sample usage code while creating a new transformer for Jest
29+
30+
```javascript
31+
const createCacheKeyFunction =
32+
require('@jest/create-cache-key-function').default;
33+
34+
const filesToAccountFor = [
35+
__filename,
36+
require.resolve('some-package-name/package.json'),
37+
];
38+
39+
const valuesToAccountFor = [process.env.SOME_LOCAL_ENV, 'Some_Other_Value'];
40+
41+
module.exports = {
42+
process(src, filename, config, options) {},
43+
getCacheKey: createCacheKeyFunction(filesToAccountFor, valuesToAccountFor),
44+
};
45+
```

0 commit comments

Comments
 (0)