Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

esbuild options are ignored #39

Open
steve-taylor opened this issue Aug 23, 2021 · 4 comments
Open

esbuild options are ignored #39

steve-taylor opened this issue Aug 23, 2021 · 4 comments

Comments

@steve-taylor
Copy link

Here's my config:

// karma.conf.js

module.exports = function (config) {
    config.set({
        frameworks: ['mocha', 'chai'],
        plugins: [
            'karma-esbuild',
            'karma-mocha',
            'karma-chai',
            'karma-chrome-launcher',
        ],
        files: ['packages/*/test/**/*.test.+(ts|tsx)'],
        preprocessors: {
            '**/*.+(ts|tsx)': 'esbuild',
        },
        reporters: ['progress'],
        port: 9876,
        colors: true,
        logLevel: config.LOG_INFO,
        browsers: ['Chrome'],
        autoWatch: false,
        singleRun: true,
        concurrency: Infinity,

        esbuild: {
            tsconfig: 'tsconfig.spec.json',
            inject: ['./karma-esbuild-react.js'],
        },
    })
}
// karma-esbuild-react.js

import React from 'react';

import React from 'react'; is not being injected at all. Also, changing tsconfig to anything else has no effect.

Uncaught ReferenceError: React is not defined
  at /path/to/MyComponent.tsx:22:11

The documentation says that this is how you pass options to esbuild, but it appears not to be the case.

@marvinhagemeister
Copy link
Owner

Just tried it out with the snippets you've provided and it works as expected on my end. All options are passed correctly to esbuild and it injects the file correctly. If an option cannot be resolved we forward all errors thrown by esbuild by default.

Please ensure that you're on a recent version of esbuild and karma-esbuild. If the error still occurs the command output might give further hints as to why those files cannot be found. Esbuild prints a big red error message at the beginning before karma logs to the console.

@steve-taylor
Copy link
Author

I don't suppose you have a working example of karma-esbuild with React, by any chance?

@RamiAlzayat
Copy link

Hey @steve-taylor ,
I'm facing the same issue, any updates/solutions?
Thanks.

@steve-taylor
Copy link
Author

@RamiAlzayat yes. My solution was to use Cypress component test runner instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants