Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix "missing ) after argument list" #7

Merged
merged 3 commits into from
Feb 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Record HTTP interactions The Node Way™. Inspired by ruby's [vcr][1].

```bash
$ npm install yaktime --save-dev
$ yarn add --dev yaktime
```

## usage
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "yaktime",
"version": "3.1.6",
"description": "",
"main": "lib/yaktime.js",
"main": "lib/index.js",
"directories": {
"lib": "lib"
},
Expand Down
4 changes: 4 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export { RequestHasher, YakTimeOpts, YakTimeServer } from './util'
export { yaktime } from './yaktime'
export { AsyncServer, createAsyncServer } from './AsyncServer'
export { createYaktimeServer } from './yaktimeServer'
30 changes: 18 additions & 12 deletions src/tape.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import { EventEmitter } from 'events'

const linter = require('standard')

const isStandardJs = (js: string) => linter.lintTextSync(js, {}).errorCount === 0
// We will have quotes error on the standard
const isStandardJs = (js: string) => linter.lintTextSync(js, {}).results.every(r => r.messages[0].ruleId === 'quotes')

const req: unknown = {
method: 'GET',
path: '/about?foo=bar',
Expand Down Expand Up @@ -32,7 +34,8 @@ describe('buildTape', () => {

const res: unknown = getRes(body, {
'content-type': 'image/gif',
'content-encoding': 'gzip'
'content-encoding': 'gzip',
foo: 'bar\'bar"bar`bar'
})

const tape = buildTape(req as ClientRequest, res as IncomingMessage)
Expand All @@ -56,13 +59,14 @@ describe('buildTape', () => {
module.exports = function (req, res) {
res.statusCode = 200

res.setHeader('content-type', 'image/gif')
res.setHeader('content-encoding', 'gzip')
res.setHeader('content-type', "image/gif")
res.setHeader('content-encoding', "gzip")
res.setHeader('foo', "bar'bar\\"bar\`bar")

res.setHeader('x-yakbak-tape', basename(__filename, '.js'))

res.write(Buffer.from('Q0hPTg==', 'base64'))
res.write(Buffer.from('TUFHVUU=', 'base64'))
res.write(Buffer.from("Q0hPTg==", 'base64'))
res.write(Buffer.from("TUFHVUU=", 'base64'))
res.end()

return __filename
Expand All @@ -76,12 +80,13 @@ module.exports = function (req, res) {

const res: unknown = getRes(body, {
'content-type': 'text/html',
'content-encoding': 'identity'
'content-encoding': 'identity',
foo: 'bar\'bar"bar`bar'
})

const tape = buildTape(req as ClientRequest, res as IncomingMessage)
body.emit('data', Buffer.from('YAK'))
body.emit('data', Buffer.from('TIME'))
body.emit('data', Buffer.from('\'"`TIME'))
body.emit('end')

expect(await tape).toEqual(`const { basename } = require('path')
Expand All @@ -101,13 +106,14 @@ module.exports = function (req, res) {
module.exports = function (req, res) {
res.statusCode = 200

res.setHeader('content-type', 'text/html')
res.setHeader('content-encoding', 'identity')
res.setHeader('content-type', "text/html")
res.setHeader('content-encoding', "identity")
res.setHeader('foo', "bar'bar\\"bar\`bar")

res.setHeader('x-yakbak-tape', basename(__filename, '.js'))

res.write(Buffer.from('YAK', 'utf8'))
res.write(Buffer.from('TIME', 'utf8'))
res.write(Buffer.from("YAK", 'utf8'))
res.write(Buffer.from("'\\"\`TIME", 'utf8'))
res.end()

return __filename
Expand Down
4 changes: 2 additions & 2 deletions src/tape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ export async function buildTape (req: ClientRequest, res: IncomingMessage) {
const requestHeaders = joinIndented(map(req.getHeaders(), (value, header) => `${header}: ${escapeComments((value || '').toString())}`), {
indent: ' * '
})
const responseHeaders = joinIndented(map(res.headers, (value, header) => `res.setHeader('${header}', '${value}')`))
const bodyText = joinIndented(body.map(data => `res.write(Buffer.from('${data.toString(encoding)}', '${encoding}'))`))
const responseHeaders = joinIndented(map(res.headers, (value, header) => `res.setHeader('${header}', ${JSON.stringify(value)})`))
const bodyText = joinIndented(body.map(data => `res.write(Buffer.from(${JSON.stringify(data.toString(encoding))}, '${encoding}'))`))

return `const { basename } = require('path')

Expand Down
10 changes: 5 additions & 5 deletions src/test/fixtures/v1.5.0.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ const { basename } = require('path')
module.exports = function (req, res) {
res.statusCode = 201

res.setHeader('content-type', 'text/html')
res.setHeader('date', 'Sat, 26 Oct 1985 08:20:00 GMT')
res.setHeader('connection', 'close')
res.setHeader('content-length', '2')
res.setHeader('content-type', "text/html")
res.setHeader('date', "Sat, 26 Oct 1985 08:20:00 GMT")
res.setHeader('connection', "close")
res.setHeader('content-length', "2")

res.setHeader('x-yakbak-tape', basename(__filename, '.js'))

res.write(Buffer.from('OK', 'utf8'))
res.write(Buffer.from("OK", 'utf8'))
res.end()

return __filename
Expand Down
2 changes: 1 addition & 1 deletion src/yaktime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const incMessH = require('incoming-message-hash')
const messageHash: RequestHasher = incMessH.sync

/**
* Returns a new yaktime proxy middleware.
* Returns a function of the signature function (req, res) that you can give to an `http.Server` as its handler.
* @param - host The hostname to proxy to
* @param - opts
*/
Expand Down