{"action":"created","issue":{"url":"https://api.github.com/repos/wallabyjs/public/issues/848","repository_url":"https://api.github.com/repos/wallabyjs/public","labels_url":"https://api.github.com/repos/wallabyjs/public/issues/848/labels{/name}","comments_url":"https://api.github.com/repos/wallabyjs/public/issues/848/comments","events_url":"https://api.github.com/repos/wallabyjs/public/issues/848/events","html_url":"https://github.com/wallabyjs/public/issues/848","id":185818465,"number":848,"title":"Test passing in mocha but not wallaby.","user":{"login":"joshfttb","id":2595454,"avatar_url":"https://avatars.githubusercontent.com/u/2595454?v=3","gravatar_id":"","url":"https://api.github.com/users/joshfttb","html_url":"https://github.com/joshfttb","followers_url":"https://api.github.com/users/joshfttb/followers","following_url":"https://api.github.com/users/joshfttb/following{/other_user}","gists_url":"https://api.github.com/users/joshfttb/gists{/gist_id}","starred_url":"https://api.github.com/users/joshfttb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/joshfttb/subscriptions","organizations_url":"https://api.github.com/users/joshfttb/orgs","repos_url":"https://api.github.com/users/joshfttb/repos","events_url":"https://api.github.com/users/joshfttb/events{/privacy}","received_events_url":"https://api.github.com/users/joshfttb/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":6,"created_at":"2016-10-28T01:25:13Z","updated_at":"2016-10-30T00:32:06Z","closed_at":null,"body":"### Issue description or question\r\nI have a test that is passing in mocha but not in wallaby. I've tried using setting workers to 1 and recycle with no resilt\r\n\r\n### Wallaby.js configuration file\r\n\r\n```javascript\r\nmodule.exports = (wallaby) => {\r\n  const path = require('path')\r\n  process.env.NODE_PATH += path.delimiter + path.join(wallaby.localProjectDir, 'server', 'node_modules')\r\n  process.env.DESIREMAP_SETTINGS = './settings.json'\r\n  return {\r\n    files: [\r\n      'server/src/**/*.js',\r\n      '!server/src/**/*.test.js',\r\n      'server/src/settings.json',\r\n    ],\r\n    tests: [\r\n      'server/src/**/*.test.js',\r\n    ],\r\n    testFramework: 'mocha',\r\n    debug: true,\r\n    compilers: {\r\n      '**/*.js': wallaby.compilers.babel(), // eslint-disable-line no-undef\r\n    },\r\n    env: {\r\n      type: 'node',\r\n    },\r\n    workers: {\r\n      initial: 1,\r\n      regular: 1,\r\n      recycle: true,\r\n    },\r\n  }\r\n}\r\n```\r\n\r\n### Test file: (failing test is marked with .skip)\r\n```javascript\r\n// setup all the things\r\nimport 'babel-polyfill'\r\nimport expect from 'expect'\r\nimport td from 'testdouble'\r\nimport { UserModel } from './model.js'\r\nimport moment from 'moment'\r\nimport mongoose from 'mongoose'\r\nimport speakeasy from 'speakeasy'\r\n\r\n// setup proper promises for mongoose\r\nmongoose.Promise = global.Promise\r\n\r\n// get the files under test\r\nimport {\r\n  generateToken,\r\n  removeUnregisteredUsers,\r\n} from './resolvers.js'\r\n\r\n// create some base models\r\nconst baseUser = {\r\n  phone: '+14103021928',\r\n  roles: [ 'user' ],\r\n  createdAt: moment().subtract(15, 'days').toDate(),\r\n  lastLoggedIn: moment().subtract(3, 'hours').toDate(),\r\n}\r\n\r\n// mock the PITA twilio object\r\nconst twilioMock = {\r\n  LookupsClient () {\r\n    this.phoneNumbers = function (phone) {\r\n      return {\r\n        get () {\r\n          return new Promise((resolve, reject) => {\r\n            if (phone.length === 10) {\r\n              resolve({\r\n                phoneNumber: `+1${phone}`,\r\n              })\r\n            } else {\r\n              reject({\r\n                status: 404,\r\n              })\r\n            }\r\n          })\r\n        },\r\n      }\r\n    }\r\n  },\r\n}\r\n\r\nconst sendMessage = td.function()\r\nconst twilioMessageMock = function () {\r\n  return {\r\n    sendMessage,\r\n  }\r\n}\r\n\r\n// for some reason I have to write this as a function expression\r\n// I'm assuming it's a problem with hoisting above babel-polyfill\r\nconst errorCatcher = async function (func, ...args) {\r\n  try {\r\n    if (args) {\r\n      await func(...args)\r\n    } else {\r\n      await func()\r\n    }\r\n  } catch (e) {\r\n    return e\r\n  }\r\n}\r\n\r\ndescribe('account tests', () => {\r\n  before((done) => {\r\n    // this is hard to debug if we forget\r\n    // create a test database\r\n    td.reset()\r\n    mongoose.connection.close()\r\n    mongoose.connect('mongodb://localhost/desiremap-test')\r\n    const db = mongoose.connection\r\n    db.once('open', async () => {\r\n      // cleanup once before start\r\n      await UserModel.remove({})\r\n      done()\r\n    })\r\n  })\r\n  after((done) => {\r\n    mongoose.connection.close()\r\n    done()\r\n  })\r\n  afterEach(async () => {\r\n    // cleanup testdoubles and the test db after each\r\n    td.reset()\r\n    await UserModel.remove({})\r\n  })\r\n  describe('validate phone', () => {\r\n  })\r\n  describe('non-logged in tests', () => {\r\n    describe('user model tests', () => {\r\n      it('should save a valid model', async () => {\r\n        const testUser = new UserModel(baseUser)\r\n        await testUser.save()\r\n        const result = await UserModel.findById(testUser.id)\r\n        expect(result).toExist()\r\n      })\r\n      it('should not allow duplicate ids', async () => {\r\n        const testUser = new UserModel(baseUser)\r\n        await testUser.save()\r\n        const anotherUser = new UserModel({\r\n          ...baseUser,\r\n          _id: testUser.id,\r\n        })\r\n        const error = await errorCatcher(anotherUser.save)\r\n        expect(await error.message).toInclude('duplicate key error')\r\n      })\r\n      it('should require a phone number', async () => {\r\n        const testUser = new UserModel({\r\n          ...baseUser,\r\n          phone: null,\r\n        })\r\n        const error = await errorCatcher(testUser.save)\r\n        expect(error.message).toEqual('User validation failed')\r\n      })\r\n      it('should not allow duplicate phone numbers', async () => {\r\n        const testUser = new UserModel(baseUser)\r\n        await testUser.save()\r\n        const anotherUser = new UserModel(baseUser)\r\n        const error = await errorCatcher(anotherUser.save)\r\n        expect(error.message).toInclude('duplicate key error')\r\n      })\r\n      it('should require roles', async () => {\r\n        // I'll just include both of these tests here\r\n        const testUser = new UserModel({\r\n          ...baseUser,\r\n          roles: null,\r\n        })\r\n        const error = await errorCatcher(testUser.save)\r\n        expect(error.message).toEqual('User validation failed')\r\n        const anotherUser = new UserModel({\r\n          ...baseUser,\r\n          roles: [],\r\n        })\r\n        const anotherError = await errorCatcher(anotherUser.save)\r\n        expect(anotherError.message).toEqual('User validation failed')\r\n      })\r\n      it('should not allow invalid roles', async () => {\r\n        const testUser = new UserModel({\r\n          ...baseUser,\r\n          roles: [ 'invalid role' ],\r\n        })\r\n        const error = await errorCatcher(testUser.save)\r\n        expect(error.message).toEqual('User validation failed')\r\n        expect(true).to\r\n      })\r\n    })\r\n    describe('generate token', () => {\r\n      it('should error on missing args', () => {\r\n        expect(() => {\r\n          generateToken()\r\n        }).toThrow()\r\n      })\r\n      it('should error on invalid args', () => {\r\n        expect(() => {\r\n          generateToken(true, false)\r\n        }).toThrow('invalid arguments')\r\n        expect(() => {\r\n          generateToken('string', {})\r\n        }).toThrow('invalid arguments')\r\n      })\r\n      it('should generate a token on valid args', () => {\r\n        // this way I can pass an actual id\r\n        const testUser = new UserModel(baseUser)\r\n        const token = generateToken(testUser.id, true)\r\n        expect(token).toBeA('string')\r\n      })\r\n    })\r\n    describe('validateNumber', () => {\r\n      let validateNumber\r\n      beforeEach(() => {\r\n        // mock twilio\r\n        td.replace('twilio', twilioMock)\r\n        validateNumber = require('./resolvers.js').validateNumber\r\n      })\r\n      it('should error on missing args', async () => {\r\n        const error = await errorCatcher(validateNumber)\r\n        expect(error).toEqual('Error: invalid arguments')\r\n      })\r\n      it('should error on invalid args', async () => {\r\n        const error = await errorCatcher(validateNumber, true)\r\n        expect(error).toEqual('Error: invalid arguments')\r\n      })\r\n      it('should throw the correct error on invalid number', async () => {\r\n        const error = await errorCatcher(validateNumber, '9')\r\n        expect(error).toEqual('Error: invalid phone number')\r\n      })\r\n      it('should return a formatted number on a valid number', async () => {\r\n        const result = await validateNumber('4103025555')\r\n        expect(result).toEqual('+14103025555')\r\n      })\r\n    })\r\n    describe('sendCode', () => {\r\n      let sendCode\r\n      beforeEach(() => {\r\n        // mock twilio\r\n        td.replace('twilio', twilioMessageMock)\r\n        sendCode = require('./resolvers.js').sendCode\r\n      })\r\n      it('should error on null args', async () => {\r\n        const error = await errorCatcher(sendCode)\r\n        expect(error).toEqual('Error: invalid arguments')\r\n      })\r\n      it('should error on incorrect args', async () => {\r\n        const badUserObject = {\r\n          key: 'value',\r\n        }\r\n        const error1 = await errorCatcher(sendCode, 'wrong')\r\n        const error2 = await errorCatcher(sendCode, badUserObject)\r\n        expect(error1).toEqual('Error: invalid arguments')\r\n        expect(error2).toEqual('Error: invalid arguments')\r\n      })\r\n      it.skip('should send a code when given a correct user object', async () => {\r\n        const secret = speakeasy.generateSecret()\r\n        const testUser = new UserModel({\r\n          ...baseUser,\r\n          reserved: {\r\n            totpSecret: secret,\r\n          },\r\n        })\r\n        await testUser.save()\r\n        await sendCode(testUser)\r\n        td.verify(sendMessage(), {ignoreExtraArgs: true})\r\n      })\r\n    })\r\n    describe('remove unregistered users', () => {\r\n      it('should remove unregistered users', async () => {\r\n        const oldDate = moment().subtract(60, 'days').toDate()\r\n        const modifiedUser = {\r\n          ...baseUser,\r\n          createdAt: oldDate,\r\n        }\r\n        delete modifiedUser.lastLoggedIn\r\n        const testUser = new UserModel(modifiedUser)\r\n        await testUser.save()\r\n        // ensure it saved correctly\r\n        await UserModel.findOne({ _id: testUser.id })\r\n        await removeUnregisteredUsers()\r\n        const afterResult = await UserModel.findOne({ _id: testUser.id })\r\n        expect(afterResult).toNotExist()\r\n      })\r\n      it('should not remove regisrered users', async () => {\r\n        const oldDate = moment().subtract(60, 'days').toDate()\r\n        const testUser = new UserModel({\r\n          ...baseUser,\r\n          createdAt: oldDate,\r\n        })\r\n        await testUser.save()\r\n        // ensure it saved correctly\r\n        await UserModel.findOne({ _id: testUser.id })\r\n        await removeUnregisteredUsers()\r\n        const afterResult = await UserModel.findOne({ _id: testUser.id })\r\n        expect(afterResult).toExist()\r\n      })\r\n    })\r\n  })\r\n})\r\n```\r\n\r\n### Code editor or IDE name and version\r\nVisual Studio Code v1.6.1\r\n\r\n### OS name and version\r\nOSX 10.2\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/wallabyjs/public/issues/comments/257124254","html_url":"https://github.com/wallabyjs/public/issues/848#issuecomment-257124254","issue_url":"https://api.github.com/repos/wallabyjs/public/issues/848","id":257124254,"user":{"login":"joshfttb","id":2595454,"avatar_url":"https://avatars.githubusercontent.com/u/2595454?v=3","gravatar_id":"","url":"https://api.github.com/users/joshfttb","html_url":"https://github.com/joshfttb","followers_url":"https://api.github.com/users/joshfttb/followers","following_url":"https://api.github.com/users/joshfttb/following{/other_user}","gists_url":"https://api.github.com/users/joshfttb/gists{/gist_id}","starred_url":"https://api.github.com/users/joshfttb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/joshfttb/subscriptions","organizations_url":"https://api.github.com/users/joshfttb/orgs","repos_url":"https://api.github.com/users/joshfttb/repos","events_url":"https://api.github.com/users/joshfttb/events{/privacy}","received_events_url":"https://api.github.com/users/joshfttb/received_events","type":"User","site_admin":false},"created_at":"2016-10-30T00:32:06Z","updated_at":"2016-10-30T00:32:06Z","body":"Well crap. I think I just figured it out. There's a debug:true setting in wallaby js that was tripping an if/then block in the code.\r\n\r\nI am getting a bunch of timeout errors I'm not getting in mocha though"}}
{"actor":{"display_login":"joshfttb"}}