|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +const fs = require('fs-extra'); |
| 4 | + |
| 5 | +const ember = require('ember-cli-blueprint-test-helpers/lib/helpers/ember'); |
| 6 | +const blueprintHelpers = require('ember-cli-blueprint-test-helpers/helpers'); |
| 7 | +const setupTestHooks = blueprintHelpers.setupTestHooks; |
| 8 | +const emberNew = blueprintHelpers.emberNew; |
| 9 | + |
| 10 | +const chai = require('ember-cli-blueprint-test-helpers/chai'); |
| 11 | +const expect = chai.expect; |
| 12 | +const file = chai.file; |
| 13 | + |
| 14 | +describe('Acceptance: ts:precompile command', function() { |
| 15 | + setupTestHooks(this); |
| 16 | + |
| 17 | + beforeEach(function() { |
| 18 | + return emberNew({ target: 'addon' }).then(() => ember(['generate', 'ember-cli-typescript'])); |
| 19 | + }); |
| 20 | + |
| 21 | + it('generates .js and .d.ts files from the addon tree', function() { |
| 22 | + fs.ensureDirSync('addon'); |
| 23 | + fs.writeFileSync('addon/test-file.ts', `export const testString: string = 'hello';`); |
| 24 | + |
| 25 | + return ember(['ts:precompile']) |
| 26 | + .then(() => { |
| 27 | + let declaration = file('test-file.d.ts'); |
| 28 | + expect(declaration).to.exist; |
| 29 | + expect(declaration.content.trim()).to.equal(`export declare const testString: string;`); |
| 30 | + |
| 31 | + let transpiled = file('addon/test-file.js'); |
| 32 | + expect(transpiled).to.exist; |
| 33 | + expect(transpiled.content.trim()).to.equal(`export const testString = 'hello';`); |
| 34 | + }); |
| 35 | + }); |
| 36 | + |
| 37 | + it('generates .js files only from the app tree', function() { |
| 38 | + fs.ensureDirSync('app'); |
| 39 | + fs.writeFileSync('app/test-file.ts', `export const testString: string = 'hello';`); |
| 40 | + |
| 41 | + return ember(['ts:precompile']).then(() => { |
| 42 | + let declaration = file('test-file.d.ts'); |
| 43 | + expect(declaration).not.to.exist; |
| 44 | + |
| 45 | + let transpiled = file('app/test-file.js'); |
| 46 | + expect(transpiled).to.exist; |
| 47 | + expect(transpiled.content.trim()).to.equal(`export const testString = 'hello';`); |
| 48 | + }); |
| 49 | + }); |
| 50 | +}); |
0 commit comments