this.context.name - does not behave as expected #228

Closed
osher opened this Issue Aug 13, 2012 · 3 comments

Comments

Projects
None yet
3 participants

osher commented Aug 13, 2012

I was trying to automate macros relaying on context.name as demonstrated in http://vowsjs.org/#-macros, but ran into some difficulties:

I would expect this.context.name to contain all the titles/context-names on the path to the executed test or topic.
In the output of the following test - at least the last part is missing included.

I suspect that this is the same bug behind issues with -r switch.

require('vows').describe(
  'aa'
).addBatch(
  {"top": 
    { "ctx" : 
      { topic: 
        function(){ 
          console.log("\ntopic!\n", this); 
          console.log("\n!topic\n"); 
          return 1 
        } 
      , fun: function(){} 
    } 
  } 
}),addBatch(
  {"top2": 
    { "ctx2" : 
      function(){ 
        console.log("\ntest!\n", this); 
        console.log("\n!test\n") 
      }
    }
 }).export(module);

Expected
this.context.name to be "top ctx topic" or "top ctx", and "top2 ctx2"

Found/
this.context.name were "top" and "top2"

raw output

topic!
 { suite:
   { subject: 'aa',
     matcher: /.*/,
     reporter:
      { name: 'dot-matrix',
        setStream: [Function],
        reset: [Function],
        report: [Function],
        print: [Function] },
     batches: [ [Object], [Object] ],
     options: { error: true },
     results:
      { honored: 0,
        broken: 0,
        errored: 0,
        pending: 0,
        total: 0,
        time: null } },
  context:
   { tests: { topic: [Function], fun: [Function] },
     topics: [],
     emitter: null,
     env: [Circular],
     name: 'ctx',
     isEvent: false,
     event: 'success',
     title: 'top ctx' },
  callback: [Function] }

!topic

·
test!
 { suite:
   { subject: 'aa',
     matcher: /.*/,
     reporter:
      { name: 'dot-matrix',
        setStream: [Function],
        reset: [Function],
        report: [Function],
        print: [Function] },
     batches: [ [Object], [Object] ],
     options: { error: true },
     results:
      { honored: 1,
        broken: 0,
        errored: 0,
        pending: 0,
        total: 1,
        time: null } },
  context:
   { tests: { ctx2: [Function] },
     topics: [],
     emitter:
      { _events: [Object],
        _vowsEmitedEvents: [Object],
        _vowsEmitedEventsOrder: [Object],
        _maxListeners: Infinity },
     env: [Circular],
     name: 'top2',
     isEvent: false,
     event: 'success',
     title: 'top2' },
  callback: [Function] }

!test

· √ OK » 2 honored (0.124s)

node 8.5, win XP sp3, vows 0.6.3

I think this is behaving as expected. In this case, ctx is a vow (with a topic) and top is its context. So context.name should return "top" and context.title should return "top ctx". Looks good to me.

Our documentation of this, on the other hand, is poor, and needs fixing.

@samlecuyer samlecuyer closed this Nov 18, 2014

@indexzero please re-open if I'm way off.

Owner

indexzero commented Nov 19, 2014

I think this is correct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment