Skip to content

Using inject in importMapsPlugin won't let exclude **/*.test.js files #2890

Open
@Totati

Description

@Totati

Our setup web-test-runner.config.js

const { playwrightLauncher } = require('@web/test-runner-playwright');
const { esbuildPlugin } = require('@web/dev-server-esbuild');
const resolve = require('path').resolve;
const importMapsPlugin = require('@web/dev-server-import-maps').importMapsPlugin;

module.exports = {
  ootDir: '.',
  files: ['./**/*.test.ts'],
  nodeResolve: { exportConditions: 'production' },
    browsers: [
    playwrightLauncher({
      product: 'chromium'
    })
  ],
  preserveSymlinks: true,
  plugins: [
    esbuildPlugin({
      ts: true,
      target: 'auto',
      tsconfig: resolve(__dirname, 'tsconfig.spec.json')
    }),
    importMapsPlugin({
      inject: [
        {
          importMap: {
            imports: {
              dayjs: '/node_modules/dayjs/esm/index.js',
              '/src/controllers/attribute-reflector.controller':
                '/src/controllers/__mocks__/attribute-reflector.controller.ts'
            }
          }
        }
      ]
    })
  ],
  testRunnerHtml: testFramework => `
    <html>
      <head>
        <script type="module" src="${testFramework}"></script>
        <script type="module">import 'jest-browser-globals';</script>
      </head>
    </html>
  `
};

We develop Lit web-components and every component has a component.test.ts file next to it. I created a controller and I can't create a config that lets me use the real controller in the attribute-reflector.controller.test.ts file and the mock in the rest. I don't want to test the controller in the component test, I just want to check if the components initialise it with the correct options, and calls the targetChange method when the slotted element changes.

I've tried adding another config in the inject array, defining the include the exclude filters, scoping, I've tried groups and overriding the plugins, but include, exclude and scoping works only on html files which we don't have, and the groups inherits the default plugins config.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions