Skip to content

enzoferey/jest-test-my-code

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

jest-test-my-code

Test code server side with Jest

This is for demonstration purposes, feel free to fork it and adapt it to your use case.

Usage

  1. Clone repository
  2. Start server running npm start

Test JS code example

  1. Make a POST request with an application/json body like:
{
  "test": "add",
  "code": "your code stringified here"
}

Test React component example

  1. Make a POST request with an application/json body like:
{
  "test": "MyText",
  "code": "import React from \"react\"; const MyText = ({ name }) => <p>Hello ${name}</p>;"
}

Notes

The method used right now is to expose user code in the global object through Jest's setupFrameworkFile, creating one setup file per user.

Another option could be to write received code to __tests__/tmp/<user_token>/index.js, clone the test file to that same directory and use the default export of index.js as the test function.

About

Test code server side with Jest

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published