Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"defineProperty" of undefined and 'setContext' of null when running tests #202

Closed
klclee opened this issue Feb 3, 2018 · 5 comments
Closed

Comments

@klclee
Copy link

klclee commented Feb 3, 2018

Hi after upgraded to ember 2.18.1. Which in turn upgraded ember-cli-qunit (manually changed to 4.3.0, but also happening at 4.1.1). Now all of my tests are braking with "defineProperty" of undefined then at the last test I get Cannot read property 'setContext' of null

{
  "name": "m-chimera",
  "version": "0.0.0",
  "private": true,
  "description": "Small description for m-chimera goes here",
  "license": "MIT",
  "author": "",
  "directories": {
    "doc": "doc",
    "test": "tests"
  },
  "repository": "",
  "scripts": {
    "build": "ember build",
    "start": "ember server",
    "test": "ember test"
  },
  "devDependencies": {
    "broccoli-asset-rev": "^2.4.5",
    "ember-ajax": "^3.0.0",
    "ember-changeset": "1.3.0",
    "ember-changeset-validations": "1.2.8",
    "ember-cli": "^2.18.2",
    "ember-cli-app-version": "^3.0.0",
    "ember-cli-babel": "^6.6.0",
    "ember-cli-dependency-checker": "^2.0.0",
    "ember-cli-dropdown": "0.0.6",
    "ember-cli-eslint": "^4.2.1",
    "ember-cli-htmlbars": "^2.0.1",
    "ember-cli-htmlbars-inline-precompile": "^1.0.0",
    "ember-cli-inject-live-reload": "^1.4.1",
    "ember-cli-mp": "^0.1.4",
    "ember-cli-qunit": "^4.3.0",
    "ember-cli-shims": "^1.2.0",
    "ember-cli-sri": "^2.1.0",
    "ember-cli-uglify": "^2.0.0",
    "ember-content-editable": "klclee/ember-content-editable#0.8.3",
    "ember-data": "~2.18.0",
    "ember-export-application-global": "^2.0.0",
    "ember-i18n": "^5.0.2",
    "ember-load-initializers": "^1.0.0",
    "ember-resize": "0.0.12",
    "ember-resolver": "^4.0.0",
    "ember-simple-auth": "^1.0.0",
    "ember-source": "~2.18.0",
    "ember-truth-helpers": "1.3.0",
    "eslint-plugin-ember": "~5.0.0",
    "loader.js": "^4.2.3"
  },
  "engines": {
    "node": "^4.5 || 6.* || >= 7.*"
  }
}

This is a error from the auto generated tests from 2.16

not ok 52 Chrome 63.0 - Integration | Component | country field: it renders
    ---
        actual: >
            null
        stack: >
            TypeError: Cannot read property 'defineProperty' of undefined
                at Module.callback (http://localhost:7357/assets/m-chimera.js:2471:10)
                at Module.exports (http://localhost:7357/assets/vendor.js:111:32)
                at Module._reify (http://localhost:7357/assets/vendor.js:148:59)
                at Module.reify (http://localhost:7357/assets/vendor.js:135:27)
                at Module.exports (http://localhost:7357/assets/vendor.js:109:10)
                at requireModule (http://localhost:7357/assets/vendor.js:32:18)
                at Class._extractDefaultExport (http://localhost:7357/assets/vendor.js:76610:20)
                at Class.resolveOther (http://localhost:7357/assets/vendor.js:76331:32)
                at Class.superWrapper [as resolveOther] (http://localhost:7357/assets/vendor.js:55613:22)
                at Class.resolve (http://localhost:7357/assets/vendor.js:23517:35)
        message: >
            Died on test #1     at Module.callback (http://localhost:7357/assets/tests.js:474:24)
                at Module.exports (http://localhost:7357/assets/vendor.js:111:32)
                at requireModule (http://localhost:7357/assets/vendor.js:32:18)
                at TestLoader.<anonymous> (http://localhost:7357/assets/test-support.js:10279:11)
                at TestLoader.require (http://localhost:7357/assets/test-support.js:10269:27)
                at TestLoader.loadModules (http://localhost:7357/assets/test-support.js:10261:16)
                at loadTests (http://localhost:7357/assets/test-support.js:10917:22): Cannot read property 'defineProperty' of undefined
        Log: |
    ...

Finally all runs always ends up with the following error, similar to issue 194:

not ok 79 Chrome 63.0 - Unit | Route | settings/registration: global failure
    ---
        actual: >
            null
        stack: >
            TypeError: Cannot read property 'setContext' of null
                at Object.beforeEach (http://localhost:7357/assets/test-support.js:10779:16)
                at callHook (http://localhost:7357/assets/test-support.js:4127:25)
                at runHook (http://localhost:7357/assets/test-support.js:4150:7)
                at Object.advance (http://localhost:7357/assets/test-support.js:3746:26)
                at Test.queue (http://localhost:7357/assets/test-support.js:4319:22)
                at test (http://localhost:7357/assets/test-support.js:4559:12)
                at Object.onError (http://localhost:7357/assets/test-support.js:5368:5)
                at window.onerror (http://localhost:7357/assets/test-support.js:6735:18)
        message: >
            beforeEach failed on global failure: Cannot read property 'setContext' of null
        Log: |
    ...
@rwjblue
Copy link
Member

rwjblue commented Feb 3, 2018

The first error seems to happen while importing your tests. My best guess is that you are overriding Object (likely via an import). You should open assets/m-chimera.js and see what is happening on line 2471...

@klclee
Copy link
Author

klclee commented Feb 3, 2018

Yes! this was causing defineProperty of undefined problem (some how) -- pods/address/countries.js:

import Object from '@ember/object';
import { A } from '@ember/array';
var Countries = A();
Countries.pushObject(Object.create({display: "Andorra"}));
Countries.pushObject(Object.create({display: "United Arab Emirates"}));
Countries.pushObject(Object.create({display: "Afghanistan"}));
Countries.pushObject(Object.create({display: "Antigua and Barbuda"}));
Countries.pushObject(Object.create({display: "Anguilla"}));
....

export default Countries;

@rwjblue should I not be doing import Object from '@ember/object'; ? but linting errors shows up in 2.18.1 asking me to do that.

@klclee
Copy link
Author

klclee commented Feb 5, 2018

yes so it should be import EmberObject from '@ember/object'; rather then import Object from '@ember/object'; 👍

@rwjblue
Copy link
Member

rwjblue commented Feb 5, 2018

Yep, this is ultimately because Babel is internally using Object.defineProperty for setting up your applications modules and if you shadow the global Object (via an import) it causes this kind of error...

@klclee
Copy link
Author

klclee commented Feb 6, 2018

Closing this now. Cuz the other issue is similar to #194

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants