Skip to content

Strange bug in circleci/travie-ci docker env: node tap.js pass but tap tap.js will fail. #272

@huan

Description

@huan

I'm using nodejs v6.

Recently, my project unit test code(which is using TAP) are always fail in circleci & travis. What very strange is, at the same time, they can pass in appveyor and my dev box.

after digged it for serval hours, I find the reason is the follow code:

function func({
  a = 'default'
  , b
} = {}) {
  return a
}

const a = func({ b: 1 })
console.log('a should be "default". actual a = "' + a + '"')

in the above code, a in func has a default value default. after we call the func without a, we should get func return value "default".

when we use node v6 to run this code, there's no problem.
when I use tap to run this code, this no problem, too.

But when this code is ran inside CircleCI & Travis-CI , the func will return undefined instead of default.

this cause my unit test fail.

a example CI failure can be found here: https://circleci.com/gh/zixia/wechaty/224 . Notice the following line:

ERR! PuppetWeb init exception: Watchdog onFeed: unsupport type undefined

the undefined should have a default value.

I can reproduce this bug inside the CirclerCI "Debug via SSH" feature, use the following script:

mkdir a
cd a

npm init --yes

mkdir b
cd b

cat > bug.js <<__CODE__
const test  = require('tap').test
const func = require('../w.js')

test('func param test', function(t) {
        const type = func({ data: 'direct call' })

        t.equal(type, 'default', 'should be default')
        t.end()
})
__CODE__

cat > ../w.js <<__CODE__
module.exports = function func(options) {
        const { type = 'default', data } = options || {}
        console.log('type=' + type + ', data=' + data)
        return type
}
__CODE__


npm install tap --save-dev

node bug.js
tap bug.js

the most interesting part is: this bug only appear when we require a module from other directory. which means:

  1. if we require('./w'), then this bug will disappear
  2. this bug will appear with require('../w'), that's the reason I mkdir two times.

The output is like the following(copy/paste from my console)

  1. use node bug.js can get the default value
ubuntu@box571:~/a/b$ node bug.js
TAP version 13
    # Subtest: func param test
type=default, data=direct call
    ok 1 - should be default
    1..1
ok 1 - func param test # time=11.414ms

1..1
# time=38.53ms
  1. at the same time, the same tap.js, run by tap, will fail.
ubuntu@box571:~/a/b$ tap bug.js

bug.js type=undefined, data=direct call
bug.js ................................................ 0/1 932ms
  func param test
  not ok should be default
    +++ found                                                          
    --- wanted                                                         
    -"default"                                                         
    +[null]                                                            
    compare: ===

P.S. The project that I use tap is https://github.com/zixia/wechaty
P.S. 2 I use 3 CI at the same time: circleci / travis / appveyor

I cross posted at stackoverflow & ci form:
https://stackoverflow.com/questions/38239735/strange-bug-in-circleci-travie-ci-docker-env-node-tap-js-pass-but-tap-tap-js
https://discuss.circleci.com/t/strange-bug-in-circleci-docker-env-node-tap-js-pass-but-tap-tap-js-will-fail/5005

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