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

Propagate error when loading suite #5910

Merged
merged 2 commits into from
Oct 1, 2020
Merged

Conversation

christian-bromann
Copy link
Member

Proposed changes

With the change we introduced in #5809 we started to ignore errors when loading the spec file. Let's say someone uses a command outside an it block or hook like this:

describe('webdriver.io page', () => {
    it('should be a pending test')

    browser.setTimeout({ script: 60000 * 10 })

    it('should have the right title', () => {
        browser.url('https://webdriver.io')
        expect(browser).toHaveTitle('WebdriverIO · Next-gen browser and mobile automation test framework for Node.js')
    })
})

WebdriverIO would pass the suite with no error:

Execution of 1 spec files started at 2020-10-01T10:46:37.704Z

let's go
[0-0] RUNNING in chrome - /mocha/mocha.test.js
[0-0] PASSED in chrome - /mocha/mocha.test.js
that's it

"spec" Reporter:
------------------------------------------------------------------
[chrome 85.0.4183.121 mac os x #0-0] Spec: /path/to/webdriverio/examples/wdio/mocha/mocha.test.js
[chrome 85.0.4183.121 mac os x #0-0] Running: chrome (v85.0.4183.121) on mac os x
[chrome 85.0.4183.121 mac os x #0-0] Session ID: 7a2ac4601d5fd4a66f21bcf3506de0bb
[chrome 85.0.4183.121 mac os x #0-0]
[chrome 85.0.4183.121 mac os x #0-0] webdriver.io page
[chrome 85.0.4183.121 mac os x #0-0]    - should be a pending test
[chrome 85.0.4183.121 mac os x #0-0]
[chrome 85.0.4183.121 mac os x #0-0] 1 skipped (242ms)

Spec Files:      1 passed, 1 total (100% completed) in 00:00:02

This is rather suboptimal as there is clearly an issue in the spec that needs to be addressed. Instead of just ignoring it we should make users aware and have the test fail.

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

We already catch the error and only need to propagate it. With this patch the test run now looks as follows:

Execution of 1 spec files started at 2020-10-01T10:47:53.778Z
                                                                                                                    
let's go
[0-0] RUNNING in chrome - /mocha/mocha.test.js
[0-0]  Error:  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/christianbromann/Sites/webdriverio/webdriverio/examples/wdio/mocha/mocha.test.js
Error: TypeError: browser.setTimeout is not a function
    at Suite.describe (/path/to/webdriverio/examples/wdio/mocha/mocha.test.js:4:13)
    at Object.create (/path/to/webdriverio/packages/wdio-mocha-framework/node_modules/mocha/lib/interfaces/common.js:148:19)
    at context.describe.context.context (/path/to/webdriverio/packages/wdio-mocha-framework/node_modules/mocha/lib/interfaces/bdd.js:42:27)
    at Object.<anonymous> (/path/to/webdriverio/examples/wdio/mocha/mocha.test.js:1:1
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Module.require (internal/modules/cjs/loader.js:692:17)
[0-0] FAILED in chrome - /mocha/mocha.test.js
that's it

 "spec" Reporter:
------------------------------------------------------------------
[chrome 85.0.4183.121 mac os x #0-0] Spec: /path/to/webdriverio/examples/wdio/mocha/mcha.test.js
[chrome 85.0.4183.121 mac os x #0-0] Running: chrome (v85.0.4183.121) on mac os x
[chrome 85.0.4183.121 mac os x #0-0] Session ID: 7aeb249aca663f4a1782fd64583ea56c
[chrome 85.0.4183.121 mac os x #0-0]
[chrome 85.0.4183.121 mac os x #0-0] webdriver.io page
[chrome 85.0.4183.121 mac os x #0-0]    - should be a pending test
[chrome 85.0.4183.121 mac os x #0-0]
[chrome 85.0.4183.121 mac os x #0-0] 1 skipped (243ms)


Spec Files:      0 passed, 1 failed, 1 total (100% completed) in 00:00:02

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

I am working on some tests for this.

Reviewers: @webdriverio/project-committers

@christian-bromann christian-bromann added the PR: Polish 💅 PRs that contain improvements on existing features label Oct 1, 2020
@christian-bromann christian-bromann merged commit 01a8fb6 into master Oct 1, 2020
@christian-bromann christian-bromann deleted the cb-spec-load-error branch October 1, 2020 11:52
@christian-bromann christian-bromann linked an issue Oct 1, 2020 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: Polish 💅 PRs that contain improvements on existing features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

mocha framework no longer loads dynamically-written tests
2 participants