npm.io
0.0.2 • Published 8 years ago

resource-mocker

Licence
MIT
Version
0.0.2
Deps
0
Size
14 kB
Vulns
0
Weekly
0

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

npm install --save-dev resource-mocker

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)
--> --> --> --> --> -->

Keywords