Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

filename of undefined error when used with mocha #12

Closed
austinmao opened this issue Feb 2, 2016 · 9 comments
Closed

filename of undefined error when used with mocha #12

austinmao opened this issue Feb 2, 2016 · 9 comments

Comments

@austinmao
Copy link

I am getting TypeError: Cannot read property 'filename' of undefined from node-source-map-support when running mocha. By manually going into that package and doing a console.trace(), I get this stack trace below:

> PORT=9999 NODE_ENV=testing mocha --compilers js:babel-register ./test/bootstrap.test.js ./test/unit/*.test.js ./test/unit/**/*.test.js --timeout 20000
warn: Sails' built-in layout support only works with the `ejs`, `handlebars`, `ractive` view engines.
warn: You're using `jade`.
warn: Ignoring `sails.config.views.layout`...
Trace
    at Object.exports.install (/Users/austinmao/Sites/aditive-backend/node_modules/source-map-support/source-map-support.js:426:11)
    at Hook.configure (/Users/austinmao/Sites/aditive-backend/node_modules/sails-hook-babel/index.js:43:28)
    at Hook.bound [as configure] (/Users/austinmao/Sites/aditive-backend/node_modules/sails/node_modules/lodash/dist/lodash.js:729:21)
    at /Users/austinmao/Sites/aditive-backend/node_modules/sails/lib/app/private/loadHooks.js:176:18
    at /Users/austinmao/Sites/aditive-backend/node_modules/sails/node_modules/async/lib/async.js:122:13
    at _each (/Users/austinmao/Sites/aditive-backend/node_modules/sails/node_modules/async/lib/async.js:46:13)
    at Object.async.each (/Users/austinmao/Sites/aditive-backend/node_modules/sails/node_modules/async/lib/async.js:121:9)
    at Object.async.series.configure (/Users/austinmao/Sites/aditive-backend/node_modules/sails/lib/app/private/loadHooks.js:174:17)
    at /Users/austinmao/Sites/aditive-backend/node_modules/sails/node_modules/async/lib/async.js:620:25
    at iterate (/Users/austinmao/Sites/aditive-backend/node_modules/sails/node_modules/async/lib/async.js:146:13)
    at /Users/austinmao/Sites/aditive-backend/node_modules/sails/node_modules/async/lib/async.js:157:25
    at /Users/austinmao/Sites/aditive-backend/node_modules/sails/node_modules/async/lib/async.js:626:21
    at done (/Users/austinmao/Sites/aditive-backend/node_modules/sails/node_modules/async/lib/async.js:132:19)
    at /Users/austinmao/Sites/aditive-backend/node_modules/sails/node_modules/async/lib/async.js:32:16
    at doNTCallback0 (node.js:407:9)
    at process._tickCallback (node.js:336:13)
/Users/austinmao/Sites/aditive-backend/node_modules/mocha-clean/index.js:45
  if (!e.stack) return e;
        ^

TypeError: Cannot read property 'filename' of undefined
npm ERR! Test failed.  See above for more details.

The weird thing is that this doesn't happen in Codeship. The problem goes away when I downgrade to package v6.0.0 (without node-source-map-support).

I'm not so familiar with these two packages, so would you know how to fix this so I can actually get source map support back?

@austinmao
Copy link
Author

Any update on this?

@dangreen
Copy link
Contributor

@austinmao can you provide example of your test?

@dangreen
Copy link
Contributor

@austinmao and see my comment here

@austinmao
Copy link
Author

packages.json:

  "scripts": {
    "start": "nodemon app.js",
    "debug": "nodemon debug app.js",
    "test": "better-npm-run test --watch",
    "ci": "better-npm-run test",
    "functional": "better-npm-run functional"
  },
  "betterScripts": {
    "test": {
      "command": "mocha ./test/bootstrap.test.js ./test/unit/*.test.js ./test/unit/**/*.test.js",
      "env": {
        "NODE_ENV": "testing",
        "PORT": 9999
      }
    },
    "functional": {
      "command": "nodemon app.js",
      "env": {
        "NODE_ENV": "functional",
        "PORT": 1337
      }
    }
  },

babel.rc:

{
  "ignore": [
    "node_modules",
    "bower_components"
  ],
  "presets": [
    "es2015"
  ],
  "plugins": [
    "babel-plugin-syntax-object-rest-spread",
    "transform-object-rest-spread",
    "syntax-async-functions",
    "transform-regenerator"
  ]
}

config/babel.js:

module.exports.babel = {
  // compile: true,
  polyfill: true,
  presets: [
    'es2015'
  ],
  plugins: [
    'babel-plugin-syntax-object-rest-spread',
    'transform-object-rest-spread',
    'syntax-async-functions',
    'transform-regenerator',
    // 'transform-runtime'
  ]
}

bootstrap.test.js:

/**
* bootstrap.test.js
*
* @description :: global before and after hooks for unit tests to raise/lower sails server
* @docs        :: http://sailsjs-documentation.readthedocs.org/en/latest/concepts/Testing/
*/

var _            = require('lodash')
var SailsApp     = require('sails').Sails
var clear        = require('cli-clear')
var Promise      = require('bluebird')
var _s           = require('underscore.string')
var changeCase   = require('change-case')
var is           = require('is_js')
var mongoose     = require('mongoose')

/** loads the sails server and fixtures */
before(function (done) {

  clear() // clear terminal

  // Lift Sails with test database
  var sails = new SailsApp()
  sails.lift({}, function(err, server) {

    if (err) {
      console.error('failed to lift sails')
      return done(err)
    };

    sails.localAppURL = ( sails.usingSSL ? 'https' : 'http' ) + '://' + sails.config.host + ':' + sails.config.port + '';

    // // NOTE: fixtures are now loaded in bootstrap.js
    // loadFixtures()

    // add to global vars for use in testing
    global.app = sails.express ? sails.express.app : sails.hooks.http.app;
    clear() // clear terminal again
    done(null, sails)
  });
});


/** stops the sails server */
after(function (done) {

  sails.log.verbose('lowering sails')

  // don't lower sails if doing functional tests
  if (process.env.NODE_ENV !== 'functional') {
    sails.lower(function(err) {
      if (err) throw new Error(err)
      sails.log.verbose('successfully lowered sails')
      done()
    });
  }
});

mocha.opts:

--compilers js:babel-register 
--require should
--require should-sinon
--require mocha-clean
--reporter spec
--recursive
--timeout 20000

@dangreen
Copy link
Contributor

@austinmao try to install package from git (npm install https://github.com/sane/sails-hook-babel.git) and test it

@sd031
Copy link

sd031 commented Nov 6, 2016

I am getting this issue too ,
issue:
/node_modules/source-map-support/source-map-support.js:415
var hasStack = (arguments[1] && arguments[1].stack);
^

TypeError: Cannot read property 'filename' of undefined

I am using:
sails 0.12.3
node.js v6.9.1

@dangreen
Copy link
Contributor

dangreen commented Nov 6, 2016

@sd031 Have you tried it?

try to install package from git (npm install https://github.com/sane/sails-hook-babel.git) and test it

@rkbrewer
Copy link

rkbrewer commented Nov 8, 2016

Thanks @dangreen. I was getting the same issue @sd031 was getting, but installing sails-hook-babel from git fixed it.

My buggy setup that got fixed was:
sails 12.4
node: 6.5
sails-hook-babel: 6.0.1

dangreen added a commit that referenced this issue Nov 9, 2016
dangreen added a commit that referenced this issue Nov 9, 2016
@dangreen
Copy link
Contributor

dangreen commented Nov 9, 2016

npm package was updated

@dangreen dangreen closed this as completed Nov 9, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants