Skip to content

Commit

Permalink
fix: conflix source map support
Browse files Browse the repository at this point in the history
  • Loading branch information
wanghx committed Jul 5, 2022
1 parent 9aeb61d commit faaf4f0
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 10 deletions.
17 changes: 9 additions & 8 deletions lib/cmd/test.js
Expand Up @@ -111,15 +111,16 @@ class TestCommand extends Command {
if (requireArr.includes('intelli-espower-loader')) {
console.warn('[egg-bin] don\'t need to manually require `intelli-espower-loader` anymore');
} else if (testArgv.espower) {
requireArr.push(require.resolve('intelli-espower-loader'));
}

// for power-assert
if (testArgv.typescript && testArgv.espower) {
if (requireArr.includes(testArgv.tscompiler)) {
requireArr.splice(requireArr.indexOf(testArgv.tscompiler), 1);
if (testArgv.typescript) {
if (requireArr.includes(testArgv.tscompiler)) {
requireArr.splice(requireArr.indexOf(testArgv.tscompiler), 1);
}

// espower-typescript must append after ts-node
requireArr.push(testArgv.tscompiler, require.resolve('../espower-typescript'));
} else {
requireArr.push(require.resolve('intelli-espower-loader'));
}
requireArr.push(testArgv.tscompiler, require.resolve('../espower-typescript'));
}

testArgv.require = requireArr;
Expand Down
4 changes: 2 additions & 2 deletions lib/espower-typescript.js
Expand Up @@ -8,8 +8,8 @@ const sourceCache = {};
const cwd = process.cwd();

espowerTypeScript({
pattern: path.resolve(cwd, 'test/**/*.@(ts|tsx)'),
extensions: [ 'ts', 'tsx' ],
pattern: path.resolve(cwd, 'test/**/*.@(js|jsx|ts|tsx)'),
extensions: [ 'js', 'jsx', 'ts', 'tsx' ],
});

function espowerTypeScript(options) {
Expand Down
9 changes: 9 additions & 0 deletions test/fixtures/example-ts-error-stack-mixed/app.ts
@@ -0,0 +1,9 @@
export default function() {
// placeholder comments
// placeholder comments
// placeholder comments
// placeholder comments
if (process.env.THROW_ERROR === 'true') {
throw new Error('throw error');
}
}
@@ -0,0 +1,7 @@
'use strict';

export default () => {
const config = {} as any;
config.keys = '123456';
return config;
};
6 changes: 6 additions & 0 deletions test/fixtures/example-ts-error-stack-mixed/package.json
@@ -0,0 +1,6 @@
{
"name": "example-ts-error-stack",
"egg": {
"typescript": true
}
}
16 changes: 16 additions & 0 deletions test/fixtures/example-ts-error-stack-mixed/test/index.test.js
@@ -0,0 +1,16 @@
'use strict';

const assert = require('assert');

describe('test/index.test.ts', () => {
// placeholder comments
it('should throw error', async () => {
throw new Error('error');
});

// placeholder comments
it('should assert', async () => {
const obj = { key: '111' };
assert(obj.key === '222');
});
});
19 changes: 19 additions & 0 deletions test/fixtures/example-ts-error-stack-mixed/tsconfig.json
@@ -0,0 +1,19 @@
{
"compilerOptions": {
"target": "es2017",
"module": "commonjs",
"strict": true,
"noImplicitAny": false,
"moduleResolution": "node",
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"pretty": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true,
"skipLibCheck": true,
"skipDefaultLibCheck": true,
"inlineSourceMap": true,
"importHelpers": true
},
}
18 changes: 18 additions & 0 deletions test/ts.test.js
Expand Up @@ -160,6 +160,24 @@ describe('test/ts.test.js', () => {
.expect('stdout', /Object\{key:"111"}/)
.end();
});

it('should correct error stack line number in mixed app', () => {
if (process.platform === 'win32') return;

const appDir = path.join(__dirname, './fixtures/example-ts-error-stack-mixed');
const testFile = path.resolve(appDir, 'test/index.test.js');
return coffee.fork(eggBin, [ 'test', testFile ], { cwd: appDir })
// .debug()
.expect('stdout', /error/)
.expect('stdout', /test[\/\\]{1}index\.test\.js:8:11\)/)
.expect('stdout', /test[\/\\]{1}index\.test\.js:14:5\)/)
.expect('stdout', /assert\(obj\.key === '222'\)/)
.expect('stdout', /| {3}| {3}|/)
.expect('stdout', /| {3}| {3}false/)
.expect('stdout', /| {3}"111"/)
.expect('stdout', /Object\{key:"111"}/)
.end();
});
});

describe('egg.typescript = true', () => {
Expand Down

0 comments on commit faaf4f0

Please sign in to comment.