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

  • Home
  • SEARCH
  • 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 9094889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T23:27:39+00:00 2026-06-16T23:27:39+00:00

For a project that I am working on I have been using a hodgepodge

  • 0

For a project that I am working on I have been using a hodgepodge of JavaScript libraries. The main logic of my code is broken down into multiple commonjs modules. I use google closure to combine the modules into one output js file which I use within my AngularJS application.

The problem I am having is trying to perform tests with testacular. There error I receive is Uncaught ReferenceError: require is not defined. It is happening because, unlike google closure, testacular doesn’t understand commonjs modules. There are a couple work arounds I can do, but I was hoping to make it work without having to restructure my code.

  1. I can restucture the modules so that I’m no longer using commonjs. I don’t like this because it feels like a step backwards. I want my code to be modular.
  2. I can run testacular on the compiled js from google closure. I don’t mind doing it this way, but I have not been able to trigger everything to work on file changes. Testacular can re-run itself on file changes, but I haven’t seen anyway to make google closure re-compile on changes.
  3. Finally, I can enable commonjs module in testacular. Ideally this is the way I want to go, but it may not be the easiest.

Has anyone else run into a similar problem? I’m open for trying different things; I just don’t want anything hacky.

javaclassstreamreader.spec.js:

"use strict"

var JavaClassStreamReader = require('../javaclassstreamreader.js').JavaClassStreamReader;

describe('javaclassstreamreader', function() {

  it('reader can be constructed', function() {
    var dataView = {
      byteLength : 0
    };
    //FIXME load dataView

    var reader = new JavaClassStreamReader(dataView);
    expect(reader.dataView).toBe(dataView);
    expect(reader.offset).toBe(0);
    expect(reader.maxOffset).toBe(0);
  });

});

javaclassstreamreader.js:

function JavaClassStreamReader(dataView, initialOffset, maxBytesToRead) {
  this.dataView = dataView;
  this.offset = initialOffset || 0;
  this.maxOffset = this.offset + (maxBytesToRead || this.dataView.byteLength);
}
//... code trucated ...
  • 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-16T23:27:41+00:00Added an answer on June 16, 2026 at 11:27 pm

    I was not able to make it work with require, but I do have a partial solution.

    grunt.js:

    /*global module:false*/
    module.exports = function(grunt) {"use strict";
    
      // Project configuration.
      grunt.initConfig({
        pkg : '<json:package.json>',
        meta : {
          banner : '/*! <%= pkg.title || pkg.name %> - v<%= pkg.version %> - ' + '<%= grunt.template.today("yyyy-mm-dd") %>\n' + '<%= pkg.homepage ? "* " + pkg.homepage + "\n" : "" %>' + '* Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %>;' + ' Licensed <%= _.pluck(pkg.licenses, "type").join(", ") %> */'
        },
        lint : {
          files : ['grunt.js', 'src/*.js', 'src/public/js/**/*.js', 'src/specs/**/*.js']
        },
        watch : {
          files : '<config:lint.files>',
          tasks : 'default'
        },
        exec : {
          ensure_generated_directory : {
            command : 'mkdir -p generated/js/'
          }
        },
        clean : {
          all : ['generated']
        },
        jshint : {
          files : '<config:lint.files>',
          options : {
            curly : true,
            eqeqeq : true,
            forin : true,
            immed : true,
            latedef : true,
            newcap : true,
            noarg : true,
            sub : true,
            undef : true,
            unused : true,
            strict : true,
            boss : true,
            eqnull : true,
            es5 : true,
            browser : true,
            jquery : true,
            devel : true
          },
          globals : {
            //jasmine
            describe : false,
            it : false,
            expect : false,
            //commonjs
            require : false,
            exports : true,
            //angular
            angular : false
          }
        },
        'closure-compiler' : {
          frontend : {
            closurePath : 'closure-compiler',
            js : ['src/*.js', 'src/public/js/**/*.js'],
            jsOutputFile : 'generated/js/complete-app.js',
            options : {
              externs : 'externs.js',
              compilation_level : 'SIMPLE_OPTIMIZATIONS',
              language_in : 'ECMASCRIPT5_STRICT',
              logging_level : 'ALL',
              debug : null,
              warning_level : 'verbose',
              summary_detail_level : 3,
              formatting : ['PRETTY_PRINT', 'PRINT_INPUT_DELIMITER'],
              common_js_entry_module : 'src/public/js/app.js',
              process_common_js_modules : null,
              process_jquery_primitives : null,
              common_js_module_path_prefix : 'src'
            }
          }
        },
        testacularServer : {
          integration : {
            options : {
              keepalive : true
            },
            configFile : 'testacular.conf.js',
            autoWatch : false,
            singleRun : true
          }
        }
      }); 
    
      // Default task.
      grunt.registerTask('default', 'lint exec:ensure_generated_directory closure-compiler testacularServer:integration');
      grunt.loadNpmTasks('grunt-contrib-watch');
      grunt.loadNpmTasks('grunt-closure-compiler');
      grunt.loadNpmTasks('grunt-exec');
      grunt.loadNpmTasks('grunt-contrib-clean');
      grunt.loadNpmTasks('grunt-testacular');
    };
    

    I can run grunt watch and I get a similar result. grunt lints, then compiles, then runs testacular. This isn’t as fast as I was hoping. testacular starts and stops the server each time.

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

Sidebar

Related Questions

I have been working on a project that dynamically creates a javascript file using
I've been working on a project where I have been using LinqToSQL that involved
I am turning an project that I have been working on for while into
I have been using TDD to drive the project that I am currently working
Hey so I have been working on a project that I want to be
I have a django project that I have been working on as a solo
I have a console project that I have been working on. I added log4net
I have a project on github that I have been working on before. However,
I'm working on an iPad project that uses a third-party SDK, and have been
I have been working on a web project that stores locations for users. The

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.