Coder Social home page Coder Social logo

ashwanth1109 / jest-generator Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 80 KB

Deno script to auto generate jest UT starter for lambda handlers

Home Page: https://jest-generator.s3.ap-south-1.amazonaws.com/index.bundle.js

JavaScript 10.53% TypeScript 89.47%

jest-generator's Introduction

Jest Generator

Repo consists of:

  • Deno script to auto generate jest UT starter
  • CDK code to deploy script into S3 bucket

Current Features:

  • Currently, only mocks jest dependencies based on imports and sets up describe function

Planned Features:

  • Generate a basic template of success-failure tests for lambda
  • Deep mocking of dependencies used (if possible)

Instructions for use:

1. Create your deployment env if you want to use your own S3 bucket to store your Deno script object

  • Run aws configure
  • Add user's ACCESS KEY ID and SECRET KEY to create default profile
  • Run cdk bootstrap aws://<account>/<region> in deploy folder if deploying env for the first time
  • Run deploy from root (or deploy) folder to deploy your CDK stack

Note: Alternatively, the object url for the script can be shared between multiple people

2. Install deno on your machine

Follow the instructions here

3. Run the deno run command as follows:

Command syntax:

deno run --allow-read --allow-write <s3-url-to-script> <input-file-name> <output-file-name>

Command example:

  • deno run --allow-read --allow-write https://jest-generator.s3.ap-south-1.amazonaws.com/index.bundle.js handler.ts handler.spec.ts

4. You can create an alias to run this command without typing the whole thing

In your powershell profile, you can add the following alias

Function SpecGen($readFile, $writeFile) {
    deno run --allow-read --allow-write https://jest-generator.s3.ap-south-1.amazonaws.com/index.bundle.js $readFile $writeFile;
}

Set-Alias spec-gen SpecGen

5. You can now run the command with your alias

Example usage:

spec-gen handler.ts handler.spec.ts

Deploying changes to deno script to S3 bucket

Run build (also cleans up previous dist):

  • npm run build

Run deploy:

  • npm run deploy

You should now be able to see your new deno script in your S3 bucket

Important Notes:

  • Meant to be a starting point for the generated test setup, you will then need to add on top of that
  • May generate incorrectly or fail but any output will only be added to end of existing files and not overwrite them
  • You can remove the generated code if it doesn't and raise an issue with input and expected output (if possible), and I can work on improving the script

jest-generator's People

Contributors

ashwanth1109 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.