stalniy / bdd-lazy-var

Provides UI for testing frameworks such as mocha, jasmine and jest which allows to define lazy variables and subjects.
MIT License
162 stars 14 forks source link

TypeError: suite.parent.appendOnlySuite is not a function #64

Closed chrisbutler closed 5 years ago

chrisbutler commented 5 years ago

if i try to run mocha with an .only block, i get the following error:

express/node_modules/bdd-lazy-var/node_modules/mocha/lib/interfaces/common.js:132
          suite.parent.appendOnlySuite(suite);
                       ^
TypeError: suite.parent.appendOnlySuite is not a function
    at Object.create (express/node_modules/bdd-lazy-var/node_modules/mocha/lib/interfaces/common.js:132:24)
    at Object.only (express/node_modules/bdd-lazy-var/node_modules/mocha/lib/interfaces/common.js:96:21)
    at context.describe.only (express/node_modules/bdd-lazy-var/node_modules/mocha/lib/interfaces/bdd.js:69:27)
    at Function.detectSuite [as only] (express/node_modules/bdd-lazy-var/global.js:475:25)
    at Module.only

this only happens on 2.5.1

Example to reproduce:

Important note: if you install dependencies using yarn only!

describe.only("test suite", () => { // <--- error thrown here
  def("name", "John");

  it("works", () => {
    expect($name).to.equal("John");
  });

  context("nested suite", () => {
    it("also works", () => {
      expect($name).to.equal("John");
    });

    it("works as well", () => {
      expect(1).to.equal(1);
    });
  });
});
stalniy commented 5 years ago

Hi,

Thanks for the issue. I’ll try to check and fix soon.

stalniy commented 5 years ago

I've just tried to reproduce the issue and I can't :) Could you please tell the version of mocha?

stalniy commented 5 years ago

Also the stack trace looks a bit weird to me -> bdd-lazy-var/node_modules/mocha/lib/interfaces/common.js

But mocha is an optional dependency of bdd-lazy-var and should not be installed as a subdependency in node_modules folder under bdd-lazy-var

stalniy commented 5 years ago

I configured the sample: https://codesandbox.io/s/7k95x0zzkq

You can open additional terminal in codesandbox (+ sign in terminal tab on the right hand) and in terminal type npm start

stalniy commented 5 years ago

@chrisbutler @AJMiller @derosm2 could you please provide more details? version of mocha version of npm version on node

and ideally link with an example

chrisbutler commented 5 years ago

@stalniy sorry for the late followup here, i wasn't getting notifications on this until i was tagged :(

so we're on mocha 5.2 and node 8. i've confirmed that updating to v2.5.1 of this package causes the following in my yarn.lock:

"mocha@^4.0.0 || ^3.0.0 || ^2.3.0 || ^5.0.0 || ^6.0.0":
  version "6.1.4"
  resolved "https://registry.yarnpkg.com/mocha/-/mocha-6.1.4.tgz#e35fada242d5434a7e163d555c705f6875951640"
  integrity sha512-PN8CIy4RXsIoxoFJzS4QNnCH4psUCPWc4/rPrst/ecSJJbLBkubMiyGCP2Kj/9YnWbotFqAoeXyXMucj7gwCFg==
  dependencies:
    ansi-colors "3.2.3"
    browser-stdout "1.3.1"
    debug "3.2.6"
    diff "3.5.0"
    escape-string-regexp "1.0.5"
    find-up "3.0.0"
    glob "7.1.3"
    growl "1.10.5"
    he "1.2.0"
    js-yaml "3.13.1"
    log-symbols "2.2.0"
    minimatch "3.0.4"
    mkdirp "0.5.1"
    ms "2.1.1"
    node-environment-flags "1.0.5"
    object.assign "4.1.0"
    strip-json-comments "2.0.1"
    supports-color "6.0.0"
    which "1.3.1"
    wide-align "1.1.3"
    yargs "13.2.2"
    yargs-parser "13.0.0"
    yargs-unparser "1.5.0"

mocha@^5.0.0:
  version "5.2.0"
  resolved "https://registry.yarnpkg.com/mocha/-/mocha-5.2.0.tgz#6d8ae508f59167f940f2b5b3c4a612ae50c90ae6"
  integrity sha512-2IUgKDhc3J7Uug+FxMXuqIyYzH7gJjXECKe/w43IGgQHTSj3InJi+yAA7T24L9bQMRKiUEHxEX37G5JpVUGLcQ==
  dependencies:
    browser-stdout "1.3.1"
    commander "2.15.1"
    debug "3.1.0"
    diff "3.5.0"
    escape-string-regexp "1.0.5"
    glob "7.1.2"
    growl "1.10.5"
    he "1.1.1"
    minimatch "3.0.4"
    mkdirp "0.5.1"
    supports-color "5.4.0"

I've been trying to get a codesandbox demo working (including some other mocha-related packages we use), but when I try to set the Mocha UI to 'bdd-lazy-var/global' it suddenly can't find any test files: https://codesandbox.io/s/53377qx20x

Either way, flipping the version of this package back to 2.5.0 results in everything working again... Thoughts on what it could be?

stalniy commented 5 years ago

@chrisbutler the only difference between 2.5.1 and 2.5.0 is in package.json. In 2.5.1. I added mocha@6.0.0 in optionalDependencies. In terms of functionality nothing was changed

stalniy commented 5 years ago

@chrisbutler I have just executed your example bdd-lazy-var@2.5.1 and mocha@5.2.0. See this video:

Peek 2019-05-09 19-53

Update: codesandbox uses node v10.15.2

chrisbutler commented 5 years ago

@stalniy i understand that your example works, but our use case currently involves programmatically running mocha. i was attempting to replicate that in codesandbox

stalniy commented 5 years ago

@chrisbutler I see. This was the missing piece for me. I'll try to setup

Update: Updated example -> https://codesandbox.io/s/l4832yzxkz

Peek 2019-05-09 20-50

chrisbutler commented 5 years ago

@stalniy thanks for getting back to me so quickly. i think i've narrowed it down to a reproducible case by adding a .only to the describe in your latest updated example: https://codesandbox.io/s/vv04my80r5

it doesn't happen if i add .only to context though

stalniy commented 5 years ago

Ok, so if I correctly understood the issue is only with top-level describe statements

stalniy commented 5 years ago

So, the weirdest thing I found is if you install package.json using npm install everything works without errors. But if you install deps using yarn only then issue can be reproduced :)

stalniy commented 5 years ago

Found the cause of issue. This is dependency tree created by yarn:

├─ bdd-lazy-var@2.5.1
│  └─ mocha@6.1.4
└─ mocha@5.2.0

and this is tree from npm:

├─┬ bdd-lazy-var@2.5.1
│ └── mocha@5.2.0  deduped
└── mocha@5.2.0 

I use npm that's why it was hard to reproduce the issue

stalniy commented 5 years ago

fixed in bdd-lazy-var@2.5.2

chrisbutler commented 5 years ago

@stalniy that's crazy! i had a feeling it was related to yarn which is why included that piece of the yarn.lock file, but i didn't have any ideas about why yarn was doing it or how to fix it

tested and confirmed that it's working again in 2.5.2. thanks again!