Coder Social home page Coder Social logo

Comments (11)

thomassuckow avatar thomassuckow commented on August 22, 2024 1

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.

vojtajina avatar vojtajina commented on August 22, 2024

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.

AdamBrodzinski avatar AdamBrodzinski commented on August 22, 2024

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.

vojtajina avatar vojtajina commented on August 22, 2024

@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.

RyanSylvestre avatar RyanSylvestre commented on August 22, 2024

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.

givankin avatar givankin commented on August 22, 2024

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.

arnoudb avatar arnoudb commented on August 22, 2024

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.

stryju avatar stryju commented on August 22, 2024

@thomassuckow thanks! your workaround works like a charm!

from karma-requirejs.

saumitrabhave avatar saumitrabhave commented on August 22, 2024

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.

masterspambot avatar masterspambot commented on August 22, 2024

+1

from karma-requirejs.

dignifiedquire avatar dignifiedquire commented on August 22, 2024

Closing this issue, as it has nothing to do with karma-requirejs itself.

from karma-requirejs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.