|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +const co = require('co'); |
| 4 | +const expect = require('chai').expect; |
| 5 | +const MockUI = require('console-ui/mock'); |
| 6 | +const CoreObject = require('core-object'); |
| 7 | +const AddonMixin = require('../lib/ember-addon-main'); |
| 8 | +const BroccoliTestHelper = require('broccoli-test-helper'); |
| 9 | +const createBuilder = BroccoliTestHelper.createBuilder; |
| 10 | +const createTempDir = BroccoliTestHelper.createTempDir; |
| 11 | + |
| 12 | +let Addon = CoreObject.extend(AddonMixin); |
| 13 | + |
| 14 | +describe('ember-cli-htmlbars addon', function () { |
| 15 | + const ORIGINAL_EMBER_ENV = process.env.EMBER_ENV; |
| 16 | + |
| 17 | + beforeEach(function () { |
| 18 | + this.ui = new MockUI(); |
| 19 | + let project = { |
| 20 | + isEmberCLIProject: () => true, |
| 21 | + _addonsInitialized: true, |
| 22 | + root: __dirname, |
| 23 | + emberCLIVersion: () => '2.16.2', |
| 24 | + dependencies() { |
| 25 | + return {}; |
| 26 | + }, |
| 27 | + addons: [], |
| 28 | + targets: { |
| 29 | + browsers: ['ie 11'], |
| 30 | + }, |
| 31 | + }; |
| 32 | + |
| 33 | + this.addon = new Addon({ |
| 34 | + project, |
| 35 | + parent: project, |
| 36 | + ui: this.ui, |
| 37 | + }); |
| 38 | + |
| 39 | + project.addons.push(this.addon); |
| 40 | + }); |
| 41 | + |
| 42 | + afterEach(function () { |
| 43 | + if (ORIGINAL_EMBER_ENV === undefined) { |
| 44 | + delete process.env.EMBER_ENV; |
| 45 | + } else { |
| 46 | + process.env.EMBER_ENV = ORIGINAL_EMBER_ENV; |
| 47 | + } |
| 48 | + }); |
| 49 | + |
| 50 | + describe('transpileTree', function () { |
| 51 | + this.timeout(0); |
| 52 | + |
| 53 | + let input; |
| 54 | + let output; |
| 55 | + let subject; |
| 56 | + |
| 57 | + beforeEach( |
| 58 | + co.wrap(function* () { |
| 59 | + input = yield createTempDir(); |
| 60 | + }) |
| 61 | + ); |
| 62 | + |
| 63 | + afterEach( |
| 64 | + co.wrap(function* () { |
| 65 | + yield input.dispose(); |
| 66 | + yield output.dispose(); |
| 67 | + }) |
| 68 | + ); |
| 69 | + |
| 70 | + it( |
| 71 | + 'should build', |
| 72 | + co.wrap(function* () { |
| 73 | + input.write({ |
| 74 | + 'hello.hbs': `<div>Hello, World!</div>`, |
| 75 | + }); |
| 76 | + |
| 77 | + let htmlbarsOptions = { |
| 78 | + isHTMLBars: true, |
| 79 | + templateCompiler: require('ember-source/dist/ember-template-compiler.js'), |
| 80 | + }; |
| 81 | + |
| 82 | + subject = this.addon.transpileTree(input.path(), htmlbarsOptions); |
| 83 | + output = createBuilder(subject); |
| 84 | + |
| 85 | + yield output.build(); |
| 86 | + |
| 87 | + expect(output.read()).to.deep.equal({ |
| 88 | + 'hello.js': |
| 89 | + 'export default Ember.HTMLBars.template({"id":"QumOHSmG","block":"{\\"symbols\\":[],\\"statements\\":[[10,\\"div\\"],[12],[2,\\"Hello, World!\\"],[13]],\\"hasEval\\":false,\\"upvars\\":[]}","meta":{"moduleName":"hello.hbs"}});', |
| 90 | + }); |
| 91 | + }) |
| 92 | + ); |
| 93 | + }); |
| 94 | +}); |
0 commit comments