Skip to content

Bug: screenshotPath/baselineFolder don't work as expected/intended. #733

@htho

Description

@htho

Environment (please complete the following information):

  • Node.js version: v20.15.1
  • NPM version: 10.8.2
  • Browser name and version: Chrome 131
  • Platform name and version: Windows 10
  • WebdriverIO version: 9.5.7
  • @wdio/visual-service version: 6.3.0

Config of WebdriverIO + @wdio/visual-service

I created a repository where I tried to reproduce the problems I found, when setting up visual testing: https://github.com/htho/wdio-repro-visual-service

https://github.com/htho/wdio-repro-visual-service/blob/main/wdio-baselineFolder.conf.ts

	services: [
        [
            "visual",
            {
                // TODO: REPORT options is `this` object - it is useless
                baselineFolder: (options) => {
                    // TS ERROR Property 'specs' does not exist on type 'ClassOptions'
                    // RUNTIME ERROR: Error: Error: Failed to initialise launcher service "visual": TypeError: Cannot read properties of undefined (reading '0')
                    // TODO: REPORT
                    const testFolder = path.dirname(options.specs[0]);
                    // TODO: REPORT what is `type` supposed to be?
                    return path.join(testFolder, "snapshots", type);
                },
            } satisfies VisualServiceOptions,
        ],
    ],

https://github.com/htho/wdio-repro-visual-service/blob/main/wdio-screenshotPath.conf.ts

	services: [
        [
            "visual",
            {
                // TODO: REPORT options is `this` object - it is useless
                screenshotPath(options) {
                    // TODO: REPORT the example makes no sense:
                    // https://webdriver.io/docs/visual-testing/service-options#screenshotpath

                    // TS ERROR Property 'specs' does not exist on type 'ClassOptions'
                    // RUNTIME ERROR: Error: Error: Failed to initialise launcher service "visual": TypeError: Cannot read properties of undefined (reading '0')
                    // TODO: REPORT
                    const testFolder = path.dirname(options.specs[0]);
                    // TODO: REPORT what is `type` supposed to be?
                    return path.join(testFolder, "snapshots", type);
                },
            } satisfies VisualServiceOptions,
        ],
    ],

Describe the bug

I think all the issues I are related.

The documentation/APIs for screenshotPath and baselineFolder are very similar.

  1. Both documentations say that one could access options.specs within the function, but TypeScript and the Runtime indicate Errors.
  2. In fact the options parameter is the VisualServiceOptions object itself. This makes it useless.
  3. The examples are confusing and even syntactically wrong.

To Reproduce

Use the repository and run npm run test:screenshotPath and npm run test:baselineFolder.

Expected behavior

  1. The documentation should be syntactically correct.
  2. The object passed into the functions should at least contain the information available for formatImageName.

Log

Relevant logs included as comments in the code above.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions