@wdio/sync: TypeError: hook.apply is not a function

1.8k views Asked by At

I'm using webdriverIO 6 with typescript and Jasmine and recently (after upgrading @wdio/sync to 6.10.11 and I'm not sure if it's coincidence or not) I noticed I've got some new errors during the test runs - before and after every "it":

Starting ChromeDriver 88.0.4324.96 on port 9515
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
[0-0] RUNNING in chrome - /dist/specs/main.spec.js
[0-0] 2021-01-28T14:28:25.059Z ERROR @wdio/sync: TypeError: hook.apply is not a function
    at execHook (/Users/marian/projects/***e2e/node_modules/@wdio/sync/build/executeHooksWithArgs.js:21:31)
[0-0] Error in "BeforeTest Hook"
hook.apply is not a function
[0-0] Opened url: ***
[0-0] 2021-01-28T14:28:28.826Z ERROR @wdio/sync: TypeError: hook.apply is not a function
    at execHook (/Users/marian/projects/-e2e/node_modules/@wdio/sync/build/executeHooksWithArgs.js:21:31)
[0-0] Error in "AfterTest Hook"
hook.apply is not a function

It stayed like this after wdio/sync upgrade to 6.11.00.

This is my stack:

  "devDependencies": {
    "@types/jasmine": "^3.6.2",
    "@types/node": "^14.14.20",
    "@typescript-eslint/eslint-plugin": "^4.12.0",
    "@typescript-eslint/parser": "^4.12.0",
    "@wdio/cli": "^6.11.3",
    "@wdio/devtools-service": "^6.11.0",
    "@wdio/jasmine-framework": "6.6.3",
    "@wdio/local-runner": "^6.11.3",
    "@wdio/spec-reporter": "^6.11.0",
    "@wdio/sync": "6.11.0",
    "eslint": "^7.17.0",
    "eslint-config-standard": "^16.0.2",
    "eslint-plugin-import": "^2.22.1",
    "eslint-plugin-node": "^11.1.0",
    "eslint-plugin-promise": "^4.2.1",
    "wdio-chromedriver-service": "^6.0.4"
  },
  "dependencies": {
    "@rpii/wdio-html-reporter": "~6.1.1",
    "@slack/web-api": "^5.15.0",
    "@wdio/reporter": "^6.11.0",
    "chromedriver": "^88.0.0",
    "typescript": "4.1.3",
    "wdio-timeline-reporter": "^5.1.4"
  }

In the wdio.conf.js I use only one hook and this is not the one causing the problem since it's triggered only once at the end (onComplete()) and commenting it does not make any difference.

I also use CustomReporter which extends WDIOreporter and use onTestPass() and onTestFail() methods there but even disabling whole reporter does not make any difference.

I looked into executeHooksWithArgs.js:21:31 but but that doesn't mean anything to me, except that this part is responsible for hooks.

I tried going back to @wdio/sync 6.6.0 (which I was using before the upgrade) fails miserably with similar error in the same file:

ERROR @wdio/local-runner: Failed launching test session: TypeError: hooks.map is not a function
    at Object.executeHooksWithArgs (/Users/marian/projects/***/node_modules/@wdio/sync/build/executeHooksWithArgs.js:16:19)
(...) Error: Could not find job

What is bothering me is I have another project with similar setup and no errors in there, I was upgrading them in the same time. I don't even know where to look anymore.

2

There are 2 answers

0
VivaceNonTroppo On

So before I send this I dived into gitlab history for this project and the similar project I mentioned in the last paragraph and I noticed one difference:

-    "@wdio/jasmine-framework": "6.6.3",
+    "@wdio/jasmine-framework": "^6.11.0",

After upgrading this, the problem is gone. I wish I could write something more about the causes but to be honest I have no idea what exactly was causing it.

What I know is if you have similar issue try to upgrading your framework, it works for Jasmine, I'm not sure if there are any problems like this with Mocha or Cucumber but if yes - it's worth the try.

1
yachao fan On

Having a similar issue, my stack is:

"@wdio/sync": "6.11.0", "@wdio/cucumber-framework": "6.8.0"

When I upgrade @wdio/cucumber-framework to 6.11.1, the error is gone.