Skip to content
This repository has been archived by the owner on Dec 8, 2024. It is now read-only.

Commit

Permalink
Update test to not stub moduleName
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonmit committed May 11, 2016
1 parent 35e6f28 commit c0a65ea
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
3 changes: 3 additions & 0 deletions tests/fixtures/hello-world.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import hbs from 'htmlbars-inline-precompile';

export default hbs('hello');
33 changes: 16 additions & 17 deletions tests/tests.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var path = require('path');
var assert = require('assert');

var babel = require('babel-core');
var HTMLBarsInlinePrecompile = require('../index');

Expand Down Expand Up @@ -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) {
Expand All @@ -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');");
Expand Down

0 comments on commit c0a65ea

Please sign in to comment.