-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: provides source map support for stack traces
- Loading branch information
Showing
17 changed files
with
292 additions
and
2 deletions.
There are no files selected for viewing
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 +1,3 @@ | ||
coverage | ||
test/fixtures/ts/app/controller/home.js | ||
test/fixtures/ts-pkg/app/controller/home.js |
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,8 +1,10 @@ | ||
logs/ | ||
npm-debug.log | ||
/node_modules | ||
node_modules | ||
coverage/ | ||
.idea/ | ||
run/ | ||
.DS_Store | ||
*.swp | ||
test/fixtures/ts/app/controller/home.js | ||
test/fixtures/ts-pkg/app/controller/home.js |
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
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
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,15 @@ | ||
import { Controller } from 'egg'; | ||
|
||
export default class AppController extends Controller { | ||
public async index() { | ||
try { | ||
throw new Error('some err'); | ||
} catch (err) { | ||
this.ctx.logger.error(err); | ||
this.ctx.body = { | ||
msg: err.message, | ||
stack: err.stack, | ||
}; | ||
} | ||
} | ||
}; |
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,6 @@ | ||
'use strict'; | ||
|
||
module.exports = app => { | ||
const { router, controller } = app; | ||
router.get('/', controller.home.index); | ||
}; |
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,3 @@ | ||
'use strict'; | ||
|
||
exports.keys = '123456'; |
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,13 @@ | ||
{ | ||
"name": "ts-pkg", | ||
"version": "1.0.0", | ||
"dependencies": { | ||
"egg": "^1.0.0" | ||
}, | ||
"egg": { | ||
"typescript": true | ||
}, | ||
"scripts": { | ||
"build": "node ../../../node_modules/.bin/tsc" | ||
} | ||
} |
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,29 @@ | ||
{ | ||
"compileOnSave": true, | ||
"compilerOptions": { | ||
"target": "es2017", | ||
"module": "commonjs", | ||
"strict": true, | ||
"noImplicitAny": false, | ||
"experimentalDecorators": true, | ||
"emitDecoratorMetadata": true, | ||
"charset": "utf8", | ||
"allowJs": false, | ||
"pretty": true, | ||
"noEmitOnError": false, | ||
"noUnusedLocals": true, | ||
"noUnusedParameters": true, | ||
"allowUnreachableCode": false, | ||
"allowUnusedLabels": false, | ||
"strictPropertyInitialization": false, | ||
"noFallthroughCasesInSwitch": true, | ||
"skipLibCheck": true, | ||
"skipDefaultLibCheck": true, | ||
"inlineSourceMap": true, | ||
"importHelpers": true | ||
}, | ||
"exclude": [ | ||
"app/public", | ||
"app/views" | ||
] | ||
} |
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,15 @@ | ||
import { Controller } from 'egg'; | ||
|
||
export default class AppController extends Controller { | ||
public async index() { | ||
try { | ||
throw new Error('some err'); | ||
} catch (err) { | ||
this.ctx.logger.error(err); | ||
this.ctx.body = { | ||
msg: err.message, | ||
stack: err.stack, | ||
}; | ||
} | ||
} | ||
}; |
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,6 @@ | ||
'use strict'; | ||
|
||
module.exports = app => { | ||
const { router, controller } = app; | ||
router.get('/', controller.home.index); | ||
}; |
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,3 @@ | ||
'use strict'; | ||
|
||
exports.keys = '123456'; |
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,10 @@ | ||
{ | ||
"name": "ts", | ||
"version": "1.0.0", | ||
"dependencies": { | ||
"egg": "^1.0.0" | ||
}, | ||
"scripts": { | ||
"build": "node ../../../node_modules/.bin/tsc" | ||
} | ||
} |
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,29 @@ | ||
{ | ||
"compileOnSave": true, | ||
"compilerOptions": { | ||
"target": "es2017", | ||
"module": "commonjs", | ||
"strict": true, | ||
"noImplicitAny": false, | ||
"experimentalDecorators": true, | ||
"emitDecoratorMetadata": true, | ||
"charset": "utf8", | ||
"allowJs": false, | ||
"pretty": true, | ||
"noEmitOnError": false, | ||
"noUnusedLocals": true, | ||
"noUnusedParameters": true, | ||
"allowUnreachableCode": false, | ||
"allowUnusedLabels": false, | ||
"strictPropertyInitialization": false, | ||
"noFallthroughCasesInSwitch": true, | ||
"skipLibCheck": true, | ||
"skipDefaultLibCheck": true, | ||
"inlineSourceMap": true, | ||
"importHelpers": true | ||
}, | ||
"exclude": [ | ||
"app/public", | ||
"app/views" | ||
] | ||
} |
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,114 @@ | ||
'use strict'; | ||
|
||
const path = require('path'); | ||
const assert = require('assert'); | ||
const cp = require('child_process'); | ||
const sleep = require('mz-modules/sleep'); | ||
const rimraf = require('mz-modules/rimraf'); | ||
const mkdirp = require('mz-modules/mkdirp'); | ||
const coffee = require('coffee'); | ||
const httpclient = require('urllib'); | ||
const mm = require('mm'); | ||
const utils = require('./utils'); | ||
|
||
describe.only('test/ts.test.js', () => { | ||
const eggBin = require.resolve('../bin/egg-scripts.js'); | ||
const homePath = path.join(__dirname, 'fixtures/home'); | ||
const waitTime = '3s'; | ||
let fixturePath; | ||
|
||
beforeEach(() => mm(process.env, 'MOCK_HOME_DIR', homePath)); | ||
afterEach(mm.restore); | ||
|
||
before(() => mkdirp(homePath)); | ||
after(() => rimraf(homePath)); | ||
|
||
describe('should display correct stack traces', () => { | ||
let app; | ||
beforeEach(function* () { | ||
fixturePath = path.join(__dirname, 'fixtures/ts'); | ||
yield utils.cleanup(fixturePath); | ||
const result = cp.spawnSync('npm', [ 'run', 'build' ], { cwd: fixturePath }); | ||
assert(!result.stderr.toString()); | ||
}); | ||
|
||
afterEach(function* () { | ||
app.proc.kill('SIGTERM'); | ||
yield utils.cleanup(fixturePath); | ||
}); | ||
|
||
it('--ts', function* () { | ||
app = coffee.fork(eggBin, [ 'start', '--workers=1', '--ts', fixturePath ]); | ||
// app.debug(); | ||
app.expect('code', 0); | ||
|
||
yield sleep(waitTime); | ||
|
||
assert(app.stderr === ''); | ||
assert(app.stdout.match(/egg started on http:\/\/127\.0\.0\.1:7001/)); | ||
const result = yield httpclient.request('http://127.0.0.1:7001', { dataType: 'json' }); | ||
// console.log(result.data); | ||
assert(result.data.stack.includes('app/controller/home.ts:6:13')); | ||
}); | ||
|
||
it('--typescript', function* () { | ||
app = coffee.fork(eggBin, [ 'start', '--workers=1', '--typescript', fixturePath ]); | ||
// app.debug(); | ||
app.expect('code', 0); | ||
|
||
yield sleep(waitTime); | ||
|
||
assert(app.stderr === ''); | ||
assert(app.stdout.match(/egg started on http:\/\/127\.0\.0\.1:7001/)); | ||
const result = yield httpclient.request('http://127.0.0.1:7001', { dataType: 'json' }); | ||
// console.log(result.data); | ||
assert(result.data.stack.includes('app/controller/home.ts:6:13')); | ||
}); | ||
|
||
it('--sourcemap', function* () { | ||
app = coffee.fork(eggBin, [ 'start', '--workers=1', '--sourcemap', fixturePath ]); | ||
// app.debug(); | ||
app.expect('code', 0); | ||
|
||
yield sleep(waitTime); | ||
|
||
assert(app.stderr === ''); | ||
assert(app.stdout.match(/egg started on http:\/\/127\.0\.0\.1:7001/)); | ||
const result = yield httpclient.request('http://127.0.0.1:7001', { dataType: 'json' }); | ||
// console.log(result.data); | ||
assert(result.data.stack.includes('app/controller/home.ts:6:13')); | ||
}); | ||
}); | ||
|
||
describe('pkg.egg.typescript', () => { | ||
let app; | ||
beforeEach(function* () { | ||
fixturePath = path.join(__dirname, 'fixtures/ts-pkg'); | ||
yield utils.cleanup(fixturePath); | ||
const result = cp.spawnSync('npm', [ 'run', 'build' ], { cwd: fixturePath }); | ||
assert(!result.stderr.toString()); | ||
}); | ||
|
||
afterEach(function* () { | ||
app.proc.kill('SIGTERM'); | ||
yield utils.cleanup(fixturePath); | ||
}); | ||
|
||
it('should got correct stack', function* () { | ||
app = coffee.fork(eggBin, [ 'start', '--workers=1', fixturePath ]); | ||
app.debug(); | ||
app.expect('code', 0); | ||
|
||
yield sleep(waitTime); | ||
|
||
assert(app.stderr === ''); | ||
assert(app.stdout.match(/egg started on http:\/\/127\.0\.0\.1:7001/)); | ||
const result = yield httpclient.request('http://127.0.0.1:7001', { dataType: 'json' }); | ||
// console.log(result.data); | ||
assert(result.data.stack.includes('app/controller/home.ts:6:13')); | ||
}); | ||
}); | ||
|
||
// TODO: add fixture for pkg egg.typescript | ||
}); | ||
|