Skip to content

Instantly share code, notes, and snippets.

@isaacs
Created December 31, 2019 17:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isaacs/3cc8394c351ead9d208748037b338764 to your computer and use it in GitHub Desktop.
Save isaacs/3cc8394c351ead9d208748037b338764 to your computer and use it in GitHub Desktop.
const t = require('tap')
t.test('throw immediately', t => {
throw new Error('thrown immediately')
})
t.test('throw in nextTick', t => {
process.nextTick(() => {
throw new Error('thrown in next tick')
})
})
t.test('throw in timeout', t => {
setTimeout(() => {
throw new Error('thrown in timeout')
})
})
@isaacs
Copy link
Author

isaacs commented Dec 31, 2019

node 13.4:

TAP version 13
# Subtest: throw immediately
    not ok 1 - thrown immediately
      ---
      at:
        line: 4
        column: 9
        file: throw.js
        function: Test.<anonymous>
      tapCaught: testFunctionThrow
      test: throw immediately
      source: |
        t.test('throw immediately', t => {
          throw new Error('thrown immediately')
        --------^
        })
      ...
    
    1..1
    # failed 1 test
not ok 1 - throw immediately # time=14.226ms

# Subtest: throw in nextTick
    not ok 1 - thrown in next tick
      ---
      at:
        line: 9
        column: 11
        file: throw.js
      tapCaught: uncaughtException
      test: throw in nextTick
      source: |2
          process.nextTick(() => {
            throw new Error('thrown in next tick')
        ----------^
          })
        })
      ...
    
    1..1
    # failed 1 test
not ok 2 - throw in nextTick # time=4.956ms

# Subtest: throw in timeout
    not ok 1 - thrown in timeout
      ---
      at:
        line: 15
        column: 11
        file: throw.js
        function: Timeout._onTimeout
      tapCaught: uncaughtException
      test: throw in timeout
      source: |2
          setTimeout(() => {
            throw new Error('thrown in timeout')
        ----------^
          })
        })
      ...
    
    1..1
    # failed 1 test
not ok 3 - throw in timeout # time=3.445ms

1..3
# failed 3 of 3 tests
# time=32.806ms

node 13.5:

TAP version 13
# Subtest: throw immediately
    not ok 1 - thrown immediately
      ---
      at:
        line: 4
        column: 9
        file: throw.js
        function: Test.<anonymous>
      tapCaught: testFunctionThrow
      test: throw immediately
      source: |
        t.test('throw immediately', t => {
          throw new Error('thrown immediately')
        --------^
        })
      ...
    
    1..1
    # failed 1 test
not ok 1 - throw immediately # time=14.32ms

Error: async hook stack has become corrupted (actual: 17, expected: 1)
 1: 0x10000b8d9 node::AsyncHooks::pop_async_id(double) [/Users/isaacs/.config/nave/installed/13.5.0/bin/node]
 2: 0x10000189a node::InternalCallbackScope::Close() [/Users/isaacs/.config/nave/installed/13.5.0/bin/node]
 3: 0x10000149a node::InternalCallbackScope::~InternalCallbackScope() [/Users/isaacs/.config/nave/installed/13.5.0/bin/node]
 4: 0x1000b3f45 node::NodeMainInstance::Run() [/Users/isaacs/.config/nave/installed/13.5.0/bin/node]
 5: 0x10005e46f node::Start(int, char**) [/Users/isaacs/.config/nave/installed/13.5.0/bin/node]
 6: 0x7fff657932e5 start [/usr/lib/system/libdyld.dylib]
 7: 0x2 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment