Skip to content

Commit

Permalink
fix(jest): Forced jest 20 (later interfere with unhandled exception w…
Browse files Browse the repository at this point in the history
…arnings)

Also improved code coverage
  • Loading branch information
grantila committed Jul 29, 2019
1 parent 8f8f97c commit bfde536
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 2 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@
"haxec": "^1.1.0"
},
"devDependencies": {
"@types/jest": "^20",
"@types/jest": "20.0.8",
"@types/node": "^12",
"already": "^1.8.0",
"commitizen": "^3",
"concurrently": "^4.1.1",
"coveralls": "^3",
"cz-conventional-changelog": "^2",
"jest": "^20",
"jest": "20.0.4",
"rimraf": "^2.6.3",
"rollup": "^1.16.3",
"semantic-release": "^15.13.18",
Expand Down
85 changes: 85 additions & 0 deletions test/register.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,89 @@ describe( "register", ( ) =>
expect( linesWoLocation.length ).toBeGreaterThanOrEqual( 2 );
expect( linesWoLocation[ 0 ] ).toBe( linesWoLocation[ 1 ] );
} ) );

it( "Handle throwing in <new Promise>", withConsoleSpy( async ( ) =>
{
const err = new Error( "the error" );

new Promise( ( resolve, reject ) =>
{
throw err;
} );

await triggerUnhandledWarnings( );

const linesWoColumns = splitLines( console.error.mock.calls[ 0 ] )
.filter( line => line.includes( "register.spec.js" ) )
.map( line => cutColumn( line ) );

const linesWoLocation = splitLines( console.error.mock.calls[ 0 ] )
.filter( line => line.includes( "register.spec.js" ) )
.map( line => cutLocation( line ) );

expect( linesWoColumns.length ).toBeGreaterThanOrEqual( 2 );
expect( linesWoColumns[ 0 ] ).not.toBe( linesWoColumns[ 1 ] );

expect( linesWoLocation.length ).toBeGreaterThanOrEqual( 2 );
expect( linesWoLocation[ 0 ] ).toBe( linesWoLocation[ 1 ] );
} ) );

it( "Handle error without stack", withConsoleSpy( async ( ) =>
{
const err = new Error( "the error" );
delete err.stack;

new Promise( ( resolve, reject ) =>
{
throw err;
} );

await triggerUnhandledWarnings( );

const linesWoColumns = splitLines( console.error.mock.calls[ 0 ] )
.filter( line => line.includes( "register.spec.js" ) )
.map( line => cutColumn( line ) );

const errorAndShared = splitLines( console.error.mock.calls[ 0 ] )
.filter( line => line );

expect( linesWoColumns.length ).toBeGreaterThanOrEqual( 2 );
expect( linesWoColumns[ 0 ] ).not.toBe( linesWoColumns[ 1 ] );

expect( errorAndShared[ errorAndShared.length - 2 ] ).toBe(
" ==== Error at: ===================="
);
expect( errorAndShared[ errorAndShared.length - 1 ] ).toBe(
" ==== Shared trace: ================"
);
} ) );

it( "Handle null error", withConsoleSpy( async ( ) =>
{
const err = null;

new Promise( ( resolve, reject ) =>
{
throw err;
} );

await triggerUnhandledWarnings( );

const linesWoColumns = splitLines( console.error.mock.calls[ 0 ] )
.filter( line => line.includes( "register.spec.js" ) )
.map( line => cutColumn( line ) );

const errorAndShared = splitLines( console.error.mock.calls[ 0 ] )
.filter( line => line );

expect( linesWoColumns.length ).toBeGreaterThanOrEqual( 2 );
expect( linesWoColumns[ 0 ] ).not.toBe( linesWoColumns[ 1 ] );

expect( errorAndShared[ errorAndShared.length - 2 ] ).toBe(
" ==== Error at: ===================="
);
expect( errorAndShared[ errorAndShared.length - 1 ] ).toBe(
" ==== Shared trace: ================"
);
} ) );
} );

0 comments on commit bfde536

Please sign in to comment.