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

Attempting to configurable attribute of unconfigurable property. #1456

Closed
gyandeeps opened this issue Jun 12, 2017 · 11 comments · Fixed by #1462
Closed

Attempting to configurable attribute of unconfigurable property. #1456

gyandeeps opened this issue Jun 12, 2017 · 11 comments · Fixed by #1462
Labels

Comments

@gyandeeps
Copy link
Contributor

gyandeeps commented Jun 12, 2017

System info

Node: 8
babel-polyfill: 6.23.0
core-js: ^2.4.0
phantomjs-prebuilt: 2.1.14
Sinon: 2.3.1 (no issue) - 2.3.2 (has issue)

What did you expect to happen?

  • It runs fine on chrome
  • It throws error on phantomjs
  • No issues with sinon 2.3.1. Issue after that.

What actually happens

I use karma run unit test. webpack for bundling and babel for code translation and polyfill. Running my unit test using phantomjs and i get the following error:

PhantomJS 2.1.1 (Windows 7 0.0.0) Positioning detectFlipPositionY Special cases Should return original if element exceeds limit on top and bottom FAILED
TypeError: Attempting to configurable attribute of unconfigurable property. in C:/Users/<dir/dir>/node_modules/babel-polyfill/dist/polyfill.js (line 4908)

How to reproduce

describe("Positioning", () => {
    const sandbox = sinon.sandbox.create();

    const mockWindowWithAttr = (width = 100, height = 100) => {
        sandbox.stub(window, "innerWidth").value(width);
        sandbox.stub(window, "innerHeight").value(height);
    };

    beforeEach(() => {
        mockWindowWithAttr();
    });

    afterEach(() => {
        sandbox.restore();
    });

    it("test", () => {
        assert.isTrue(true);
    });
});

UPDATE

Regression: #1419

  • If I remove configurable: true then it works fine.
@fatso83
Copy link
Contributor

fatso83 commented Jun 12, 2017

Where do you mean you set the configurable option? It's not in the code. Thanks for finding the regression btw

@gyandeeps
Copy link
Contributor Author

#1419 PR sets a configurable: true at many places when using Object.defineProperty. Thats where If i remove that then it works fine..

@fatso83
Copy link
Contributor

fatso83 commented Jun 13, 2017

👌. I guess we could wrap those defineProperty calls in a try/catch. Unless there is some way of knowing if they are configurable before attempting?

@lucasfcosta
Copy link
Member

@fatso83 Yup, there's an easy way to do it.

We can use Object.getOwnPropertyDescriptor while going all the way up the prototype chain to find this properties' property descriptor (because that method only returns own property descriptors). Btw, we actually have a utility method that already does this.

Then we need to check if that property exists and if it's configurable in order to decide how Object.defineProperty will behave.

This change should be enough to fix this issue.

@gyandeeps if you want to do a PR for this I'd be more than happy to review it. I don't think I will have enough time to work on this in the next two weeks, so if anyone wants to tackle it I highly encourage you to do so. Otherwise I can work on it (alongside the other ongoing things I have got here) when I come back.

@fatso83
Copy link
Contributor

fatso83 commented Jun 19, 2017

@lucasfcosta There is a PR ready for review from you at #1462 :-)

fatso83 pushed a commit that referenced this issue Jun 20, 2017
* Fix: check configurable on a prop before creating (fixes #1456)
@mroderick
Copy link
Member

#1462 didn't fix this in all environments, the build fails in Safari 9.0

  1. issues Attempting to configurable attribute of unconfigurable property. #1456 stub window innerHeight:
    Attempting to change access mechanism for an unconfigurable property.

Unfortunately, I was a bit too fast at getting a new release out the door, so now we have v2.3.5 out there. I am trying to figure out if I can unpublish that version.

@mroderick mroderick reopened this Jun 20, 2017
@mroderick
Copy link
Member

I am trying to figure out if I can unpublish that version.

That doesn't work currently. I think we should just leave it as is, and then fix that error asap.

@fatso83
Copy link
Contributor

fatso83 commented Jun 20, 2017

Maybe it's OK to just drop the failing test? There isn't a way of "fixing" the test for Safari anyhow - it doesn't allow modifying that property.

@mroderick
Copy link
Member

I liked your proposal about using try/catch. Could that be applicable here?

@lucasfcosta
Copy link
Member

We cannot unpublish but we can move the latest tag to a previous version, which means people would not be installing the one with bugs when using npm install sinon (or yarn add sinon if you're one of the cool kids 😆).

From the NPM docs for dist-tag:

Publishing a package sets the latest tag to the published version unless the --tag option is used. For example, npm publish --tag=beta.
By default, npm install (without any @ or @ specifier) installs the latest tag.

This is the command you've gotta use for that:

npm dist-tag add <pkg>@<old_version_number> latest

fatso83 added a commit to fatso83/sinon that referenced this issue Jul 4, 2017
fatso83 added a commit to fatso83/sinon that referenced this issue Jul 4, 2017
fatso83 added a commit to fatso83/sinon that referenced this issue Jul 13, 2017
fatso83 added a commit to fatso83/sinon that referenced this issue Jul 13, 2017
fatso83 added a commit to fatso83/sinon that referenced this issue Jul 13, 2017
fatso83 added a commit to fatso83/sinon that referenced this issue Jul 13, 2017
mroderick added a commit that referenced this issue Jul 15, 2017
@stale
Copy link

stale bot commented Jan 13, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Jan 13, 2018
@stale stale bot closed this as completed Jan 20, 2018
franck-romano pushed a commit to franck-romano/sinon that referenced this issue Oct 1, 2019
…nonjs#1462)

* Fix: check configurable on a prop before creating (fixes sinonjs#1456)
franck-romano pushed a commit to franck-romano/sinon that referenced this issue Oct 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
4 participants