Discussion:
[Cucumber] [CUCUMBER] [JS] Failing to instantiate WorldConstructor in trivial project
(too old to reply)
Derrell Durrett
2015-05-14 21:43:31 UTC
Permalink
I'm having trouble using cucumber.js.

With a *very* simple .feature file:

Feature: Open and parse JSON-formatted stitch data file
As a user
I want to use JSON-formatted stitch data files
So that I can more easily communicate with the server

Background:
Given I have an existing design

Scenario: I want to display the design in the file
Given I open the design in a canvas element

I hit a TypeError in the following fashion:


C:\Users\ddurrett\AppData\Roaming\npm\node_modules\cucumber\lib\cucumber\
support_code\library.js:109
var world = new WorldConstructor(function (explicitWorld) {
^
TypeError: undefined is not a function
at Object.instantiateNewWorld (C:\Users\ddurrett\AppData\Roaming\npm\
node_modules\cucumber\lib\cucumber\support_code\library.js:109:19)
at Object.visitScenario (C:\Users\ddurrett\AppData\Roaming\npm\node_modules
\cucumber\lib\cucumber\runtime\ast_tree_walker.js:55:26)
[....truncated stack trace...]

If I run to this point in the node debugger (starting it on the command
line), I see that only the following files are loaded:
debug> scripts
82: feature.js
119: ast_tree_walker.js
* 132: library.js
140: collection.js

So, I'm not yet loading my code (or am I wrong about that?). Which is odd,
because a nearly identical (and similarly small) project was running fine
yesterday. All of which suggests to me that the problems I'm having are due
to some configuration failure on my part, and not some problem with
cucumber.js.

Can anyone suggest a way to identify what problem it is that I'm causing?
Is there any other information I should provide to give better insight into
why I'm hitting this?

Thanks,

Derrell
--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Derrell Durrett
2015-05-15 17:27:47 UTC
Permalink
Post by Derrell Durrett
C:\Users\ddurrett\AppData\Roaming\npm\node_modules\cucumber\lib\cucumber\
support_code\library.js:109
var world = new WorldConstructor(function (explicitWorld) {
^
TypeError: undefined is not a function
at Object.instantiateNewWorld (C:\Users\ddurrett\AppData\Roaming\npm\
node_modules\cucumber\lib\cucumber\support_code\library.js:109:19)
at Object.visitScenario (C:\Users\ddurrett\AppData\Roaming\npm\
node_modules\cucumber\lib\cucumber\runtime\ast_tree_walker.js:55:26)
[....truncated stack trace...]
When looking at the code in library.js, I discovered that at the end were
the following lines (132-3):
supportCodeDefinition.call(supportCodeHelper);
WorldConstructor = supportCodeHelper.World;

When I changed those lines to:
WorldConstructor = supportCodeHelper.World;
supportCodeDefinition.call(supportCodeHelper);
the code worked as expected (which means that I now have bugs that I can
attribute to me to solve!).

Is this likely an actual solution? Or am I leading myself down the wrong
path?

Thanks,

Derrell
--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Julien Biezemans
2015-05-18 10:43:40 UTC
Permalink
Post by Derrell Durrett
Post by Derrell Durrett
C:\Users\ddurrett\AppData\Roaming\npm\node_modules\cucumber\lib\cucumber
\support_code\library.js:109
var world = new WorldConstructor(function (explicitWorld) {
^
TypeError: undefined is not a function
at Object.instantiateNewWorld (C:\Users\ddurrett\AppData\Roaming\npm\
node_modules\cucumber\lib\cucumber\support_code\library.js:109:19)
at Object.visitScenario (C:\Users\ddurrett\AppData\Roaming\npm\
node_modules\cucumber\lib\cucumber\runtime\ast_tree_walker.js:55:26)
[....truncated stack trace...]
When looking at the code in library.js, I discovered that at the end were
supportCodeDefinition.call(supportCodeHelper);
WorldConstructor = supportCodeHelper.World;
WorldConstructor = supportCodeHelper.World;
supportCodeDefinition.call(supportCodeHelper);
the code worked as expected (which means that I now have bugs that I can
attribute to me to solve!).
Do you have any support code of yours? I understand the debugger tells you
none of it was loaded yet but I'd like to make sure nothing weird is being
done there as it looks like the suite execution is being done too soon.

The full stack trace would be useful here. If you're now running 0.4.9,
please run Cucumber with the `--backtrace` flag.
Post by Derrell Durrett
Is this likely an actual solution? Or am I leading myself down the wrong
path?
Thanks,
Derrell
--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/d/optout.
--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Derrell Durrett
2015-05-18 15:04:13 UTC
Permalink
Sent: 18 May, 2015 04:44
Subject: Re: [Cucumber] Re: [CUCUMBER] [JS] Failing to instantiate WorldConstructor in trivial project
On Thursday, May 14, 2015 at 3:59:27 PM UTC-6, Derrell Durrett wrote:


C:\Users\ddurrett\AppData\Roaming\npm\node_modules\cucumber\lib\cucumber\support_code\library.js:109
var world = new WorldConstructor(function (explicitWorld) {
^
TypeError: undefined is not a function
at Object.instantiateNewWorld (C:\Users\ddurrett\AppData\Roaming\npm\node_modules\cucumber\lib\cucumber\support_code\library.js:109:19)
at Object.visitScenario (C:\Users\ddurrett\AppData\Roaming\npm\node_modules\cucumber\lib\cucumber\runtime\ast_tree_walker.js:55:26)
[....truncated stack trace...]

When looking at the code in library.js, I discovered that at the end were the following lines (132-3):
supportCodeDefinition.call(supportCodeHelper);
WorldConstructor = supportCodeHelper.World;

When I changed those lines to:
WorldConstructor = supportCodeHelper.World;
supportCodeDefinition.call(supportCodeHelper);
the code worked as expected (which means that I now have bugs that I can attribute to me to solve!).
Do you have any support code of yours? I understand the debugger tells you none of it was loaded yet but I'd like to make > sure nothing weird is being done there as it looks like the suite execution is being done too soon.
I do have some support code. I’m trying to run with Spine and Hem, and (at this point) a trivial amount of additional code. My world.coffee looks like this:

Browser= require 'zombie'
nock= require 'nock'
Hem= require 'hem'
App= new Hem
App.server()

class World
@browser= new Browser()
@apiMock = nock("http://localhost")
@LoadJSON= require process.cwd() + '/app/lib/load-json'
constructor: ->

@visit: (url, next) =>
@browser.visit url, next

module.exports= World
The full stack trace would be useful here. If you're now running 0.4.9, please run Cucumber with the `--backtrace` flag.
I’ll keep trying to (re)create it for you. My efforts at the moment are failing to reach the appropriate part of the code, and are dying with:

events.js:85
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE
at exports._errnoException (util.js:746:11)
at Server._listen2 (net.js:1129:14)
at listen (net.js:1155:10)
at net.js:1253:9
at dns.js:85:18
at process._tickDomainCallback (node.js:381:11)
at Function.Module.runMain (module.js:503:11)
at startup (node.js:129:16)
at node.js:814:3

I thought this was likely due to my having a different instance open (I was bouncing between the debugger at the command line and execution in WebStorm trying to work through some other things), but failed to recover the original error when I closed the debugger.

If I can recreate it, I’ll reply with the stack trace, as I’m very interested to know if this is something I need to correct. Meantime, things work as expected if I make the change described above.

Thanks,

Derrell
--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Julien Biezemans
2015-05-19 07:41:49 UTC
Permalink
Behalf Of *Julien Biezemans
*> Sent:* 18 May, 2015 04:44
*> Subject:* Re: [Cucumber] Re: [CUCUMBER] [JS] Failing to instantiate
WorldConstructor in trivial project
C:\Users\ddurrett\AppData\Roaming\npm\node_modules\cucumber\lib\
cucumber\support_code\library.js:109
var world = new WorldConstructor(function (explicitWorld) {
^
TypeError: undefined is not a function
at Object.instantiateNewWorld (C:\Users\ddurrett\AppData\Roaming\npm\
node_modules\cucumber\lib\cucumber\support_code\library.js:109:19)
at Object.visitScenario (C:\Users\ddurrett\AppData\Roaming\npm\
node_modules\cucumber\lib\cucumber\runtime\ast_tree_walker.js:55:26)
[....truncated stack trace...]
When looking at the code in library.js, I discovered that at the end
supportCodeDefinition.call(supportCodeHelper);
WorldConstructor = supportCodeHelper.World;
WorldConstructor = supportCodeHelper.World;
supportCodeDefinition.call(supportCodeHelper);
the code worked as expected (which means that I now have bugs that I can
attribute to me to solve!).
Post by Julien Biezemans
Do you have any support code of yours? I understand the debugger tells
you none of it was loaded yet but I'd like to make > sure nothing weird
is being done there as it looks like the suite execution is being done too
soon.
I do have some support code. I’m trying to run with Spine and Hem, and (at
this point) a trivial amount of additional code. My world.coffee looks like
*Browser*= require
*'zombie' **nock*= require
*'nock' **Hem*= require
*'hem' **App*= *new *
*Hem App*.server()
*class *World
*'/app/lib/load-json' *constructor: ->
module.exports= World
This line has an issue. Cucumber will automatically execute the function
exposed as the `module.exports` property by any modules in your features/
directory. This is to let you define step definitions and run one-off
pre-run code.

It means you need to avoid exposing functions like that (including World
constructors) if you don't want them to be executed by Cucumber. To do
that, you can simply expose an object as `module.exports` and set a
property with your World constructor on it. You'll then be able to require
your module's World property without it being auto-executed by Cucumber:

`module.exports.World = World` should do the trick.

Of course, you'll need to change the code that requires the module to
something like that:

`var World = require('world').World`

HTH,

J.
Post by Julien Biezemans
The full stack trace would be useful here. If you're now running 0.4.9,
please run Cucumber with the `--backtrace` flag.
I’ll keep trying to (re)create it for you. My efforts at the moment are
events.js:85
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE
at exports._errnoException (util.js:746:11)
at Server._listen2 (net.js:1129:14)
at listen (net.js:1155:10)
at net.js:1253:9
at dns.js:85:18
at process._tickDomainCallback (node.js:381:11)
at Function.Module.runMain (module.js:503:11)
at startup (node.js:129:16)
at node.js:814:3
I thought this was likely due to my having a different instance open (I
was bouncing between the debugger at the command line and execution in
WebStorm trying to work through some other things), but failed to recover
the original error when I closed the debugger.
If I can recreate it, I’ll reply with the stack trace, as I’m very
interested to know if this is something I need to correct. Meantime, things
work as expected if I make the change described above.
Thanks,
Derrell
--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/d/optout.
--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Derrell Durrett
2015-05-19 15:06:21 UTC
Permalink
From: ***@googlegroups.com [mailto:***@googlegroups.com] On Behalf Of Julien Biezemans
Sent: 19 May, 2015 01:42
To: ***@googlegroups.com
Subject: Re: [Cucumber] Re: [CUCUMBER] [JS] Failing to instantiate WorldConstructor in trivial project

On Mon, May 18, 2015 at 5:04 PM Derrell Durrett <***@melco.com<mailto:***@melco.com>> wrote:

Browser= require 'zombie'
nock= require 'nock'
Hem= require 'hem'
App= new Hem
App.server()

class World
@browser= new Browser()
@apiMock = nock("http://localhost")
@LoadJSON= require process.cwd() + '/app/lib/load-json'
constructor: ->

@visit: (url, next) =>
@browser.visit url, next

module.exports= World
This line has an issue. Cucumber will automatically execute the function exposed as the `module.exports` property by any
modules in your features/ directory. This is to let you define step definitions and run one-off pre-run code.
It means you need to avoid exposing functions like that (including World constructors) if you don't want them to be
executed by Cucumber. To do that, you can simply expose an object as `module.exports` and set a property with your
World constructor on it. You'll then be able to require your module's World property without it being auto-executed by
`module.exports.World = World` should do the trick.
`var World = require('world').World`
Thanks (particularly for the explanation)! I had struggled with that, even though I was able to get it “working” the way I previously posted. But doing it the correct way is obviously preferable.

Still, this doesn’t alter the result reported previously. I continue to get:

events.js:85
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE
at exports._errnoException (util.js:746:11)
at Server._listen2 (net.js:1129:14)
at listen (net.js:1155:10)
at net.js:1253:9
at dns.js:85:18
at process._tickDomainCallback (node.js:381:11)
at Function.Module.runMain (module.js:503:11)
at startup (node.js:129:16)
at node.js:814:3

when I revert library.js (in cucumber/lib/cucumber/support_code/library.js)
--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...