web icon indicating copy to clipboard operation
web copied to clipboard

HTML test importmaps doesn't work with esbuild + typescript?

Open enjikaka opened this issue 4 years ago • 1 comments

Trying to mock es modules in a test by using a HTML-test with importmaps.

<script type="importmap">
      {
        "imports": {
          "../../../src/player/index.ts": "./player.mock.ts"
        }
      }
</script>
<script type="module" src="player.test.ts"></script>

It fails to include the mock, and includes the original file instead. However, when logging import.meta.url in the original file I see that ?wds-import-map=0 has been appended to the import. I suppose this tells the dev-server to include the mock but for some unknown reason it fails to do so?

Active plugins:

plugins: [
    commonjs({
      transformMixedEsModules: true,
      include: [
        'node_modules/shaka-player/dist/shaka-player.compiled.js'
      ],
    }),
    esbuildPlugin({ ts: true }),
    importMapsPlugin()
  ]

enjikaka avatar Dec 23 '21 10:12 enjikaka

I see same problem. If I add ?wds-import-map=0 to the import map url manually, it works. Like:


  plugins: [
    litCss({
      include: ['src/components/**/*.css'],
    }),

    esbuildPlugin({ ts: true, target: 'esnext' }),

    importMapsPlugin({
      inject: {
        importMap: {
          imports: {
            '/src/components/icon/bl-icon.ts?wds-import-map=0': '/src/utilities/bl-icon.mock.ts',
          },
        },
      },
    }),
  ],

But I think we should not add this parameter manually.

muratcorlu avatar Jul 14 '22 13:07 muratcorlu