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

TypeError: Cannot read property 'toString' of undefined at ActivityTracker.shouldTrack #174

Closed
nbarrett opened this issue Feb 24, 2018 · 3 comments

Comments

@nbarrett
Copy link
Contributor

nbarrett commented Feb 24, 2018

I've been happily running my specs for a few days and suddenly I'm now having this problem and I have no idea why:

[12:12:50] I/launcher - Running 1 instances of WebDriver

[12:12:50] I/direct - Using ChromeDriver directly...

 0 passing (74ms)
  1 failing
  1) Walks and Events Manager walk upload:
     TypeError: Cannot read property \'toString\' of undefined
      at ActivityTracker.shouldTrack (node_modules/@serenity-js/core/src/screenplay/actor.ts:96:59)
      at ActivityTracker.track (node_modules/@serenity-js/core/src/screenplay/actor.ts:91:42)
      at Array.map (native)
      at Actor.attemptsTo (node_modules/@serenity-js/core/src/screenplay/actor.ts:68:27)
      at Context.<anonymous> (client/spec/features/walks-upload.ts:20:22)
      at runTest (node_modules/serenity-js/src/serenity-mocha/controlflow.ts:96:32)
      at node_modules/serenity-js/src/serenity-mocha/controlflow.ts:117:24
      at new ManagedPromise (node_modules/selenium-webdriver/lib/promise.js:1067:7)
      at controlFlowExecute (node_modules/serenity-js/src/serenity-mocha/controlflow.ts:116:20)
      at TaskQueue.execute_ (node_modules/selenium-webdriver/lib/promise.js:2970:14)
  From: Task: Walks and Events Manager walk upload
      at Context.ret (node_modules/serenity-js/src/serenity-mocha/controlflow.ts:115:14)

[12:12:52] I/launcher - 0 instance(s) of   WebDriver still running

[12:12:52]   E/launcher - Process exited with error code 1

[12:12:52] I/launcher - chrome #01 failed 1   test(s) [12:12:52] I/launcher - overall: 1 failed spec(s) 

Error: ERR! Darwin 16.7.0 npm ERR! argv   "/Users/nick/.nvm/versions/node/v6.11.3/bin/node"   "/Users/nick/.nvm/versions/node/v6.11.3/bin/npm" "run"   "e2e" npm ERR! node v6.11.3 npm ERR! npm v3.10.10 npm ERR! code   ELIFECYCLE npm ERR! ekwg@0.0.1 e2e: `protractor ./protractor.conf.js` npm   ERR! Exit status 1 npm ERR!

I can't even find out what part of my code I'm running as there is none of my code in the stack trace.

I've also tried adding/removing the crew as I don't actually need them on this project (which is a screen-scraping application), but it doesn't make any difference. Any thoughts please @jan-molak ?

@nbarrett
Copy link
Contributor Author

nbarrett commented Feb 24, 2018

Found it after about 12 hours of head-scratching!! I used to have this static method:

static requested() {
        const walkParameters = RequestParameterExtractor.extract();
        return new DeleteWalksWithIds(walkParameters.walkDeletions);
    }

However I changed this method to be conditional as follows:

    static requested() {
        const walkParameters = RequestParameterExtractor.extract();
        if (walkParameters.walkDeletions.length > 0) {
            return new DeleteWalksWithIds(walkParameters.walkDeletions);
        }
    }

This means that when the if statement was false the method returned undefined but because I had no type information on the static method, the test was able to run but an undefined Task found it's way into Serenity (perhaps a PR might be worth creating that validates such undefined Tasks and points the developer to their faulty line of code? I'd hate for other people to go through this pain 😭).

So my fixed method now looks like this which always returns a Task:

    static requested(): Task {
        const walkParameters = RequestParameterExtractor.extract();
        if (walkParameters.walkDeletions.length > 0) {
            console.log(`Deleting existing ${walkParameters.walkDeletions.length} walk(s) from site before upload`);
            return new DeleteWalksWithIds(walkParameters.walkDeletions);
        } else {
            return new SilentPerformable();
        }
    }

** SilentPerformable is part of a PR #159 that still awaits your approval 😄.

@jan-molak
Copy link
Member

Thanks for the update, @nbarrett! Yes, so it looks like static requested() had an implicit return type of any and perhaps that's why the TS transpiler didn't complain?

Let's discuss the SilentPerformable in #159 and I'll close this ticket unless you feel it should remain open?

@nbarrett
Copy link
Contributor Author

umm, I could raise a PR following my previous comment?

a PR might be worth creating that validates such undefined Tasks and points the developer to their faulty line of code? I'd hate for other people to go through this pain 😭).

nbarrett pushed a commit to nbarrett/serenity-js that referenced this issue May 1, 2020
…d_yarn/serenity-js/console-reporter-2.2.2
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

2 participants