An open API service indexing awesome lists of open source software.

https://github.com/enzoferey/jest-test-my-code

Test code server side with Jest
https://github.com/enzoferey/jest-test-my-code

jest serverside testing

Last synced: 2 months ago
JSON representation

Test code server side with Jest

Awesome Lists containing this project

README

          

# 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**

3. Make a POST request with an `application/json` body like:

```json
{
"test": "add",
"code": "your code stringified here"
}
```

**Test React component example**

3. Make a POST request with an `application/json` body like:

```json
{
"test": "MyText",
"code": "import React from \"react\"; const MyText = ({ name }) =>

Hello ${name}

;"
}
```

## 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//index.js`, clone the test file to that same directory and use the default export of `index.js` as the test function.