Skip to content

Commit 04efc05

Browse files
committed
f
1 parent b9fe64d commit 04efc05

File tree

7 files changed

+127
-123
lines changed

7 files changed

+127
-123
lines changed

src/commands/start.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ export default class Start<T extends typeof Start> extends BaseCommand<T> {
223223
flags.sourcemap = true;
224224
}
225225
if (flags.sourcemap) {
226-
const sourceMapSupport = importResolve('source-map-support/register', {
226+
const sourceMapSupport = importResolve('source-map-support/register.js', {
227227
paths: [ getSourceDirname() ],
228228
});
229229
if (this.isESM) {
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
'use strict';
2-
31
module.exports = app => {
4-
app.get('/', function* () {
2+
app.get('/', async function() {
53
this.body = `hi, ${app.config.framework || 'egg'}`;
64
});
75

8-
app.get('/env', function* () {
6+
app.get('/env', async function() {
97
this.body = app.config.env + ', ' + app.config.pre;
108
});
119

12-
app.get('/path', function* () {
10+
app.get('/path', async function() {
1311
this.body = process.env.PATH;
1412
});
1513
};

test/fixtures/ts-pkg/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"typescript": true
99
},
1010
"scripts": {
11-
"build": "node ../../../node_modules/.bin/tsc",
11+
"build": "sh ../../../node_modules/.bin/tsc",
1212
"windows-build": "call ../../../node_modules/.bin/tsc.cmd"
1313
}
1414
}

test/fixtures/ts/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"egg": "^1.0.0"
66
},
77
"scripts": {
8-
"build": "node ../../../node_modules/.bin/tsc",
8+
"build": "sh ../../../node_modules/.bin/tsc",
99
"windows-build": "call ../../../node_modules/.bin/tsc.cmd"
1010
}
1111
}

test/fixtures/ts/tsconfig.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
"noImplicitAny": false,
88
"experimentalDecorators": true,
99
"emitDecoratorMetadata": true,
10-
"charset": "utf8",
1110
"allowJs": false,
1211
"pretty": true,
1312
"noEmitOnError": false,
@@ -26,4 +25,4 @@
2625
"app/public",
2726
"app/views"
2827
]
29-
}
28+
}

test/ts.test.js

Lines changed: 0 additions & 113 deletions
This file was deleted.

test/ts.test.ts

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
import path from 'node:path';
2+
import { fileURLToPath } from 'node:url';
3+
import { strict as assert } from 'node:assert';
4+
import fs from 'node:fs/promises';
5+
import cp from 'node:child_process';
6+
import { scheduler } from 'node:timers/promises';
7+
import coffee from 'coffee';
8+
import { request } from 'urllib';
9+
import { mm, restore } from 'mm';
10+
import { cleanup, replaceWeakRefMessage, Coffee } from './utils.js';
11+
import { isWindows, getSourceFilename } from '../src/helper.js';
12+
13+
const __filename = fileURLToPath(import.meta.url);
14+
const __dirname = path.dirname(__filename);
15+
16+
describe('test/ts.test.ts', () => {
17+
const eggBin = getSourceFilename('../bin/run.js');
18+
const homePath = path.join(__dirname, 'fixtures/home');
19+
const waitTime = 5000;
20+
let fixturePath: string;
21+
22+
beforeEach(() => mm(process.env, 'MOCK_HOME_DIR', homePath));
23+
afterEach(restore);
24+
25+
before(() => fs.mkdir(homePath, { recursive: true }));
26+
after(() => fs.rm(homePath, { recursive: true, force: true }));
27+
28+
describe('should display correct stack traces', () => {
29+
let app: Coffee;
30+
beforeEach(async () => {
31+
fixturePath = path.join(__dirname, 'fixtures/ts');
32+
await cleanup(fixturePath);
33+
const result = cp.spawnSync('npm', [ 'run', isWindows ? 'windows-build' : 'build' ], {
34+
cwd: fixturePath,
35+
shell: isWindows,
36+
});
37+
assert.equal(result.stderr.toString(), '');
38+
});
39+
40+
afterEach(async () => {
41+
app && app.proc.kill('SIGTERM');
42+
await cleanup(fixturePath);
43+
});
44+
45+
it('--ts', async () => {
46+
app = coffee.fork(eggBin, [ 'start', '--workers=1', '--ts', fixturePath ]) as Coffee;
47+
// app.debug();
48+
app.expect('code', 0);
49+
50+
await scheduler.wait(waitTime);
51+
52+
assert.equal(replaceWeakRefMessage(app.stderr), '');
53+
assert.match(app.stdout, /egg started on http:\/\/127\.0\.0\.1:7001/);
54+
const result = await request('http://127.0.0.1:7001', { dataType: 'json' });
55+
// console.log(result.data);
56+
assert(result.data.stack.includes(path.normalize('app/controller/home.ts:6:13')));
57+
});
58+
59+
it('--typescript', async () => {
60+
app = coffee.fork(eggBin, [ 'start', '--workers=1', '--typescript', fixturePath ]) as Coffee;
61+
// app.debug();
62+
app.expect('code', 0);
63+
64+
await scheduler.wait(waitTime);
65+
66+
assert.equal(replaceWeakRefMessage(app.stderr), '');
67+
assert.match(app.stdout, /egg started on http:\/\/127\.0\.0\.1:7001/);
68+
const result = await request('http://127.0.0.1:7001', { dataType: 'json' });
69+
// console.log(result.data);
70+
assert(result.data.stack.includes(path.normalize('app/controller/home.ts:6:13')));
71+
});
72+
73+
it('--sourcemap', async () => {
74+
app = coffee.fork(eggBin, [ 'start', '--workers=1', '--sourcemap', fixturePath ]) as Coffee;
75+
// app.debug();
76+
app.expect('code', 0);
77+
78+
await scheduler.wait(waitTime);
79+
80+
assert.equal(replaceWeakRefMessage(app.stderr), '');
81+
assert.match(app.stdout, /egg started on http:\/\/127\.0\.0\.1:7001/);
82+
const result = await request('http://127.0.0.1:7001', { dataType: 'json' });
83+
// console.log(result.data);
84+
assert(result.data.stack.includes(path.normalize('app/controller/home.ts:6:13')));
85+
});
86+
});
87+
88+
describe('pkg.egg.typescript', () => {
89+
let app: Coffee;
90+
beforeEach(async () => {
91+
fixturePath = path.join(__dirname, 'fixtures/ts-pkg');
92+
await cleanup(fixturePath);
93+
const result = cp.spawnSync('npm', [ 'run', isWindows ? 'windows-build' : 'build' ], {
94+
cwd: fixturePath,
95+
shell: isWindows,
96+
});
97+
assert(!result.stderr.toString());
98+
});
99+
100+
afterEach(async () => {
101+
app && app.proc.kill('SIGTERM');
102+
await cleanup(fixturePath);
103+
});
104+
105+
it('should got correct stack', async () => {
106+
app = coffee.fork(eggBin, [ 'start', '--workers=1', fixturePath ]) as Coffee;
107+
// app.debug();
108+
app.expect('code', 0);
109+
110+
await scheduler.wait(waitTime);
111+
112+
assert.equal(replaceWeakRefMessage(app.stderr), '');
113+
assert.match(app.stdout, /egg started on http:\/\/127\.0\.0\.1:7001/);
114+
const result = await request('http://127.0.0.1:7001', { dataType: 'json' });
115+
// console.log(result.data);
116+
assert(result.data.stack.includes(path.normalize('app/controller/home.ts:6:13')));
117+
});
118+
});
119+
});
120+

0 commit comments

Comments
 (0)