question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

pollyjs config is undefined when reusing ember build and running ember test

See original GitHub issue

Hello 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:closed
  • Created 4 years ago
  • Comments:12

github_iconTop GitHub Comments

1reaction
offirgolancommented, Dec 18, 2019

@shankarsridhar released under v3.0.0

1reaction
jasonmitcommented, Nov 24, 2019

Yup, looks related. I can work around it but will wait to see how the above progresses first. Thanks for linking the issues.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Upgrading Ember - Issues with Tests - Questions
So I took on the task of upgrading our Ember app from 2.16 to 3.26. The application runs fine locally. Got through the...
Read more >
@pollyjs/ember - npm
Start using @pollyjs/ember in your project by running `npm i ... Check out the Ember CLI Addon documentation for more details.
Read more >
Converting Your Ember App to TypeScript - Inside Skylight
The first step is to run ember install ember-cli-typescript . ... Etc… create tsconfig.json create app/config/environment.d.ts create ...
Read more >
Renovate Bot Package Diff
dist/config-validator.js +5 -14; dist/config-validator.js.map +1 -1 ... [preset];\n if (newPreset !== undefined) {\n presets[i] = newPreset;\n }\n }\n }\n ...
Read more >
Apple introduces MapKitJS, Meteor 1.7 released
This video session from WWDC runs through how you could use it. ... APIs and Infrastructure for Next-Gen JavaScript Apps— Build and scale...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found