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

Remove direct dependency on Sinon #44

Closed
IanVS opened this issue Dec 4, 2015 · 15 comments
Closed

Remove direct dependency on Sinon #44

IanVS opened this issue Dec 4, 2015 · 15 comments

Comments

@IanVS
Copy link

IanVS commented Dec 4, 2015

Why are Sinon methods being exported from this package (for example in https://github.com/airbnb/reagent/blob/master/src/index.js#L20)? This poses a problem for us, as Sinon is throwing an exception on our codebase and we don't necessarily want to use Sinon and would rather have the flexibility to choose our own mocking/stubbing library. I understand that it's perhaps a convenience to be able to useSinon, but It seems outside of the scope of what Reagent is trying to accomplish, and it is trivial to set up Sinon ourselves. Is there a chance you'll rethink this approach? I'd really like to be able to use Reagent for testing, but right now this is preventing us from doing so.

@ljharb
Copy link
Member

ljharb commented Dec 4, 2015

It seems reasonable to move the sinon stuff into a reagent-sinon package which you could use if you wanted that behavior.

@mudetroit
Copy link

I think it makes a ton of sense to not have sinon as part of the main package. I am curious what direct benefit a user of reagent would get from including sinon with reagent that wouldn't be there if you depended on sinon directly.

Additionally the current implementation makes assumptions about test framework lifecycle methods that might not make sense in every environment.

@ljharb
Copy link
Member

ljharb commented Dec 4, 2015

I'm not sure what assumptions you're talking about - could you please file a separate issue for that?

@IanVS
Copy link
Author

IanVS commented Dec 4, 2015

Not every test framework has a beforeEach and afterEach.

@mudetroit
Copy link

@ljharb not certain it is worth an issue. but before and after while available in most frameworks aren't present in them all. Qunit for example uses setup and teardown.

@lelandrichardson
Copy link
Collaborator

The use of sinon in this project has been largely left undocumented because of the assumptions it's making about mocha being present (which is a vestige of this being used internally at airbnb).

I agree this should be done as it is somewhat separate from the meat of the library.

@just-boris
Copy link
Contributor

+1
I am using this with jasmine, and I don't need an extra library for spies, since I have a built-in one.

lelandrichardson added a commit that referenced this issue Dec 8, 2015
This refactor addresses several issues regarding enzyme working in a variety of environments, and
the library just generally not making any assumptions about the environment that tests will be
run in.

For the most part, this amounts to:

- remove direct dependency on jsdom
- remove direct dependency on sinon
- remove assumed dependency on mocha

Additionally, this change moves the code that was removed into separate modules that are
defined in the packages folder. In this case we have added two modules: "enzyme-mocha" and
"enzyme-sinon".

This design will allow us to have one repo where all issues, code, and documentation
regarding enzyme are centralized, but modules are still separated at the NPM level. This
will allow us to make atomic releases across the modules more easily, as well as keep
all of the discussion in one place.

Left to do before this is mergable:

 [ ] Add a "guides" section in the docs explaining how to use enzyme in different environments
 [ ] Build a proper npm script to run an npm publish in the proper order for each module
 [ ] Add more meaningful tests for packages

This PR addresses several issues that havee been brought up:

- Fixes #55
- Fixes #47
- Fixes #44
@Sinewyk
Copy link

Sinewyk commented Jan 20, 2016

Considering the related PR was just closed with no comments, what does this mean for this issue ?

Do you still accept work for this or do you have other plans ?

@lelandrichardson
Copy link
Collaborator

@Sinewyk this is still going to happen! I just closed the PR because this branch was doing some mono-repo things that we've decided not to do.

This is definitely planned for 2.0!

@mikl
Copy link

mikl commented Feb 1, 2016

Just fyi., the Sinon dependency could also be a significant blocker to adoption, since Sinon has issues with WebPack, so it starts puking out errors as soon as I add a import { shallow } from 'enzyme' to my project.

WARNING in ./~/sinon/lib/sinon.js
Critical dependencies:
40:25-32 require function is used in a way in which dependencies cannot be statically extracted
 @ ./~/sinon/lib/sinon.js 40:25-32

I'm using a setup based on the react-redux-starter-kit, but there's plenty of other people with the same problem, and the accepted workaround won't work here, since I can't modify how Enzyme requires Sinon (without forking).

@lelandrichardson
Copy link
Collaborator

@mikl I totally 100% agree. Enzyme 2.0 will be coming out soon with this as one of the breaking changes. You can try pulling in the RC in the time being (no guarantees on what that will do though):

npm i enzyme@2.0.0-rc1

Part of enzyme 2.0 will be that all major test environments will be supported, and this will be ensured by having "example" projects whose test suites actually run as part of the CI of this project.

Sorry again for the frustrations that this is causing at the moment.

@IanVS
Copy link
Author

IanVS commented Feb 1, 2016

@lelandrichardson no need to apologize! You're doing us all an awesome service by open sourcing this. Thanks for all your hard work on it.

@mikl
Copy link

mikl commented Feb 2, 2016

@lelandrichardson thanks, no need to apologise. It 2.0.0-rc1 solves the Sinon problem, although I still needed one of the workarounds from #47 to make it all work.

@lelandrichardson
Copy link
Collaborator

@mikl yes - some of the problems present in #47 and other issues are not easy problems to fix as they are present in part because there are conditional require statements that are different for react 0.13 and react 0.14, which could only be fixed through dropping 0.13 support. Additionally cheerio has some problems specifically which would mean we'd have to drop render support or roll our own cheerio.

With the release of 2.0 I will include guides for the steps to get enzyme working in every popular testing environment that I'm hoping will achieve a good balance of ease-of-installation and compatibility.

@mikl
Copy link

mikl commented Feb 2, 2016

@lelandrichardson yeah, nothing like multi-version, multi-environment support to create work for you 😞. Thanks for your efforts.

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

No branches or pull requests

7 participants