jest-transform-cloudfront-function
v1.0.1
Published
A simple jest transform to add module.exports=handler; to the end of cloudfront functions for testing.
Downloads
11
Readme
jest-transform-cloudfront-function
Jest transform to add ;module.exports=handler;
to the end of cloudfront functions for testing.
Description
When writing a cloudfront function you don't include an export statement which means it cannot be imported for testing with a tool like jest.
We don't want to modify or rewrite our code just for the sake of testing.
This package takes a very simple brute-force approach of adding ;module.exports=handler;
to the end of any js file you test so that you can access the handler function in a test.
This package will only work if the function you're testing is called
handler
.
Installation
# NPM
npm install jest-transform-cloudfront-function --save-dev
# Yarn
yarn add jest-transform-cloudfront-function --dev --exact
# PNPM
pnpm add jest-transform-cloudfront-function --save-dev --save-exact
Usage
In your jest.config.js
(or jest.config.ts
) file, add
the following:
module.exports = {
// ...
transform: {
// ... other transforms ...
"\\.js$": "jest-transform-cloudfront-function",
},
// ...
}