Skip to content

Throw exception when using equal & same for some variable #791

@huan

Description

@huan

Versions

tap@15.0.10
wechaty@1.9.8
wechaty-puppet-mock@1.9.1

equal() Cannot read property 'length' of null

# Subtest: Wechaty <> Tap `Error: undefined is not a function`
    not ok 1 - Cannot read property 'length' of null
      ---
      stack: |
        Format.arrayIsEmpty (node_modules/tcompare/lib/format.js:390:31)
        Format.array (node_modules/tcompare/lib/format.js:384:14)
        Format.collection (node_modules/tcompare/lib/format.js:211:58)
        Format.printValue (node_modules/tcompare/lib/format.js:140:21)
        Format.print (node_modules/tcompare/lib/format.js:78:51)
        Same.simplePrint (node_modules/tcompare/lib/same.js:134:8)
        Same.diff (node_modules/tcompare/lib/same.js:434:35)
        Same.print (node_modules/tcompare/lib/same.js:146:37)
        simple (node_modules/tcompare/index.js:9:11)
        node_modules/tcompare/index.js:13:3
      at:
        line: 390
        column: 31
        file: node_modules/tcompare/lib/format.js
        function: Format.arrayIsEmpty
      type: TypeError
      tapCaught: returnedPromiseRejection
      test: "Wechaty <> Tap `Error: undefined is not a function`"
      source: |2
          arrayIsEmpty () {
            return this.objectAsArray.length === 0
        ------------------------------^
          }
          arrayEmpty () {
      ...
    
    1..1
    # failed 1 test

same() Error: undefined is not a function

$ ./src/t.ts 
TAP version 13
# Subtest: Wechaty <> Tap
    not ok 1 - undefined is not a function
      ---
      stack: >
        Object.createSeq [as createNode]
        (node_modules/yaml/dist/Schema-88e323a7.js:35:16)
      
        createNode (node_modules/yaml/dist/Schema-88e323a7.js:444:41)
      
        Schema.createNode (node_modules/yaml/dist/Schema-88e323a7.js:507:12)
      
        Schema.createPair (node_modules/yaml/dist/Schema-88e323a7.js:515:20)
      
        Object.createMap [as createNode] (node_modules/yaml/dist/Schema-88e323a7.js:13:63)
      
        createNode (node_modules/yaml/dist/Schema-88e323a7.js:444:41)
      
        Schema.createNode (node_modules/yaml/dist/Schema-88e323a7.js:507:12)
      
        Schema.createPair (node_modules/yaml/dist/Schema-88e323a7.js:515:20)
      
        Object.createMap [as createNode] (node_modules/yaml/dist/Schema-88e323a7.js:13:63)
      
        createNode (node_modules/yaml/dist/Schema-88e323a7.js:444:41)
      at:
        line: 35
        column: 16
        file: node_modules/yaml/dist/Schema-88e323a7.js
        function: Object.createSeq
        method: createNode
      type: TypeError
      tapCaught: returnedPromiseRejection
      test: Wechaty <> Tap
      source: |2
          if (obj && obj[Symbol.iterator]) {
            for (const it of obj) {
        ---------------^
              const v = schema.createNode(it, ctx.wrapScalars, null, ctx);
              seq.items.push(v);
      ...
    
    1..2
    # test count(1) != plan(2)
    # failed 1 test
not ok 1 - Wechaty <> Tap # time=42.396ms

1..1
# failed 1 test
# time=54.162ms

Reproduciable minimum code

NPM Versions:

npm install tap@15.0.10 wechaty@1.9.8 wechaty-puppet-mock@1.9.1

Code:

#!/usr/bin/env -S node --no-warnings --loader ts-node/esm

import { test } from 'tap'  // tap@15.0.10

import { WechatyBuilder } from 'wechaty'  // wechaty@1.9.8
import { PuppetMock }     from 'wechaty-puppet-mock'  // wechaty-puppet-mock@1.9.1

test('Wechaty <> Tap reproduce bug', async t => {
  const puppet = new PuppetMock()
  const wechaty = WechatyBuilder.build({ puppet })

  t.same(wechaty, undefined, 'should have wechaty registered after use plugin')
  /**
   * Error: Cannot read property 'length' of null
   *
   * stack: |
   *    Format.arrayIsEmpty (node_modules/tcompare/lib/format.js:390:31)
   */

  t.equal(wechaty, undefined, 'should have wechaty registered after use plugin')
  /**
   * Error: undefined is not a function
   *
   * stack: >
   *    Object.createSeq [as createNode]
   *    (node_modules/yaml/dist/Schema-88e323a7.js:35:16)
   */
}).catch(console.error)

Cross-posted from:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions