-
Notifications
You must be signed in to change notification settings - Fork 38
/
ts.test.js
114 lines (92 loc) · 3.68 KB
/
ts.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
'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('test/ts.test.js', () => {
const eggBin = require.resolve('../bin/egg-scripts.js');
const homePath = path.join(__dirname, 'fixtures/home');
const waitTime = '5s';
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
});