Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: conflix source map support #181

Merged
merged 1 commit into from Jul 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 5 additions & 8 deletions lib/cmd/test.js
Expand Up @@ -111,15 +111,12 @@ 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) {
// 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