From 28769f5a09759d77e5c2f4b6cd4d55b8f95b2e4a Mon Sep 17 00:00:00 2001 From: Jonny Gerig Meyer Date: Fri, 18 Sep 2015 17:02:53 -0400 Subject: [PATCH] Fix creating WebLoader without opts. --- src/web-loaders.js | 5 +++-- tests/loader.js | 17 +++++++++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/web-loaders.js b/src/web-loaders.js index 8c09e956..53af252f 100644 --- a/src/web-loaders.js +++ b/src/web-loaders.js @@ -6,19 +6,20 @@ var PrecompiledLoader = require('./precompiled-loader.js'); var WebLoader = Loader.extend({ init: function(baseURL, opts) { this.baseURL = baseURL || '.'; + opts = opts || {}; // By default, the cache is turned off because there's no way // to "watch" templates over HTTP, so they are re-downloaded // and compiled each time. (Remember, PRECOMPILE YOUR // TEMPLATES in production!) - this.useCache = opts.useCache; + this.useCache = !!opts.useCache; // We default `async` to false so that the simple synchronous // API can be used when you aren't doing anything async in // your templates (which is most of the time). This performs a // sync ajax request, but that's ok because it should *only* // happen in development. PRECOMPILE YOUR TEMPLATES. - this.async = opts.async; + this.async = !!opts.async; }, resolve: function(from, to) { // jshint ignore:line diff --git a/tests/loader.js b/tests/loader.js index ea2ac546..e492f268 100644 --- a/tests/loader.js +++ b/tests/loader.js @@ -1,21 +1,34 @@ (function() { 'use strict'; - var expect, Environment, Loader, templatesPath; + var expect, Environment, WebLoader, FileSystemLoader, templatesPath; if(typeof require !== 'undefined') { expect = require('expect.js'); Environment = require('../src/environment').Environment; + WebLoader = require('../src/web-loaders').WebLoader; + FileSystemLoader = require('../src/node-loaders').FileSystemLoader; templatesPath = 'tests/templates'; } else { expect = window.expect; Environment = nunjucks.Environment; - Loader = nunjucks.WebLoader; + WebLoader = nunjucks.WebLoader; + FileSystemLoader = nunjucks.FileSystemLoader; templatesPath = '../templates'; } describe('loader', function() { + it('should have default opts', function() { + var webLoader = new WebLoader(templatesPath); + var fileSystemLoader = new FileSystemLoader(templatesPath); + expect(webLoader).to.be.a(WebLoader); + expect(webLoader.useCache).to.be(false); + expect(webLoader.async).to.be(false); + expect(fileSystemLoader).to.be.a(FileSystemLoader); + expect(fileSystemLoader.noCache).to.be(false); + }); + it('should allow a simple loader to be created', function() { // From Docs: http://mozilla.github.io/nunjucks/api.html#writing-a-loader // We should be able to create a loader that only exposes getSource