webdriverio / visual-testing

Image comparison / visual regression testing for WebdriverIO
https://webdriver.io/docs/visual-testing
MIT License
110 stars 41 forks source link

Cannot find name 'expect' in typescript #68

Closed Searcher865 closed 2 years ago

Searcher865 commented 3 years ago

Environment (please complete the following information):

Describe the bug Cannot find name 'expect'

To Reproduce tsconfig: Add "wdio-image-comparison-service" for "types" run npm test

[Include code or an example repository that can easily be set up]

Expected behavior Clear compilation

Log

Execution of 1 workers started at 2021-07-01T15:18:51.989Z

2021-07-01T15:18:52.133Z INFO @wdio/cli:launcher: Run onPrepare hook
2021-07-01T15:18:52.134Z INFO chromedriver: Start Chromedriver (C:\GitHub\wdio\node_modules\chromedriver\lib\chromedriver\chromedriver.exe) with 
args --port=9515 --url-base=/
2021-07-01T15:18:52.159Z INFO chromedriver: Starting ChromeDriver 91.0.4472.101 (af52a90bf87030dd1523486a1cd3ae25c5d76c9b-refs/branch-heads/4472@{#1462}) on port 9515
2021-07-01T15:18:52.159Z INFO chromedriver: Only local connections are allowed.
2021-07-01T15:18:52.160Z INFO chromedriver: Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
2021-07-01T15:18:52.164Z INFO chromedriver: ChromeDriver was started successfully.
2021-07-01T15:18:52.265Z INFO @wdio/cli:launcher: Run onWorkerStart hook
2021-07-01T15:18:52.270Z INFO @wdio/local-runner: Start worker 0-0 with arg: run,./wdio.conf.js
[0-0] 2021-07-01T15:18:53.069Z INFO @wdio/local-runner: Run worker command: run
[0-0] 2021-07-01T15:18:55.960Z WARN @wdio/mocha-framework: Unable to load spec files quite likely because they rely on `browser` object that is not fully initialised.
[0-0] `browser` object has only `capabilities` and some flags like `isMobile`.
[0-0] Helper files that use other `browser` commands have to be moved to `before` hook.
[0-0] Spec file(s): C:\GitHub\wdio\test\specs\example.ts
[0-0] Error: TSError: ⨯ Unable to compile TypeScript:
[0-0] test/specs/example.ts(12,15): error TS2304: Cannot find name 'expect'.
[0-0]
[0-0]     at createTSError (C:\GitHub\wdio\node_modules\ts-node\src\index.ts:587:12)
[0-0]     at reportTSError (C:\GitHub\wdio\node_modules\ts-node\src\index.ts:591:19)
[0-0]     at getOutput (C:\GitHub\wdio\node_modules\ts-node\src\index.ts:921:36)
[0-0]     at Object.compile (C:\GitHub\wdio\node_modules\ts-node\src\index.ts:1189:32)
[0-0]     at Module.m._compile (C:\GitHub\wdio\node_modules\ts-node\src\index.ts:1295:42)
[0-0]     at Module.m._compile (C:\GitHub\wdio\node_modules\ts-node\src\index.ts:1295:23)
[0-0]     at Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
[0-0]     at require.extensions.<computed> (C:\GitHub\wdio\node_modules\ts-node\src\index.ts:1298:12)
[0-0]     at Object.require.extensions.<computed> [as .ts] (C:\GitHub\wdio\node_modules\ts-node\src\index.ts:1298:12)
[0-0]     at Module.load (internal/modules/cjs/loader.js:928:32)
[0-0] RUNNING in chrome - C:\GitHub\wdio\test\specs\example.ts
[0-0] 2021-07-01T15:18:56.085Z INFO webdriver: Initiate new session using the WebDriver protocol
[0-0] 2021-07-01T15:18:56.086Z INFO webdriver: [POST] http://localhost:9515/session
[0-0] 2021-07-01T15:18:56.086Z INFO webdriver: DATA {
[0-0]   capabilities: {
[0-0]     alwaysMatch: { browserName: 'chrome', acceptInsecureCerts: true },
[0-0]     firstMatch: [ {} ]
[0-0]   },
[0-0]   desiredCapabilities: { browserName: 'chrome', acceptInsecureCerts: true }
[0-0] }

DevTools listening on ws://127.0.0.1:54207/devtools/browser/84f39e7f-7451-49a4-b524-42c9dfe923a4
[27008:31760:0701/231856.520:ERROR:device_event_log_impl.cc(214)] [23:18:56.519] Bluetooth: bluetooth_adapter_winrt.cc:1072 Getting Default Adapter failed.
[0-0] 2021-07-01T15:18:56.732Z INFO wdio-image-comparison-service: Adding commands to global browser
[0-0] 2021-07-01T15:18:56.736Z ERROR @wdio/runner: Error: Unable to load spec files quite likely because they rely on `browser` object that is not fully initialised.
[0-0] `browser` object has only `capabilities` and some flags like `isMobile`.
[0-0] Helper files that use other `browser` commands have to be moved to `before` hook.
[0-0] Spec file(s): C:\GitHub\wdio\test\specs\example.ts
[0-0] Error: TSError: ⨯ Unable to compile TypeScript:
[0-0] test/specs/example.ts(12,15): error TS2304: Cannot find name 'expect'.
[0-0]
[0-0]     at createTSError (C:\GitHub\wdio\node_modules\ts-node\src\index.ts:587:12)
[0-0]     at reportTSError (C:\GitHub\wdio\node_modules\ts-node\src\index.ts:591:19)
[0-0]     at getOutput (C:\GitHub\wdio\node_modules\ts-node\src\index.ts:921:36)
[0-0]     at Object.compile (C:\GitHub\wdio\node_modules\ts-node\src\index.ts:1189:32)
[0-0]     at Module.m._compile (C:\GitHub\wdio\node_modules\ts-node\src\index.ts:1295:42)
[0-0]     at Module.m._compile (C:\GitHub\wdio\node_modules\ts-node\src\index.ts:1295:23)
[0-0]     at Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
[0-0]     at require.extensions.<computed> (C:\GitHub\wdio\node_modules\ts-node\src\index.ts:1298:12)
[0-0]     at Object.require.extensions.<computed> [as .ts] (C:\GitHub\wdio\node_modules\ts-node\src\index.ts:1298:12)
[0-0]     at Module.load (internal/modules/cjs/loader.js:928:32)
[0-0]     at MochaAdapter._loadFiles (C:\GitHub\wdio\node_modules\@wdio\mocha-framework\build\index.js:85:35)
[0-0]     at processTicksAndRejections (internal/process/task_queues.js:93:5)
[0-0]     at MochaAdapter.init (C:\GitHub\wdio\node_modules\@wdio\mocha-framework\build\index.js:54:9)
[0-0]     at Object.adapterFactory.init (C:\GitHub\wdio\node_modules\@wdio\mocha-framework\build\index.js:305:22)
[0-0]     at Runner.run (C:\GitHub\wdio\node_modules\@wdio\runner\build\index.js:82:27)
[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): C:\GitHub\wdio\test\specs\example.ts
Error: TSError: ⨯ Unable to compile TypeScript:
test/specs/example.ts(12,15): error TS2304: Cannot find name 'expect'.

    at createTSError (C:\GitHub\wdio\node_modules\ts-node\src\index.ts:587:12)
    at reportTSError (C:\GitHub\wdio\node_modules\ts-node\src\index.ts:591:19)
    at getOutput (C:\GitHub\wdio\node_modules\ts-node\src\index.ts:921:36)
    at Object.compile (C:\GitHub\wdio\node_modules\ts-node\src\index.ts:1189:32)
    at Module.m._compile (C:\GitHub\wdio\node_modules\ts-node\src\index.ts:1295:42)
    at Module.m._compile (C:\GitHub\wdio\node_modules\ts-node\src\index.ts:1295:23)
    at Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at require.extensions.<computed> (C:\GitHub\wdio\node_modules\ts-node\src\index.ts:1298:12)
    at Object.require.extensions.<computed> [as .ts] (C:\GitHub\wdio\node_modules\ts-node\src\index.ts:1298:12)
    at Module.load (internal/modules/cjs/loader.js:928:32)
[0-0] 2021-07-01T15:18:56.738Z INFO webdriver: COMMAND deleteSession()
[0-0] 2021-07-01T15:18:56.738Z INFO webdriver: [DELETE] http://localhost:9515/session/f88bd0d08e0134347c82e7e36d272686
[0-0] FAILED in chrome - C:\GitHub\wdio\test\specs\example.ts
2021-07-01T15:18:56.912Z INFO @wdio/cli:launcher: Run onComplete hook

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

2021-07-01T15:18:56.913Z INFO @wdio/local-runner: Shutting down spawned worker
2021-07-01T15:18:57.168Z INFO @wdio/local-runner: Waiting for 0 to shut down gracefully
2021-07-01T15:18:57.169Z INFO @wdio/local-runner: shutting down
npm ERR! Test failed.  See above for more details.

example.ts

describe('Example', () => {
    it('should save some screenshots', async () => {
     await expect(browser.checkScreen('examplePaged', { /* some options */ })).toEqual(0);
    });
  });

tsconfig.json

{
    "compilerOptions": {
        "outDir": "./build",
        "allowJs": true,
        "inlineSourceMap": true,
        "types": [
            "node",
            "webdriverio/async",
            "@wdio/mocha-framework",
            "wdio-image-comparison-service"
        ],
        "module": "commonjs",
        "target": "ES6"
    }
}
fabianschmider123 commented 3 years ago

Hi @Searcher865, do you still need help?

If you use async mode you have to give an await to the browser object.

Try: await expect(await browser.checkScreen('examplePaged', { / some options / })).toEqual(0);

Does this help? BR Fabian Schmider

Searcher865 commented 2 years ago

@opensourcesensor yes. Thank you.