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

Support ESM specs with Mocha #5809

Merged
merged 1 commit into from
Sep 10, 2020
Merged

Support ESM specs with Mocha #5809

merged 1 commit into from
Sep 10, 2020

Conversation

diachedelic
Copy link
Contributor

@diachedelic diachedelic commented Sep 9, 2020

Proposed changes

Mocha#loadFiles only support CommonJS, so I replaced it with
Mocha#loadFilesAsync which supports both CommonJS and ESM.

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update

Checklist

  • I have read the CONTRIBUTING doc
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)
  • I have added proper type definitions for new commands (if appropriate)

Further comments

Reviewers: @webdriverio/project-committers

@jsf-clabot
Copy link

jsf-clabot commented Sep 9, 2020

CLA assistant check
All committers have signed the CLA.

@diachedelic
Copy link
Contributor Author

diachedelic commented Sep 9, 2020

Source: https://mochajs.org/api/mocha#loadFilesAsync
Edit: fixes #3269

@christian-bromann
Copy link
Member

@diachedelic thanks a lot for the patch. I think you need to adapt the Mocha mock to get tests passing.

Mocha#loadFiles only support CommonJS, so I replaced it with
Mocha#loadFilesAsync which supports both CommonJS and ESM.
@diachedelic
Copy link
Contributor Author

Ah yes, done!

Copy link
Member

@christian-bromann christian-bromann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 thanks!

@unickq
Copy link
Contributor

unickq commented Sep 10, 2020

Did it pass all the tests? @christian-bromann

Looks like after update to 6.4.7 I can't run any test with npx wdio --spec. Is there a way to retrieve wdio logs?

@diachedelic
Copy link
Contributor Author

Running wdio --spec using v6.4.7 is working for me - I ran unit tests but I'm not sure if there were any e2e tests I should have run.

@christian-bromann
Copy link
Member

@unickq it passed all tests and was released with the latest version.

@unickq
Copy link
Contributor

unickq commented Sep 10, 2020

weird. I had to downgrade it back to 6.4.0 for all my ts projects.

Thanks anyway

@vchuchkalov
Copy link

same. I had to downgrade it back to 6.4.0 for all my ts projects.
6.4.7 passes all tests without passing them.

@christian-bromann
Copy link
Member

@unickq @vchuchkalov could you provide a minimal reproducible example?

@vchuchkalov
Copy link

vchuchkalov commented Sep 14, 2020

this happens when there is no function implementation or other errors before the test starts

[0-0] 2020-09-14T09:17:48.112Z INFO @wdio/local-runner: Run worker command: run
[0-0] 2020-09-14T09:18:00.188Z DEBUG @wdio/local-runner:utils: init remote session
[0-0] 2020-09-14T09:18:00.190Z INFO webdriverio: Initiate new session using the ./protocol-stub protocol
[0-0] 2020-09-14T09:18:05.474Z WARN @wdio/mocha-framework: Unable to load spec files quite likely because they rely on `browser` object that is not fully initialised.
`browser` object has only `capabilities` and some flags like `isMobile`.
Helper files that use other `browser` commands have to be moved to `before` hook.
Spec file(s): /Users/User/WebstormProjects/myProject/autotests/test/ui/mainPage/errorDesktop1.ts
 Error:  TypeError: elements.MeetupsListDesktop is not a function

my elements.MeetupsListDesktop function gets implementation in the before hook.
In version 6.4.0, the error is the same, but the test runs passes. In 6.4.7, the test body does not run

@unickq
Copy link
Contributor

unickq commented Sep 14, 2020

Probably found why it happens.
I have a file with commands - browserCommands.
Which I load in

framework: "mocha",
  mochaOpts: {
    ui: "bdd",
    timeout: 90000,
    require: [
      "ts-node/register",
      "tsconfig-paths/register",
      "src/wdio/browserCommands",
    ],
  },

Just noticed that it throws warn on 6.4.0 as well.

WARN @wdio/mocha-framework: Unable to load spec files quite likely because they rely on `browser` object that is not fully initialised.
`browser` object has only `capabilities` and some flags like `isMobile`.
Helper files that use other `browser` commands have to be moved to `before` hook.
Spec file(s): C:\Git\q\download.spec.ts
Error:  Error: Module src/wdio/browserCommands can't get loaded. Are you sure you have installed it?
Note: if you've installed WebdriverIO globally you need to install these external modules globally too!

But tests are running even with this warning.

After update to 6.4.7 - I see the same warning, but tests don't start.

So if I remove "src/wdio/browserCommands" from mochaOpts - everything is gonna be fine, but I won't have my commands active.

[0-0] RUNNING in chrome - C:\Git\q\download.spec.ts
[0-0] TypeError in "Cards Download Finish option "before all" hook for "Card size - Half""
this.root.$(...).waitUntilClickable is not a function

@christian-bromann so is there a correct way to config custom commands for TS?

@christian-bromann
Copy link
Member

so is there a correct way to config custom commands for TS?

You can also use the before hook in your wdio.conf.js but I feel like this should continue to work given that we initialise the browser instance before we initialise the framework. Would you mind setting up a minimal TS project that reproduces this? I would be happy to look into it.

@unickq
Copy link
Contributor

unickq commented Sep 14, 2020

Would you mind setting up a minimal TS project that reproduces this? I would be happy to look into it.

example.zip
wdio.conf.js line 142

And yes, looks like moving src/wdio/browserCommands from mochaOpts to before` fixes this,
Thanks

@diachedelic
Copy link
Contributor Author

I can confirm that if a spec fails to load, it is immediately reported as a success (try including some invalid syntax and you'll see what I mean), and I'm not using typescript.

@alecf
Copy link

alecf commented Sep 18, 2020

I'm seeing some of my tests fail to load starting in 6.4.7 and had to back down to 6.4.0 - could this PR be the cause of #5874 ?

@diachedelic
Copy link
Contributor Author

@alecf could you please post your wdio.log for the failing specs? When my specs failed to load, the error message was printed in there.

@alecf
Copy link

alecf commented Sep 21, 2020

@diachedelic I'll post it over in #5874

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: Bug Fix 🐛 PRs that contain bug fixes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants