Comments (11)
You are absolutely correct that this is behaviour from requirejs.
What happens is that the spec files are loaded with an absolute url and the generated "relative" url becomes absolute when normalized. Therefore the decision of whether to add a .js extension becomes false and the world ends.
I now mangle the files list to be relative to get around this in my script to load tests.
https://gist.github.com/thomassuckow/6372324
Reading up on the requirejs issues, this is not a "bug" persay. Basically you should never do a require call with an absolute or url path. If you must, you should make a paths entry with the absolute path or url and then everything should work (though I have not tried).
from karma-requirejs.
I though, that was how Require.js worked, no ?
- You can either ask for stuff like "app" or "some/app" (all these are relative to your
baseUrl
) and Require.js will take care of adding.js
. - Or you can ask for stuff relative to current file like "./app.js" or "../some/app.js" in which case you Require.js won't take care of
.js
.
I however don't use Require.js that much, so I might be wrong. Are you seing this behavior only when using Require.js with Karma ? Because really, the only thing Karma does - it forces you to use baseUrl
.
from karma-requirejs.
Hi Vojta,
The current version of RequireJS will let you require relative to the current file without an extension and it will still append the js, however i'm not terribly familiar with RJS myself. Currently i'm only experiencing this error when running it through Karma, as the code will work when using main.js and the normal require.js.
Below is a test sample that errors out on karma start
but runs in the browser if you cd source
and start a simple server, sum will log Sum is: 4
https://github.com/AdamBrodzinski/karma-test-sample
if line 1 of widget.js is changed to "./sum.js"
karma will function and pass all tests.
On a personal level I don't mind too much if I have to manually append .js
, however some people might get tripped up trying to test their code if they're app has ../foo
requires in it, so I thought I would at least mention it.
I looked through the RequireJS monkey patch and I can't find exactly what would be causing this, but i'll keep looking into it. It seems like it's looking for /base/...../widget
but it doesn't exist in __karma__.files
, only /base/...../widget.js
does, so it 404's and logs: There is no timestamp for /base/components/widget/sum!
.
from karma-requirejs.
@AdamBrodzinski thanks for digging into this! I'm all for fixing this issue, but I think it's a problem of RequireJS.
Try, in your example, adding into scripts/main.js
something like this:
define(['appSpec'], function() {
console.log('LOADED')
});
And try to open index.html
in the browser, without Karma. You will get 404, RequireJS won't resolve the path of app.js
correctly. I think it's because the spec is outside the baseUrl...
from karma-requirejs.
I am having this issue as well trying to use paths relative to the current directory, the stopgap that @thomassuckow provided with a few tweaks works for me. Although there must be a better way of dealing with this.
from karma-requirejs.
Well yes, workaround can work but it's pretty ugly :)
Treating ".js" files as absolute paths is an old and well known behavior of RequireJS (http://requirejs.org/docs/api.html#jsfiles), so I think this should be fixed on karma's side.
from karma-requirejs.
I think too this should be fixed at the karma side. Hope somebody with the knowledge to do so will make it happen. thnx
from karma-requirejs.
@thomassuckow thanks! your workaround works like a charm!
from karma-requirejs.
Thanks @thomassuckow .. You workaround is the way to go. In fact i dont know whats the workaround in this? Felt like a clean solution. Its just another way of filtering files.
from karma-requirejs.
+1
from karma-requirejs.
Closing this issue, as it has nothing to do with karma-requirejs itself.
from karma-requirejs.
Related Issues (20)
- Uncaught Error: Mismatched anonymous define()
- Unable to install karma-requirejs HOT 1
- Uncaught Error: Module name "http-errors"
- Repeated " Some of your tests did a full page reload!" error HOT 2
- Provide a mechnism to disable the caching
- vague require.js + karma errors HOT 2
- Require.js does not prepend baseUrl to dependencies HOT 2
- nodejs require
- native require() seems to completely overridden HOT 2
- Is the project abandoned? HOT 3
- Automatically append ".js" when normalizing filename HOT 3
- Error: Mismatched anonymous define() module
- change the default test-main to strip the base and .js extensions so that sub dependencies load HOT 4
- Dynamic requirejs file from remote machine
- There is no timestamp error when using CommonJS syntax HOT 1
- Add support for RequireJS 2.2.x HOT 4
- Link down
- Mocha v3 triggers "mismatched anonymous define" error HOT 3
- pleaser release v1.0.1 HOT 1
- Installation fails with NPM 3 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from karma-requirejs.