Skip to content

Commit

Permalink
fix: conflict source map support (#182)
Browse files Browse the repository at this point in the history
Co-authored-by: wanghx <[email protected]>
  • Loading branch information
whxaxes and wanghx authored Jul 11, 2022
1 parent a1fb829 commit a12dc1a
Show file tree
Hide file tree
Showing 11 changed files with 86 additions and 13 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ name: Node.js CI
on:
push:
branches:
- master
- 4.x
pull_request:
branches:
- master
- 4.x
schedule:
- cron: '0 2 * * *'

Expand All @@ -20,7 +20,7 @@ jobs:
strategy:
fail-fast: false
matrix:
node-version: [8, 10, 12, 14, 16]
node-version: [14, 16]
os: [ubuntu-latest, windows-latest, macos-latest]

steps:
Expand Down
13 changes: 5 additions & 8 deletions lib/cmd/test.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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');
}
}
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
},
}
Binary file added test/fixtures/test-files-c8/.DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions test/fixtures/test-files-c8/test/a.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const a = require('../lib/a');
describe('a.test.js', () => {
it('should success', () => {
a(true);
a(false);
});

it('should show tmp', () => {
Expand Down
18 changes: 18 additions & 0 deletions test/ts.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,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 a12dc1a

Please sign in to comment.