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

unable to pass hook typechecks after upgrading to version 5.10.7 #4104

Closed
flurmbo opened this issue Jun 20, 2019 · 14 comments · Fixed by #4114
Closed

unable to pass hook typechecks after upgrading to version 5.10.7 #4104

flurmbo opened this issue Jun 20, 2019 · 14 comments · Fixed by #4114
Assignees
Labels

Comments

@flurmbo
Copy link

flurmbo commented Jun 20, 2019

Environment:

  • WebdriverIO version: 5.10.7
  • Mode: wdio CLI with mocha
  • If WDIO Testrunner, running sync/async: async
  • Node.js version: 10.15.1
  • NPM version: 6.9.0
  • Platform name and version: Ubuntu 18.04

Config of WebdriverIO

exports.config = {
  user: credentials.user
  key: credentials.key,
  specs: [
    // specs
  ],
  capabilities: [
    // capabilities
  ],
  framework: 'mocha',
  mochaOpts: {
    ui: 'bdd',
    timeout: 180000, // 3 minutes
  },
};

Describe the bug
Hi! I tried to upgrade our Webdriverio test script to the latest version, 5.10.7, from 5.7.8. When I tried running the script, I got an error that onPrepare needs to be a list of functions (we currently do not use any hooks). After adding a list containing a dummy function to the config (onPrepare: [() => {}]), I got an error saying that config.onPrepare is not a function! Not sure if this is a bug or if I'm misunderstanding how to correctly configure my script, any help would be appreciated!

To Reproduce
Steps to reproduce the behavior:

I think it's fairly clear how to reproduce, but I will make an example if requested

Expected behavior
Config should validate successfully with no hooks defined, or with dummy hooks defined

Log

Worker Error:
Error: Type check for option "onPrepare" failed: a hook option needs to be a list of functions
     at validateConfig 

After adding in a list containing 1 dummy function, I get:

node_modules/@wdio/cli/build/run.js:89
    throw e;
    ^

TypeError: config.onPrepare is not a function
@christian-bromann
Copy link
Member

After adding a list containing a dummy function to the config (onPrepare: [() => {}]), I got an error saying that config.onPrepare is not a function

Can you try to update all packages in your package.json? Do you have a minimal reproducible example?

@mgrybyk
Copy link
Member

mgrybyk commented Jun 25, 2019

@christian-bromann @flurmbo I can confirm the issue.

It is possible to pass plain function but it is not possible to pass an array of functions.

@mgrybyk
Copy link
Member

mgrybyk commented Jun 25, 2019

// works fine
const conf: WebdriverIO.Config = {
    onPrepare: (config, caps) => { }
}
// throws an error
const conf: WebdriverIO.Config = {
    onPrepare: [() => { }]
}

@christian-bromann christian-bromann added Bug 🐛 good first pick a reasonable task to start getting familiar with the code base help wanted Issues that are free to take by anyone interested labels Jun 25, 2019
@mgrybyk mgrybyk self-assigned this Jun 25, 2019
@mgrybyk mgrybyk removed good first pick a reasonable task to start getting familiar with the code base help wanted Issues that are free to take by anyone interested labels Jun 25, 2019
@mgrybyk mgrybyk mentioned this issue Jun 25, 2019
6 tasks
@Laxmipb28
Copy link

Hi All,

I'm facing the same issue. Is there any solution for this?

@mgrybyk
Copy link
Member

mgrybyk commented Jul 30, 2019

What exactly are you facing? The solution is to upgrade to the latest versions of all wdio packages

@Laxmipb28
Copy link

My code is failing when reaches resolve(), it throws
message:
'Type check for option "onPrepare" failed: a hook option needs to be a list of functions',
stack:
'Error: Type check for option "onPrepare" failed: a hook option needs to be a list of functions

Can anyone help me with this?

@mgrybyk
Copy link
Member

mgrybyk commented Aug 5, 2019

Make it a functions list. Does it help?

You need to update all wdio packages to the latest version. Try deleting node modules folder and package lock json file

@Laxmipb28
Copy link

It was working fine for 1 window, but it was not able to open a new Window. So, I updated the selenium server version using 'java -jar -Dwebdriver.gecko.driver=./geckodriver selenium-server-standalone-3.5.3.jar'. After that, it started giving "Type check for option "onPrepare" failed: a hook option needs to be a list of functions' " . My onprepare method is function list only.

@mgrybyk
Copy link
Member

mgrybyk commented Aug 5, 2019

It should work fine, both with functions and function list.
Please upgrade to latest versions, try deleting package lock json and nodr modules, and try again.
If it still doesn't work rise an issue with reproducible example in some repo.

@Laxmipb28
Copy link

Please confirm if these steps correct:

  1. Delete node modules folder
  2. Delete package-lock.json file
  3. npm install
  4. npm install webdriverio@latest
  5. npm install @wdio/cli --save-dev

I'm not sure if I'm missing something

@mgrybyk
Copy link
Member

mgrybyk commented Aug 5, 2019

It works for me

@Laxmipb28
Copy link

Hey,

Thank you so much. It worked for me too.

@mgrybyk
Copy link
Member

mgrybyk commented Aug 6, 2019

Nice!

NickGerleman added a commit to NickGerleman/react-native-windows that referenced this issue Feb 22, 2020
We hardcode an old version of WebderiverIO beacuse of microsoft#3019. These seem to have loose dependency requirements, because the change to deuplicate packages broke this (see webdriverio/webdriverio#4104). Hardcode resolutions in E2ETest for existing versions of wdio packages in the meantime.
ghost pushed a commit to microsoft/react-native-windows that referenced this issue Feb 22, 2020
* Initial commit of override tooling

Add a foundation for new override tooling described in #4104. This includes:

- Build scripts, lint scripts, config files, etc
- Logic for parsing and checking validity of an override manifest
- Unit tests for override manifest logic
- Abstractions to allow fetching React Native files of arbtrary versions

A lot of this is foundational. The override logic has been well-tested,
and the Git logic has been manually tested, but we don't have much
end-to-end set up yet.

* Address comments and deuplicate lockfile

* Add more dependencies for WebDriverIO

We hardcode an old version of WebderiverIO beacuse of #3019. These seem to have loose dependency requirements, because the change to deuplicate packages broke this (see webdriverio/webdriverio#4104). Hardcode resolutions in E2ETest for existing versions of wdio packages in the meantime.
@sytolk
Copy link

sytolk commented Jan 19, 2021

Hi All

afterTest hook throw Error: Type check for option "afterTest" failed: a hook option needs to be a list of functions

let options = {
      host: 'localhost', // Use localhost as chrome driver server
      port: 9515, // "9515" is the port opened by chrome driver.
      capabilities: {
        browserName: 'chrome',
        'goog:chromeOptions': {
          args: [
            '--no-sandbox',
            '--window-size=1920,1080',
            '--disable-dev-shm-usage'
          ]
        },
        timeouts: {
          script: 60000
        }
      },
      afterTest: async (
        test,
        context,
        { error, result, duration, passed, retries }
      ) => {
        await takeScreenshot();
        await clearLocalStorage();
      },
      waitforTimeout: 5000,
      maxInstances: 1,
      logLevel: 'silent',
      coloredLogs: true
    };

global.client = await webdriverio.remote(options);

I have try to change

afterTest: [async (
        test,
        context,
        { error, result, duration, passed, retries }
      ) => {
        await takeScreenshot();
        await clearLocalStorage();
      }],

now the error disapers but afterTest hook is newer called. What can be the reason for this ?

webdriverio -> "version": "6.4.6",

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants