Sha256: 7bfa214f537ac7a66e36ff4f38c7be53dce506768625b07024dc6ab919bcc009

Contents?: true

Size: 1.71 KB

Versions: 10

Compression:

Stored size: 1.71 KB

Contents

// ==========================================================================
// Project:   Spade - CommonJS Runtime
// Copyright: ©2010 Strobe Inc. All rights reserved.
// License:   Licened under MIT license (see __preamble__.js)
// ==========================================================================

var Ct = require('core-test/sync'),
    Spade = require('spade').Spade;

// ..........................................................
// BASIC REQUIRE
// 

Ct.module('spade: basic require');

Ct.setup(function(t) {
  t.spade = new Spade(); 
    
  // preload a module
  t.spade.register('foo/main', function(r, e) { e.id = 'foo'; });
  
  // dummy loader loads only foo/bar on demand
  t.spade.loader = {
    
    requests: 0, 
    
    loadFactory: function(spade, id, formats, done) {
      this.requests++;
      if (id === 'foo/bar') {
        spade.register(id, function(r,e) { e.id='foo/bar'; });
      }
      if (done) throw "should not be passed done"
    }
  };
  
});

Ct.teardown(function(t) { 
  delete t.spade;
});

Ct.test('should not talk to loader if module is registered', function(t) {
  var spade = t.spade;
  t.equal(spade.require('foo').id, 'foo', 'should find foo');
  t.equal(spade.loader.requests, 0, 'loader should not have been called');
});

Ct.test('should let loader register', function(t) {
  var spade = t.spade;
  t.equal(spade.require('foo/bar').id, 'foo/bar', 'should find foo');
  t.equal(spade.loader.requests, 1, 'loader should have been called');
});

Ct.test('should throw if loader does not register', function(t) {
  var spade = t.spade;
  t.throws(function() {
    spade.require('imaginary/bar');
  });
  t.equal(spade.loader.requests, 1, 'loader should have been called');
});



Ct.run();

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
spade-0.1.1.1 lib/spade/package/spec/javascript/loader-test.js
spade-runtime-0.1.0.1 spec/javascript/loader-test.js
spade-0.0.8.1 spec/javascript/loader-test.js
spade-0.0.7 spec/javascript/loader-test.js
spade-0.0.6 spec/javascript/loader-test.js
spade-0.0.5 spec/javascript/loader-test.js
spade-0.0.4 spec/javascript/loader-test.js
spade-0.0.3 spec/javascript/loader-test.js
spade-0.0.2 spec/javascript/loader-test.js
spade-0.0.1 spec/javascript/loader-test.js