-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Allow inserting source files in the HEAD / custom context.html #488
Comments
I was thinking about a more minimalistic approach; what about having something like this inside the config file: headFiles = [
'test/ieshiv.js',
'test/helpers/*.js'
]; this would let you include files into the IMHO, this would be simpler to use than the What do you think @vojtajina? |
I like the idea from @redaemn. We could use a simple templating language and allow multiple entry points into the files, e.g. |
Would love to see this feature |
@vojtajina While studying the code (it's huge, by the way...) I thought: are you sure that including the
Just don't want to implement something that will not solve my problem... :P |
After examining the code, I changed my mind: instead of creating a new The following code would include the files = [
{ pattern: 'test/ieshiv.js', included: 'head' }
];
|
@redaemn Can you try to hack the context.html to include your Now... two questions, would really appreciate feedback from everybody on this, because I don't know ;-)
Another option would be have a config option |
@vojtajina - I can't think of any other use-case apart from @(*&#^$@ IE8 but I think it would be still more flexible to allow people load they own files instead of just enumerating DOM elements to be created. I'm saying this since a project will probably alrready have some kind of If those elements are to be enumerated in Karma's config it would mean that the list of custom tags needs to be maintained in 2 places. Not a big deal but still... |
Not everyone follows the load scripts at body bottom paradigm, so having this flexibility is very useful. At work we tend to load vendor and core scripts at head and page specific scripts at body bottom. I would think a body top injection point instead would satisfy the ieshiv need as well as allowing any situation. |
@vojtajina Bad news: I edited the I'm beginning to think that maybe I'm doing something wrong, @pkozlowski-opensource could you please try to debug the tests and:
|
@redaemn are you saying that you put the That would mean, we are back on page one and I have no idea why it fails... |
@vojtajina yes... that's why I'm hoping that I did something wrong from the start and maybe the problem isn't there at all!! |
@redaemn I'm desperately trying to finish a book about AngularJS so don't have much cycles left till the end of this month but if you could create a clean repo with a minimal directive and minimal Karma config this would help a lot. Just to have a really minimal scenario. |
I'm gonna try the ng-directive-testing to get it running on IE8. On Sat, Apr 13, 2013 at 12:49 PM, Pawel Kozlowski
|
@pkozlowski-opensource that's exactly the same idea I had, we should start from a minimal example and try to understand what's going on. I created this repo https://github.com/redaemn/karma-test, directive and test are based on those in In Chrome the test is green, in #&(%$@ IE8 it fails on line https://github.com/redaemn/karma-test/blob/master/test.js#L16 with the exception "Unexpected call to method or access property" (a different line and different exception than the I also tried setting the I'm out of ideas!! |
Ok, I started my Windows VM. Disabled sound, so that I can't hear the Windows login sound which already makes me sick. Note, I only have IE9 in IE8 mode (but it looks like the issue is there as well). 1/ the 2/ the element, where you are adding the custom elements into, HAS TO BE already appended to the document. Here's the ng-directive-testing example working on IE8: |
Closing the issue, as I don't think we need this feature. |
Sound is always off on my Winzoz VM, I really hate that login sound!!! Anyway, I tried your solution and it worked like a charm!! :D Thank you very much @vojtajina |
@vojtajina Vojta, thnx so much for looking into it... After reading your comments it makes sense... in a wired IE logic... If I remember correctly attaching those DOM nodes to a document will slow down tests, right? As a browser will have to render them, calculate positioning etc. Or am I talking rubbish? |
@pkozlowski-opensource you are correct, it's better to append to DOM only when necesary. You can do if (IE) append... |
Hi, I'm coming from The good thing about all of this is that it gives power to users that need and won't complicate the life of people that don't need it. I would ask you to reconsider custom context.html and debug.html. Thanks. |
@guilhermeaiolfi I'm not against a configurable All the karma code is already encapsulate, so you only need a one line What exactly are you missing ? |
What I'm missing is how to tell karma where my custom context.html file is. Or do I have to edit this file in node_modules/karma/static? Because that's not a good idea since it's not going to be checkout with my project files and my changes can be lost when installing/updating karma in the future. |
@guilhermeaiolfi that's a valid point, we need to support that. You are correct, changing |
@vojtajina It would be nice to have the flexibility to have scripts in the head. I work with legacy systems that are mandated by asset load order, and it has proven troublesome to integrate karma with that structure. Also that would allow fixtures to be created in the head as well, another issue that I have come across. |
Bounty added here if anyone wants to add to it: https://www.catincan.com/bounty/allow-inserting-source-files-head-custom-context-html-issue-488-karma-runner-karma-github Crowdfund issue & get feature merged into main branch to collect. |
Is there any existing way to use a custom context.html? |
Similar to @franleplant and @guilhermeaiolfi, we have a single-page app that we'd like to run specs in the context of and it's too complicated to inject as a "fixture" (from what I know). So I would also like to be able to specify a custom context.html. It would be great it karma then injected what it needs into that page, rather than the other way around. |
Why do you need to run specs inside of the context of the app? sounds like you're wanting to run integration tests, and karma might not be the best matchup for that (keep in mind this opinion may be based on outdated knowledge of karma). Have you considered using selenium for that sort of thing? |
@caitp Yeah, I get that a lot :). Yes, we've considered selenium, and may end up going that route, but right now we have these (integration) specs written in client-side JS and thought karma could be the tool we use for launching in browserstack/saucelabs and aggregating results. But the specs all rely on running within the specific app page. @vojtajina, Is it out of the scope of karma to be a runner/aggregator for integration/functional tests (potentially using selenium, but not necessarily)? Is there another tool in that space? Here are two examples of what needs to be injected on a page to get mocha or jasmine2 to run specs on the page - in both cases, it isn't much, but running on the page is essential. |
I am running into an issue with this that is preventing the rest of my tests from running. I'm attempting to build a webapp with Polymer which some of it's polyfills require being placed in the HEAD of the document. WARN: 'platform.js is not the first script on the page. See http://www.polymer-project.org/docs/start/platform.html#setup for details.' {pattern: 'src/main/app/bower_components/**/*.{js,map}', included: false, served: true}, var script = document.createElement('script');
script.src = '/base/src/main/app/bower_components/platform/platform.js';
document.getElementsByTagName('head')[0].appendChild(script); I'd be fine with being able to use a custom context.html or allow the files attribute to allow placing the file in the HEAD. All the tutorials I've found around Karma and Polymer don't seem to solve this problem for me so if anyone has an idea for this to work I'd be interested to hear your thoughts. |
Would love to have this functionality. |
Added support to add custom context.html / debug.html - in "Support for custom context and/or debug html files" #1360 Unlike other pull request this one is little bit cleaner and doesn't break existing unit tests |
any update on when this change will be ready to use? I'd like to give this a try. I tried adding in the changes from the PR, but I'm running into problems; it seems like other places need to add in the extra parameter |
Sorry, my bad. To busy to finish the job. I will try to make appropriate pull request asap |
@AiBoy did you get a free moment to make that pull request? |
Another good point for custom context.html files is that ExtJs 6 for example wants I'm really looking forward to this being implemented. |
I believe there are many reasons why allowing custom HTML would be desirable. It gives other projects flexibility to do basically any kind of experimentation with Karma without having to fork the project. In our specific case, we use oojspec to run unit and integration tests with a single runner. Most integration test runners out there are pretty slow, like Capybara, Selenium or anything using a real browser, headless like phantomjs or not. OOJSpec doesn't enforce the way people should write code. If someone wants to be able to register events on DOM selectors which are never unregistered because it's not needed in the application, they shouldn't change the way they write their code just to satisfy their test runner limitations. So, one is free to register those events once in a For this to work, OOJSpec has to run each set of tests, grouped in an specification file, in a separate iframe. OOJSpec currently uses sprockets to create such structure in a similar way adopted by other gems like Konacha and others. It would be awesome to be able to use Karma infra-structure to run a custom HTML runner created to be compatible with Karma API so that it reports the tests run correctly to the client console. It should be doable once we have the ability to specify how the HTML should be written. My plan is to integrate OOJSpec to webpack and test with Karma and stop using sprockets. Another advantage of running the tests in separate iframes is that you are able to test whether all required dependencies were correctly declared since only the dependencies for that test file are loaded in the isolated iframe. |
Done in #1825 |
Based on #430
Let's allow custom
context.html
anddebug.html
.Add two config options:
The text was updated successfully, but these errors were encountered: