How to map imports for testing in webdriverio

39 Views Asked by At

Using webdriverio and vite (ES6/typescript), is there any way to map imports, so that (for tests only), importing a given path will result in importing a different path (containing a mocked version of the import)?

I'm porting a project that was previously using Modern Web and the file web-test-runner.config.js contained such maps:

export default {
  testFramework: {
    config: {
      timeout: '3000'
    }
  },
  plugins: [
    vitePlugin(),
    importMapsPlugin({
      inject: {
        importMap: {
          imports: {
            // this path needs to be absolute url whatever browser trys to load. cannot be relative path. prod file path: mocked file path
            'http://localhost:9000/src/features/sequencer/hooks/useSequencerService.ts':
              'http://localhost:9000/test/mocks/useSequencerService.ts',
          }
        }
      }
    })
  ],

I suppose if this feature is not available for webdriverio, I would have to use a mocking API instead.

0

There are 0 best solutions below