# resource-mocker

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

Latest version **0.0.2** (published 2018-09-05) · MIT license · 0 weekly downloads

## Install

```sh
npm install resource-mocker
pnpm add resource-mocker
yarn add resource-mocker
bun add resource-mocker
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.2 |
| Published | 2018-09-05 |
| First published | 2018-09-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 14.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Sebastian Gurin |
| Maintainers | cancerberosgx |
| Keywords | resource mocker, test, server mocker, server mock |

## Links

- npm: https://www.npmjs.com/package/resource-mocker
- Repository: https://github.com/cancerberoSgx/resource-mocker
- Homepage: https://github.com/cancerberoSgx/resource-mocker#readme
- Issues: https://github.com/cancerberoSgx/resource-mocker/issues
- npm.io page: https://npm.io/package/resource-mocker

## Alternatives

- [duck](https://npm.io/package/duck.md) — 4.2M weekly downloads
- [ava](https://npm.io/package/ava.md) — 560.2K weekly downloads
- [storybook-addon-module-mock](https://npm.io/package/storybook-addon-module-mock.md) — 71.7K weekly downloads
- [vest](https://npm.io/package/vest.md) — 50.1K weekly downloads
- [@ethereum-waffle/mock-contract](https://npm.io/package/@ethereum-waffle/mock-contract.md) — 40.0K weekly downloads

## Recent versions

- 0.0.2 (latest) — 2018-09-05
- 0.0.1 — 2018-09-05

## 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: `
<html>
<head><title>hello world1</title></head>
<body><script src="file1.js"></script></body>
</html>`
  },
]
const mocker = new ServerMocker({ port: 3000, resources })
mocker.start()

let { data } = await get('http://localhost:3000/file1.html')
expect(data).toContain('<title>hello world1</title>')
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)



<!-- 
<!-- ### Backup -->
<!-- move to other file : -->
<!-- Language (basic) --> -->
<!-- 
 <!-- * code is evaluated from "top to bottom" and ingeneral from right to left -->
 <!-- * variables (they are name for values) -->
 <!-- * assignments: let a = 1 -->
 <!-- * statements (console.log(3.14)) --> -->
<!--  -->
<!-- 
<!-- Data (basic) --> -->
<!-- 
 <!-- * explain -->
<!-- Behavior (basic) --> -->
<!-- 
<!-- Data + behavior (basic) --> -->
<!-- 
 <!-- * array filter, find, map -->
 <!-- * basic object manipulation (propert) -->
 <!-- * string substring, concatenation --> -->
<!--  -->
<!--  -->

---
_Source: https://npm.io/package/resource-mocker · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
