jest-transform-cloudfront-function

1.0.1 • Public • Published

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",
    },
    // ...
}

Readme

Keywords

none

Package Sidebar

Install

npm i jest-transform-cloudfront-function

Weekly Downloads

27

Version

1.0.1

License

MIT

Unpacked Size

4.79 kB

Total Files

6

Last publish

Collaborators

  • nickheal