valotas / karma-parcel

Karma with Parcel bundler
MIT License
6 stars 2 forks source link

Double import in the Entry.js #25

Closed adaliszk closed 1 year ago

adaliszk commented 3 years ago

I was trying out this plugin and it seems it could work, however, there is an issue I am facing where the generated entry.js file has the import for my file twice:

import "../tests/unit/custom-element.test.ts";
import "../tests/unit/custom-element.test.ts";

The configuration is fairly simple:

module.exports = (config) => {
    config.set(
        {
            frameworks: ["mocha", "chai", "parcel"],
            files: [
                "tests/**/*.test.ts",
                {
                    pattern: "tests/**/*.test.ts",
                    watched: false,
                    included: false
                }
            ],
            preprocessors: {
                "tests/**/*.ts": ["parcel"]
            },
            reporters: ["progress", "coverage"],
            browsers: ["ChromeHeadless"],
            concurrency: Infinity,
            singleRun: true,

            plugins: [
                "karma-chrome-launcher",
                "karma-coverage",
                "karma-mocha",
                "karma-chai",
                "karma-parcel",
            ],

            coverageReporter: {
                type: 'html',
                dir: `${__dirname}/tests/coverage/`
            },
        }
    )

    return config
}

The test itself:

import {expect} from 'chai'
import '../../source/custom-element'

describe('custom-element', () => {
    it('can be tested', () => {
        expect(true).to.equal(true)
    })
})

The issue with the double import that in this case the CustomElementRegistry will be called multiple times with the same element definitions and thus yield an Error.

In any way, I don't think it's actually intended to import the same file multiple times. I've had a quick look at the code, and from what I can tell, there is no check if a particular file was already added, so this could be a very simple fix.

valotas commented 1 year ago

Fixed with #47