@@ -7,13 +7,17 @@ const CoreObject = require('core-object');
77const AddonMixin = require ( '../index' ) ;
88const path = require ( 'path' ) ;
99const resolve = require ( 'resolve' ) ;
10+ const CommonTags = require ( 'common-tags' ) ;
11+ const stripIndent = CommonTags . stripIndent ;
1012const BroccoliTestHelper = require ( 'broccoli-test-helper' ) ;
1113const createBuilder = BroccoliTestHelper . createBuilder ;
1214const createTempDir = BroccoliTestHelper . createTempDir ;
1315
1416let Addon = CoreObject . extend ( AddonMixin ) ;
1517
1618describe ( 'ember-cli-babel' , function ( ) {
19+ const ORIGINAL_EMBER_ENV = process . env . EMBER_ENV ;
20+
1721 beforeEach ( function ( ) {
1822 this . ui = new MockUI ( ) ;
1923 let project = { root : __dirname } ;
@@ -24,6 +28,14 @@ describe('ember-cli-babel', function() {
2428 } ) ;
2529 } ) ;
2630
31+ afterEach ( function ( ) {
32+ if ( ORIGINAL_EMBER_ENV === undefined ) {
33+ delete process . env . EMBER_ENV ;
34+ } else {
35+ process . env . EMBER_ENV = ORIGINAL_EMBER_ENV ;
36+ }
37+ } ) ;
38+
2739 describe ( 'transpileTree' , function ( ) {
2840 this . timeout ( 50000 ) ;
2941
@@ -33,8 +45,6 @@ describe('ember-cli-babel', function() {
3345
3446 beforeEach ( co . wrap ( function * ( ) {
3547 input = yield createTempDir ( ) ;
36- subject = this . addon . transpileTree ( input . path ( ) ) ;
37- output = createBuilder ( subject ) ;
3848 } ) ) ;
3949
4050 afterEach ( co . wrap ( function * ( ) {
@@ -48,6 +58,9 @@ describe('ember-cli-babel', function() {
4858 "bar.js" : `let bar = () => {};`
4959 } ) ;
5060
61+ subject = this . addon . transpileTree ( input . path ( ) ) ;
62+ output = createBuilder ( subject ) ;
63+
5164 yield output . build ( ) ;
5265
5366 expect (
@@ -57,6 +70,131 @@ describe('ember-cli-babel', function() {
5770 "foo.js" : `var foo = function foo() {};` ,
5871 } ) ;
5972 } ) ) ;
73+
74+ describe ( 'debug macros' , function ( ) {
75+ it ( "can opt-out via ember-cli-babel.disableDebugTooling" , co . wrap ( function * ( ) {
76+ process . env . EMBER_ENV = 'development' ;
77+
78+ let contents = stripIndent `
79+ import { DEBUG } from '@glimmer/env';
80+ if (DEBUG) {
81+ console.log('debug mode!');
82+ }
83+ ` ;
84+
85+ input . write ( {
86+ "foo.js" : contents
87+ } ) ;
88+
89+ subject = this . addon . transpileTree ( input . path ( ) , {
90+ 'ember-cli-babel' : {
91+ disableDebugTooling : true
92+ }
93+ } ) ;
94+
95+ output = createBuilder ( subject ) ;
96+
97+ yield output . build ( ) ;
98+
99+ expect (
100+ output . read ( )
101+ ) . to . deep . equal ( {
102+ "foo.js" : contents
103+ } ) ;
104+ } ) ) ;
105+
106+ describe ( 'in development' , function ( ) {
107+ it ( "should replace env flags by default " , co . wrap ( function * ( ) {
108+ process . env . EMBER_ENV = 'development' ;
109+
110+ input . write ( {
111+ "foo.js" : stripIndent `
112+ import { DEBUG } from '@glimmer/env';
113+ if (DEBUG) { console.log('debug mode!'); }
114+ `
115+ } ) ;
116+
117+ subject = this . addon . transpileTree ( input . path ( ) ) ;
118+ output = createBuilder ( subject ) ;
119+
120+ yield output . build ( ) ;
121+
122+ expect (
123+ output . read ( )
124+ ) . to . deep . equal ( {
125+ "foo.js" : `\nif (true) {\n console.log('debug mode!');\n}`
126+ } ) ;
127+ } ) ) ;
128+
129+ it ( "should replace debug macros by default " , co . wrap ( function * ( ) {
130+ process . env . EMBER_ENV = 'development' ;
131+
132+ input . write ( {
133+ "foo.js" : stripIndent `
134+ import { assert } from '@ember/debug';
135+ assert('stuff here', isNotBad());
136+ `
137+ } ) ;
138+
139+ subject = this . addon . transpileTree ( input . path ( ) ) ;
140+ output = createBuilder ( subject ) ;
141+
142+ yield output . build ( ) ;
143+
144+ expect (
145+ output . read ( )
146+ ) . to . deep . equal ( {
147+ "foo.js" : `(true && Ember.assert('stuff here', isNotBad()));`
148+ } ) ;
149+ } ) ) ;
150+ } ) ;
151+
152+ describe ( 'in production' , function ( ) {
153+ it ( "should replace env flags by default " , co . wrap ( function * ( ) {
154+ process . env . EMBER_ENV = 'production' ;
155+
156+ input . write ( {
157+ "foo.js" : stripIndent `
158+ import { DEBUG } from '@glimmer/env';
159+ if (DEBUG) { console.log('debug mode!'); }
160+ `
161+ } ) ;
162+
163+ subject = this . addon . transpileTree ( input . path ( ) ) ;
164+ output = createBuilder ( subject ) ;
165+
166+ yield output . build ( ) ;
167+
168+ expect (
169+ output . read ( )
170+ ) . to . deep . equal ( {
171+ "foo.js" : `\nif (false) {\n console.log('debug mode!');\n}`
172+ } ) ;
173+ } ) ) ;
174+
175+ it ( "should replace debug macros by default " , co . wrap ( function * ( ) {
176+ process . env . EMBER_ENV = 'production' ;
177+
178+ input . write ( {
179+ "foo.js" : stripIndent `
180+ import { assert } from '@ember/debug';
181+ assert('stuff here', isNotBad());
182+ `
183+ } ) ;
184+
185+ subject = this . addon . transpileTree ( input . path ( ) ) ;
186+ output = createBuilder ( subject ) ;
187+
188+ yield output . build ( ) ;
189+
190+ expect (
191+ output . read ( )
192+ ) . to . deep . equal ( {
193+ "foo.js" : `(false && Ember.assert('stuff here', isNotBad()));`
194+ } ) ;
195+ } ) ) ;
196+ } ) ;
197+ } ) ;
60198 } ) ;
61199
62200 describe ( '_getAddonOptions' , function ( ) {
0 commit comments