From e386d76da5f6a42b63e3e5d0f734b0b98c525d36 Mon Sep 17 00:00:00 2001 From: Hammad Date: Thu, 24 Feb 2022 21:27:13 -0330 Subject: [PATCH 1/3] docs: add a new README file with some documentation on the basic usage of the jest-create-cache-key-function package (#12004) --- .../jest-create-cache-key-function/README.md | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 packages/jest-create-cache-key-function/README.md diff --git a/packages/jest-create-cache-key-function/README.md b/packages/jest-create-cache-key-function/README.md new file mode 100644 index 000000000000..414ee43aca91 --- /dev/null +++ b/packages/jest-create-cache-key-function/README.md @@ -0,0 +1,48 @@ +# jest-create-cache-key-function + +This module creates a function which is used for generating cache keys used by code transformers in Jest. + +## Install + +```sh +$ npm install --save-dev @jest/create-cache-key-function +``` + +## API + +### `createCacheKey(files?: Array, values?: Array): GetCacheKeyFunction` + +Get a function that can generate cache keys using source code, provided files and provided values. + +#### Parameters + +- `files`: [Optional] Array of absolute paths to files whose code should be accounted for when generating cache key +- `values`: [Optional] Array of string values that should be accounted for when generating cache key + +**Note:** + +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. + +## Usage + +Here is some sample usage code while creating a new transformer for Jest + +```javascript +const createCacheKeyFunction = require('@jest/create-cache-key-function').default; + +const filesToAccountFor = [ + __filename, + require.resolve('some-package-name/package.json'), +]; + +const valuesToAccountFor = [ + process.env.SOME_LOCAL_ENV, + "Some_Other_Value" +] + +module.exports = { + process(src, filename, config, options) {}, + getCacheKey: createCacheKeyFunction(filesToAccountFor, valuesToAccountFor), +}; +``` From 22f77028f1f17d7f4792454c0283b375cc801060 Mon Sep 17 00:00:00 2001 From: Hammad Date: Thu, 24 Feb 2022 21:49:49 -0330 Subject: [PATCH 2/3] Update CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4ae06c8a4e65..8428e99f04a0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -66,6 +66,7 @@ - `[expect]` [**BREAKING**] Snapshot matcher types are moved to `@jest/expect` ([#12404](https://github.com/facebook/jest/pull/12404)) - `[jest-cli]` Update `yargs` to v17 ([#12357](https://github.com/facebook/jest/pull/12357)) - `[jest-config]` [**BREAKING**] Remove `getTestEnvironment` export ([#12353](https://github.com/facebook/jest/pull/12353)) +- `[jest-create-cache-key-function]` Added README.md file with basic usage instructions ([#12492](https://github.com/facebook/jest/pull/12492)) - `[@jest/core]` Use `index.ts` instead of `jest.ts` as main export ([#12329](https://github.com/facebook/jest/pull/12329)) - `[jest-environment-jsdom]` [**BREAKING**] Migrate to ESM ([#12340](https://github.com/facebook/jest/pull/12340)) - `[jest-environment-node]` [**BREAKING**] Migrate to ESM ([#12340](https://github.com/facebook/jest/pull/12340)) From 9b0630e54e27644000964cbfa859e012290de148 Mon Sep 17 00:00:00 2001 From: Hammad Date: Fri, 25 Feb 2022 09:31:51 -0330 Subject: [PATCH 3/3] Ran prettier to fix formatting issues in the readme file --- packages/jest-create-cache-key-function/README.md | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/packages/jest-create-cache-key-function/README.md b/packages/jest-create-cache-key-function/README.md index 414ee43aca91..cd014e038c6b 100644 --- a/packages/jest-create-cache-key-function/README.md +++ b/packages/jest-create-cache-key-function/README.md @@ -21,25 +21,22 @@ Get a function that can generate cache keys using source code, provided files an **Note:** -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. +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. ## Usage Here is some sample usage code while creating a new transformer for Jest ```javascript -const createCacheKeyFunction = require('@jest/create-cache-key-function').default; +const createCacheKeyFunction = + require('@jest/create-cache-key-function').default; const filesToAccountFor = [ __filename, require.resolve('some-package-name/package.json'), ]; -const valuesToAccountFor = [ - process.env.SOME_LOCAL_ENV, - "Some_Other_Value" -] +const valuesToAccountFor = [process.env.SOME_LOCAL_ENV, 'Some_Other_Value']; module.exports = { process(src, filename, config, options) {},