-
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
I hate myself for not writing tests at first place and everyone faced issues coz of same. Fixing it
- Loading branch information
1 parent
972b718
commit 0918cb5
Showing
7 changed files
with
162 additions
and
15 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,12 @@ | ||
language: node_js | ||
env: | ||
- CXX=g++-4.8 | ||
addons: | ||
apt: | ||
sources: | ||
- ubuntu-toolchain-r-test | ||
packages: | ||
- g++-4.8 | ||
node_js: | ||
- node | ||
- 5.3.0 | ||
- 6.0.0 | ||
- 5.0.0 | ||
- 4.0.0 | ||
sudo: false | ||
install: | ||
- npm install --no-optional | ||
- npm install | ||
notifications: | ||
slack: | ||
secure: m91zkX2cLVDRDMBAUnR1d+hbZqtSHXLkuPencHadhJ3C3wm53Box8U25co/goAmjnW5HNJ1SMSIg+DojtgDhqTbReSh5gSbU0uU8YaF8smbvmUv3b2Q8PRCA7f6hQiea+a8+jAb7BOvwh66dV4Al/1DJ2b4tCjPuVuxQ96Wll7Pnj1S7yW/Hb8fQlr9wc+INXUZOe8erFin+508r5h1L4Xv0N5ZmNw+Gqvn2kPJD8f/YBPpx0AeZdDssTL0IOcol1+cDtDzMw5PAkGnqwamtxhnsw+i8OW4avFt1GrRNlz3eci5Cb3NQGjHxJf+JIALvBeSqkOEFJIFGqwAXMctJ9q8/7XyXk7jVFUg5+0Z74HIkBwdtLwi/BTyXMZAgsnDjndmR9HsuBP7OSTJF5/V7HCJZAaO9shEgS8DwR78owv9Fr5er5m9IMI+EgSH3qtb8iuuQaPtflbk+cPD3nmYbDqmPwkSCXcXRfq3IxdcV9hkiaAw52AIqqhnAXJWZfL6+Ct32i2mtSaov9FYtp/G0xb4tjrUAsDUd/AGmMJNEBVoHtP7mKjrVQ35cEtFwJr/8SmZxGvOaJXPaLs43dhXKa2tAGl11wF02d+Rz1HhbOoq9pJvJuqkLAVvRdBHUJrB4/hnTta5B0W5pe3mIgLw3AmOpk+s/H4hAP4Hp0gOWlPA= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
environment: | ||
matrix: | ||
- nodejs_version: 'Stable' | ||
- nodejs_version: '6' | ||
- nodejs_version: '5' | ||
- nodejs_version: '4' | ||
|
||
init: | ||
git config --global core.autocrlf true | ||
|
||
install: | ||
- ps: Install-Product node $env:nodejs_version | ||
- npm install | ||
|
||
test_script: | ||
- node --version | ||
- npm --version | ||
- npm run test:win | ||
|
||
build: off | ||
clone_depth: 1 | ||
|
||
matrix: | ||
fast_finish: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
'use strict' | ||
|
||
const http = require('http') | ||
const supertest = require('supertest') | ||
const test = require('japa') | ||
const Youch = require('../src/Youch') | ||
|
||
const DEFAULT_PORT=8000 | ||
|
||
test.group('Youch', () => { | ||
|
||
test('initiate a new instance by passing error object', (assert) => { | ||
const error = new Error('foo') | ||
const youch = new Youch(error, {}) | ||
assert.equal(youch.error.message, 'foo') | ||
assert.deepEqual(youch.request, {}) | ||
}) | ||
|
||
test('parse the error into frames', (assert, done) => { | ||
assert.plan(2) | ||
const error = new Error('foo') | ||
const youch = new Youch(error, {}) | ||
youch | ||
._parseError() | ||
.then((stack) => { | ||
assert.equal(stack[0].fileName, __filename) | ||
assert.equal(stack[0].native, false) | ||
done() | ||
}).catch(done) | ||
}) | ||
|
||
test('parse stack frame context to tokens', (assert, done) => { | ||
const error = new Error('this is bar') | ||
const youch = new Youch(error, {}) | ||
|
||
youch | ||
._parseError() | ||
.then((stack) => { | ||
const context = youch._getContext(stack[0]) | ||
assert.equal(context.line.trim(), 'const error = new Error(\'this is bar\')') | ||
done() | ||
}) | ||
.catch(done) | ||
}) | ||
|
||
test('return active class when index is 0', (assert) => { | ||
const error = new Error('this is bar') | ||
const youch = new Youch(error, {}) | ||
const frame = { | ||
isNative: () => false, | ||
getFileName: () => './hello.js' | ||
} | ||
|
||
const classes = youch._getDisplayClasses(frame, 0) | ||
assert.equal(classes, 'active') | ||
}) | ||
|
||
test('return native frame class when frame is native', (assert) => { | ||
const error = new Error('this is bar') | ||
const youch = new Youch(error, {}) | ||
const frame = { | ||
isNative: () => true, | ||
getFileName: () => './hello.js' | ||
} | ||
|
||
const classes = youch._getDisplayClasses(frame, 0) | ||
assert.equal(classes, 'active native-frame') | ||
}) | ||
|
||
test('return native frame class when frame is from node_modules', (assert) => { | ||
const error = new Error('this is bar') | ||
const youch = new Youch(error, {}) | ||
const frame = { | ||
isNative: () => false, | ||
getFileName: () => './node_modules/hello.js' | ||
} | ||
|
||
const classes = youch._getDisplayClasses(frame, 0) | ||
assert.equal(classes, 'active native-frame') | ||
}) | ||
|
||
test('serialize http request', (assert, done) => { | ||
const server = http.createServer((req, res) => { | ||
const youch = new Youch({}, req) | ||
res.writeHead(200, {'content-type': 'application/json'}) | ||
res.write(JSON.stringify(youch._serializeRequest())) | ||
res.end() | ||
}).listen(DEFAULT_PORT) | ||
|
||
supertest(server).get('/').end((error, response) => { | ||
if (error) { | ||
done(error) | ||
return | ||
} | ||
|
||
assert.isArray(response.body.cookies) | ||
assert.deepEqual(response.body.cookies, []) | ||
assert.equal(response.body.url, '/') | ||
assert.isArray(response.body.headers) | ||
server.close() | ||
done() | ||
}) | ||
}) | ||
|
||
test('serialize http request and return cookies from it', (assert, done) => { | ||
const server = http.createServer((req, res) => { | ||
const youch = new Youch({}, req) | ||
res.writeHead(200, {'content-type': 'application/json'}) | ||
res.write(JSON.stringify(youch._serializeRequest())) | ||
res.end() | ||
}).listen(DEFAULT_PORT) | ||
|
||
supertest(server).get('/').set('Cookie', 'name=virk; Path=/').end((error, response) => { | ||
if (error) { | ||
done(error) | ||
return | ||
} | ||
|
||
assert.isArray(response.body.cookies) | ||
assert.deepEqual(response.body.cookies, [{key: 'name', value: 'virk'}, {key: 'Path', value: '/'}]) | ||
assert.equal(response.body.url, '/') | ||
assert.isArray(response.body.headers) | ||
done() | ||
}) | ||
}) | ||
}) |