Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8604307
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:32:24+00:00 2026-06-12T02:32:24+00:00

I have a project with which I have just recently introduced RequireJS. Before RequireJS,

  • 0

I have a project with which I have just recently introduced RequireJS. Before RequireJS, I had been testing my project with Jasmine. I am now trying to update Jasmine’s SpecRunner so that it can handle RequireJS.

I found this article on unit testing with RequireJS and Jasmine which I have used to get me started. I’ve hit a snag with how I am loading modules. Each modules defines other modules it has a dependency on, but each module’s load path is relative to the location where requireJS was loaded.

I load requireJS in two different locations: background.html and SpecRunner.html. Background is for the main application and SpecRunner is for testing. The problem is that my modules fail to load when called from SpecRunner because their relative paths change.

Example:

  • js/third_party/jquery-1.7.2.min.js
  • js/background/player.js
  • js/background/playlists.js
  • tests/SpecRunner.html
  • tests/spec/PlayerSpec.js
  • background.html

With this folder hierarchy and files I have two scenarios. One in which the code runs properly and one in which there is an issue:

Good Scenario

  • background.html loads require.js and executes targeting player.js as the loading point.
  • player.js defines playlists.js as a dependency.
  • playlists.js is loaded.
  • player.js is loaded.

Bad Scenario

  • SpecRunner.html loads require.js and executes targeting player.js as the loading point.
  • player.js defines playlists.js as a dependency.
  • playlists.js fails to load. GET file://tests/playlists.js
    • The file location is incorrect. playlists.js is not under /tests, it is under js/background!

I’m not sure how I should handle this? It seems like being extremely explicit with path names is my only way out, but that goes against all of the requireJS examples.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T02:32:26+00:00Added an answer on June 12, 2026 at 2:32 am

    Paths in require are relative to the data-main location or relative to the location of the function that called require(). In your good scenario this is js/background/, and in your bad scenario this is tests/. In the blog you linked they use require.paths to make this work properly:

    <!--
        Since we are in the "test" directory, not in the standard
        "js" directory, we need to define the path prefix' for the
        RequireJS modules so that the modules can be found from the
        tests running in the Spec directory.
    -->
    <script type="text/javascript">
    
        var require = {
            paths: {
                "domReady": "../js/lib/require/domReady",
                "model": "../js/model"
            }
        };
    
    </script>
    

    In your case, you’ll have to set up paths like

    'player':    '../js/background/player.js',
    'playlists': '../js/background/playlists.js'
    

    and explicitly require player and your spec in your test runner as they do in the blog post.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just recently got involved in a classic ASP.NET project which contains lots
I have a project using DevExpress 8.3 (2008.3) which I just recently upgraded to
I have recently being trying to create a project which has several levels of
I have just recently discovered Project Sumatra , which aims to bring the JVM
I have been using TortoiseSVN for a while now and just recently started using
I have a WPF project which compiles just fine. However, when I enable code
I have just begun working on a project which uses Mercurial as a version
I have just restarted a project in which I am using NHibernate. The project
I recently tried to compile an older Xcode project (which used to compile just
recently I've been given a project which need to display a spherical panorama view.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.