pollyjs config is undefined when reusing ember build and running ember test
See original GitHub issueHello pollyjs contributors and devs, I am not sure if this is a bug report or a question 😃
TL;DR
pollyjs config from consuming ember app is not available inside the polly js addon methods, when reusing the build, which happens when running the command,
ember test --path <build folder name>
Description
I am using pollyjs/@ember package for my ember project, and it works just fine, when I run the tests using the command, ember test
.
But when I try to reuse an existing build of my ember project(ember test --path <build folder name. by default, 'dist'>
), I run into this error in command line:
Cannot read property 'enabled' of undefined
Stack Trace and Error Report: /var/folders/l3/zfkk52zd2qsdh8lbhdz6gy1r000lf7/T/error.dump.466e5463069e16ef55ccda6970db9a12.log
On further looking into the logs and debugging the ember node process, the error was happening in the testemMiddleware()
method in the @pollyjs/ember/index.js
file as show below:
testemMiddleware(app) {
if (this._config.enabled) { // <== `this._config` is undefined here
registerExpressAPI(app, this._config.server);
}
},
And the root cause seems to be that pollyjs this.app.options.pollyjs
config defined and retrieved from the consuming ember app into the addon, is available only in the included()
hook; but not available inside the other methods.
Error Message & Stack Trace
stack: TypeError: Cannot read property 'enabled' of undefined
at Class.testemMiddleware (/Users/shsridha/workspace/srd-backstop/gryphon-fe/node_modules/@pollyjs/ember/index.js:45:22)
at middlewares.forEach.middleware (/Users/shsridha/workspace/srd-backstop/gryphon-fe/node_modules/testem/lib/server/index.js:183:9)
at Array.forEach (<anonymous>)
at Server.injectMiddleware (/Users/shsridha/workspace/srd-backstop/gryphon-fe/node_modules/testem/lib/server/index.js:182:19)
at Server.createExpress (/Users/shsridha/workspace/srd-backstop/gryphon-fe/node_modules/testem/lib/server/index.js:133:10)
at Server.start (/Users/shsridha/workspace/srd-backstop/gryphon-fe/node_modules/testem/lib/server/index.js:41:10)
at App.startServer (/Users/shsridha/workspace/srd-backstop/gryphon-fe/node_modules/testem/lib/app.js:231:24)
at App.getServer (/Users/shsridha/workspace/srd-backstop/gryphon-fe/node_modules/testem/lib/app.js:235:17)
at Bluebird.using (/Users/shsridha/workspace/srd-backstop/gryphon-fe/node_modules/testem/lib/app.js:74:38)
at tryCatcher (/Users/shsridha/workspace/srd-backstop/gryphon-fe/node_modules/bluebird/js/release/util.js:16:23)
at /Users/shsridha/workspace/srd-backstop/gryphon-fe/node_modules/bluebird/js/release/using.js:185:26
at tryCatcher (/Users/shsridha/workspace/srd-backstop/gryphon-fe/node_modules/bluebird/js/release/util.js:16:23)
at Promise._settlePromiseFromHandler (/Users/shsridha/workspace/srd-backstop/gryphon-fe/node_modules/bluebird/js/release/promise.js:517:31)
at Promise._settlePromise (/Users/shsridha/workspace/srd-backstop/gryphon-fe/node_modules/bluebird/js/release/promise.js:574:18)
at Promise._settlePromise0 (/Users/shsridha/workspace/srd-backstop/gryphon-fe/node_modules/bluebird/js/release/promise.js:619:10)
at Promise._settlePromises (/Users/shsridha/workspace/srd-backstop/gryphon-fe/node_modules/bluebird/js/release/promise.js:699:18)
at Promise._fulfill (/Users/shsridha/workspace/srd-backstop/gryphon-fe/node_modules/bluebird/js/release/promise.js:643:18)
at PromiseArray._resolve (/Users/shsridha/workspace/srd-backstop/gryphon-fe/node_modules/bluebird/js/release/promise_array.js:126:19)
at PromiseArray._promiseFulfilled (/Users/shsridha/workspace/srd-backstop/gryphon-fe/node_modules/bluebird/js/release/promise_array.js:144:14)
at Promise._settlePromise (/Users/shsridha/workspace/srd-backstop/gryphon-fe/node_modules/bluebird/js/release/promise.js:579:26)
at Promise._settlePromise0 (/Users/shsridha/workspace/srd-backstop/gryphon-fe/node_modules/bluebird/js/release/promise.js:619:10)
at Promise._settlePromises (/Users/shsridha/workspace/srd-backstop/gryphon-fe/node_modules/bluebird/js/release/promise.js:699:18)
Config
Defined inside the ember-cli-build.js
pollyjs: {
enabled: EmberApp.env() !== 'production',
server: {
expiresIn: null,
keepUnusedRequests: false
}
},
Environment
Node.js v10.15.0
darwin 18.7.0
6.4.1
1.15.2
Issue Analytics
- State:
- Created 4 years ago
- Comments:12
@shankarsridhar released under
v3.0.0
Yup, looks related. I can work around it but will wait to see how the above progresses first. Thanks for linking the issues.