From 7ea7c6f4ca890bd15b4abd1d5d8c664eab1028d7 Mon Sep 17 00:00:00 2001 From: Rich-Harris Date: Sat, 25 Mar 2017 21:46:33 -0400 Subject: [PATCH] reinstate test, resolve shared path. closes #19 --- index.js | 2 +- test/loader.spec.js | 25 ++++++++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 496e463b..a6bf985a 100644 --- a/index.js +++ b/index.js @@ -22,7 +22,7 @@ module.exports = function(source, map) { options.filename = this.resourcePath; options.format = this.version === 1 ? options.format || 'cjs' : 'es'; - options.shared = options.format === 'es'; + options.shared = options.format === 'es' && require.resolve( 'svelte/shared.js' ); if (!options.name) options.name = capitalize(sanitize(options.filename)); diff --git a/test/loader.spec.js b/test/loader.spec.js index b40fe7c2..1a288932 100644 --- a/test/loader.spec.js +++ b/test/loader.spec.js @@ -15,7 +15,7 @@ const loader = require('../'); describe('loader', function() { - function testLoader(fileName, callback, query) { + function testLoader(fileName, callback, query, version = 2) { return function() { @@ -29,6 +29,7 @@ describe('loader', function() { cacheable: cacheableSpy, callback: callbackSpy, resourcePath: fileName, + version, query, }, fileContents, null); @@ -164,6 +165,28 @@ describe('loader', function() { }); + describe('shared', function() { + + it('should configure shared=false (default)', + testLoader('test/fixtures/good.html', function(err, code, map) { + expect(err).not.to.exist; + + expect(code).not.to.contain('import {'); + expect(code).not.to.contain('svelte/shared.js'); + }, {}, 1) + ); + + + it('should configure shared=true', + testLoader('test/fixtures/good.html', function(err, code, map) { + expect(err).not.to.exist; + + expect(code).to.contain('import {'); + expect(code).to.contain('svelte/shared.js'); + }, { shared: true }) + ); + + }); describe('generate', function() {