From c0a65ea019d7efc0e97d2fb46385fb88020613e3 Mon Sep 17 00:00:00 2001 From: Jason Mitchell Date: Tue, 10 May 2016 22:55:23 -0700 Subject: [PATCH] Update test to not stub moduleName --- tests/fixtures/hello-world.js | 3 +++ tests/tests.js | 33 ++++++++++++++++----------------- 2 files changed, 19 insertions(+), 17 deletions(-) create mode 100644 tests/fixtures/hello-world.js diff --git a/tests/fixtures/hello-world.js b/tests/fixtures/hello-world.js new file mode 100644 index 00000000..05046b4f --- /dev/null +++ b/tests/fixtures/hello-world.js @@ -0,0 +1,3 @@ +import hbs from 'htmlbars-inline-precompile'; + +export default hbs('hello'); diff --git a/tests/tests.js b/tests/tests.js index 3e1bda2e..6545e234 100644 --- a/tests/tests.js +++ b/tests/tests.js @@ -1,5 +1,5 @@ +var path = require('path'); var assert = require('assert'); - var babel = require('babel-core'); var HTMLBarsInlinePrecompile = require('../index'); @@ -59,6 +59,21 @@ describe("htmlbars-inline-precompile", function() { }, /placeholders inside a tagged template string are not supported/); }); + it("moduleName is supplies to the precompiler", function() { + var fullpath = path.join(__dirname, 'fixtures', 'hello-world.js'); + + var precompile = function(template, options) { + assert.equal(options.moduleName, fullpath); + + return "precompiled(" + template + ")"; + }; + + babel.transformFileSync(fullpath, { + blacklist: ['strict', 'es6.modules'], + plugins: [HTMLBarsInlinePrecompile(precompile)] + }); + }); + describe('single string argument', function() { it("works with a plain string as parameter hbs('string')", function() { var transformed = transform("import hbs from 'htmlbars-inline-precompile'; var compiled = hbs('hello');", function(template) { @@ -68,22 +83,6 @@ describe("htmlbars-inline-precompile", function() { assert.equal(transformed, "var compiled = Ember.HTMLBars.template(precompiled(hello));", "tagged template is replaced"); }); - it("moduleName (filenameRelative) is passed through to precompiler", function() { - var code = "import hbs from 'htmlbars-inline-precompile'; var compiled = hbs('hello');"; - - var precompile = function(template, options) { - assert.equal(options.moduleName, 'module-name-test.js'); - - return "precompiled(" + template + ")"; - }; - - babel.transform(code, { - blacklist: ['strict', 'es6.modules'], - plugins: [HTMLBarsInlinePrecompile(precompile)], - filenameRelative: 'module-name-test.js' - }); - }); - it("warns when more than one argument is passed", function() { assert.throws(function() { transform("import hbs from 'htmlbars-inline-precompile'; var compiled = hbs('first', 'second');");