Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/cancerberosgx/resource-mocker

API and CLI to mock a static resources like .js, .css, .html files in a local server
https://github.com/cancerberosgx/resource-mocker

Last synced: about 1 month ago
JSON representation

API and CLI to mock a static resources like .js, .css, .html files in a local server

Awesome Lists containing this project

README

        

API and CLI sto mock a static resources like .js, .css, .html files in a local server. It creates a real http local server that serves provided resources.

# Usage

```sh
npm install --save-dev resource-mocker
```

```js

import { ServerMocker } from 'resource-mocker'
import { get } from 'hyperquest-promise'

const resources = [
{ name: '/file1.js', content: 'window.file1 = "file1"' },
{
name: '/file1.html', content: `

hello world1

`
},
]
const mocker = new ServerMocker({ port: 3000, resources })
mocker.start()

let { data } = await get('http://localhost:3000/file1.html')
expect(data).toContain('hello world1')
mocker.shutdown()
```

# TODO

* read config from .json file
* CLI (so I can entre `resource-mocker --config test-assets/resources1.json` --port 3000)
* suggestion: build .json of resources in folder (using my program fs-to-json)

-->



-->

-->

-->
-->


-->