Bubbit / wct-istanbub

11 stars 5 forks source link

Import resolutions differ from polyserve #24

Closed nimatt closed 4 years ago

nimatt commented 5 years ago

When running test coverage on Polymer 3 components importing libraries from node_modules wct-istanbub behaves differently than polyserve which leads to some modules being loaded twice when some files are excluded from wct-istanbub (for example node_modules folder).

The problem is that isComponentRequest is always set to false in wct-istanbub but always true.

I would be happy to create a fix for this but I am not sure what is the correct behaviour as I've explaned in an issue in the polymer repo.

Any ideas on how to deal with this?

Bubbit commented 5 years ago

First of all sorry for the late reply.

Secondly I'm not sure what the current issue is.

istanbub behaves differently than polyserve which leads to some modules being loaded twice when some files are excluded from wct-istanbub (for example node_modules folder).

Can you create a example repo where this occurs? Does this influence the coverage metric or your test results in anyway? From my point of view it's a good thing that the files in the node_module folder are excluded as they are not part of my code, so I don't care about the coverage?

I might not grasp your complete issue, sorry if that's the case :)

veith commented 5 years ago

Same issue here. When you put all files under coverage, everything is fine. But when you exclude some files, like test helpers, you run into a problem.

The files which are excluded from coverage are importing like this:

import { PolymerElement, html } from "../../@polymer/polymer/polymer-element.js";

The files with coverage are importing like this:

import { PolymerElement, html } from "./node_modules/@polymer/polymer/polymer-element.js";

This causes following error: Error: Failed to execute 'define' on 'CustomElementRegistry': this name has already been used with this registry...

Workaround: Put all files under coverage or disable wct-istanbub :-(

Bubbit commented 5 years ago

I'm trying to figure out what the exact issue is, in order to do so I forked the PWA starter kit: https://github.com/Bubbit/pwa-starter-kit It currently runs fine with wct-istanbub: https://travis-ci.org/Bubbit/pwa-starter-kit/builds/490368152

If you have any pointers in order for me to replicate your issue feel free to comment and I can see what I can do.

nimatt commented 5 years ago

Sorry for taking so long to respond.

I've created a repo where the problem is shown when running polymer serve. It is a bit contrived example but I went for the minimal change to the basic Polymer 3 element. It seems to come when there are two things in the repo

  1. node_modulesis excluded from coverage
  2. A file that is used in the tests and is excluded (in the example istanbub-issue-demo_test.html) imports PolymerElement

The example is here

Bubbit commented 5 years ago

I've added a config option: isComponentRequestOverride: https://github.com/Bubbit/wct-istanbub/blob/master/README.md#iscomponentrequestoverride for the time being till I have time to find a proper fix, I've tested it with the example you linked me to always set it to true, works. Also tested with a bigger app at work (still Polymer 2), also no issues putting it on true.

Can you have a test run with 0.2.9 and see if you run into any issues?

The baseUrl is always empty in all the testing I've done, so not sure if it has ever said anything but false ^^

veith commented 5 years ago

It works fine with "isComponentRequestOverride": true

Thank you

nimatt commented 5 years ago

Setting iscomponentRequestOverride works fine for me too.

Thanks