emberjs/ember-test-waiters

Allow stripping from production builds

makepanic opened this issue · 3 comments

Hi,

I saw that ember-test-waiters it always included in our production build.
This seems weird as one wouldn't expect test-waiters in an app that isn't build for testing.

Our app was using ember-test-waiters@1.1.1 and I've also tried to manually resolve to 1.2.0 but it didn't change the resulting payload.

Would it be ok to strip ember-test-waiters in all production builds or provide an option to make it configurable?

I could open a PR that adds a funnel that excludes everything from the addon tree if enabled.

Hey @makepanic, this is true in that ember-test-waiters is included in prod builds. It was built this way to allow the correct interleaving of application code with async markers (waiters) to ensure that correct waiting occurs. In prod, we strip down to very few bytes, and noop the waiters.

This is intentional, as we want to ultimately enable testing prod code too.

@scalvert - this is the production minified code that I get:

define("ember-test-waiters/build-waiter",["exports","ember-test-waiters","ember-test-waiters/noop-test-waiter"],(function(e,t,r){"use strict"
Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(e){0
return new r.default(e)}})),define("ember-test-waiters/index",["exports","ember-test-waiters/waiter-manager","ember-test-waiters/test-waiter","ember-test-waiters/build-waiter","ember-test-waiters/wait-for-promise"],(function(e,t,r,n,i){"use strict"
Object.defineProperty(e,"__esModule",{value:!0}),Object.defineProperty(e,"register",{enumerable:!0,get:function(){return t.register}}),Object.defineProperty(e,"unregister",{enumerable:!0,get:function(){return t.unregister}}),Object.defineProperty(e,"getWaiters",{enumerable:!0,get:function(){return t.getWaiters}}),Object.defineProperty(e,"_reset",{enumerable:!0,get:function(){return t._reset}}),Object.defineProperty(e,"getPendingWaiterState",{enumerable:!0,get:function(){return t.getPendingWaiterState}}),Object.defineProperty(e,"hasPendingWaiters",{enumerable:!0,get:function(){return t.hasPendingWaiters}}),Object.defineProperty(e,"TestWaiter",{enumerable:!0,get:function(){return r.default}}),Object.defineProperty(e,"buildWaiter",{enumerable:!0,get:function(){return n.default}}),Object.defineProperty(e,"waitForPromise",{enumerable:!0,get:function(){return i.default}})})),define("ember-test-waiters/noop-test-waiter",["exports"],(function(e){"use strict"
Object.defineProperty(e,"__esModule",{value:!0}),e.default=void 0
e.default=class{constructor(e){this.name=e}beginAsync(){return this}endAsync(){}waitUntil(){return!0}debugInfo(){return[]}reset(){}}})),define("ember-test-waiters/test-waiter",["exports","ember-test-waiters/waiter-manager"],(function(e,t){"use strict"
Object.defineProperty(e,"__esModule",{value:!0}),e.default=void 0
let r=0
function n(){return r++}e.default=class{constructor(e,t){this.isRegistered=!1,this.items=new Map,this.name=e,this.nextToken=t||n}register(){this.isRegistered||((0,t.register)(this),this.isRegistered=!0)}beginAsync(e=this.nextToken(),t){if(this.register(),this.items.has(e))throw new Error(`beginAsync called for ${e} but it is already pending.`)
let r=new Error
return this.items.set(e,{get stack(){return r.stack},label:t}),e}endAsync(e){if(!this.items.has(e))throw new Error(`endAsync called for ${e} but it is not currently pending.`)
this.items.delete(e)}waitUntil(){return 0===this.items.size}debugInfo(){return[...this.items.values()]}reset(){this.items.clear()}}})),define("ember-test-waiters/types/index",[],(function(){})),define("ember-test-waiters/wait-for-promise",["exports","ember-test-waiters/test-waiter"],(function(e,t){"use strict"
Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(e,t){let r=e
0
return r}
new t.default("promise-waiter")})),define("ember-test-waiters/waiter-manager",["exports"],(function(e){"use strict"
Object.defineProperty(e,"__esModule",{value:!0}),e.register=function(e){t.set(e.name,e)},e.unregister=function(e){t.delete(e.name)},e.getWaiters=function(){return[...t.values()]},e._reset=function(){t.clear()},e.getPendingWaiterState=r,e.hasPendingWaiters=n
const t=new Map
function r(){let e={pending:0,waiters:{}}
return t.forEach(t=>{if(!t.waitUntil()){e.pending++
let r=t.debugInfo()
e.waiters[t.name]=r||!0}}),e}function n(){return r().pending>0}Ember.Test&&Ember.Test.registerWaiter(()=>!n())})),

It is 3.4K according to my file system. I don't plan on testing my production code and would like to save these bytes.

Would you mind reconsidering this feature request? If @makepanic is willing to open a PR to add that option - why not?

@boris-petrov - Thanks for chiming in here! Can you open a new issue specifically for ensuring that our production impact is as low as possible? Obviously, that is a bit different from what you (and this issue) were asking, but it is something we can do basically right away and will have a pretty good impact.