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

Migrate sinon-test from sinon package. #1

Merged
merged 11 commits into from
Jan 31, 2016

Conversation

jonnyreeves
Copy link
Contributor

  • sinon.test
  • sinon.testCase
  • Update README

Extract sinon.test and sinon.testCase from the current sinon 2.0-pre package. Modify both methods to be independent of sinon.config.

Still need to get the test-case tests back on their feet (they stubbed on sinon.test so are a little tricky to migrate) - but otherwise it's taking shape.

Please let me know your thoughts about the proposed API.

Extract `sinon.test` and `sinon.testCase` from the current sinon 2.0-pre package.  Modify both methods to be indenpendant of `sinon.config`.
@jonnyreeves jonnyreeves mentioned this pull request Jan 18, 2016
36 tasks
@cjohansen
Copy link
Contributor

Looking good! I have some thoughts:

The dependency on Sinon is unfortunate, as it will require constant republishing of this package. I understand the appeal of var sinon.test = require('sinon-test'), but catering to convenience is what introduced the problematic sinon.config and other singletons in the first place. Besides, it is very unfortunate that var sinon.test = require('sinon-test') will make sinon and sinon.test use potentially different versions of Sinon.

I suggest the following API instead:

sinon.test = require('sinon-test')(sinon);
sinon.test = require('sinon-test')(sinon, config);

or, more explicit:

sinon.test = require('sinon-test').configure(sinon);
sinon.test = require('sinon-test').configure(sinon, config);

But then, how to access testCase? Maybe:

sinon.testCase = require('sinon-test').configureTestCase(sinon, config);

Other suggestions?

Now that we're using browserify, do we need all the closures and scaffolding in the modules? Couldn't we just make them regular CommonJS modules?

@fatso83
Copy link
Contributor

fatso83 commented Jan 19, 2016

Agree with removing the explicit sinon dependency. With regards to injecting, I prefer the first alternative: sinon.test = require('sinon-test')(sinon, config);. Then you could throw an error on require if you fail to pass a sinon instance, something which is not done with the configure version.

@cjohansen
Copy link
Contributor

How can you throw an error on require? I don't see the difference:

sinon.test = require('sinon-test');

sinon.test(); // This can throw a predefined error regardless of the chosen API

@fatso83
Copy link
Contributor

fatso83 commented Jan 19, 2016

I was struck by temporary retardedness 😭 You are absolutely right.

@mantoni
Copy link
Member

mantoni commented Jan 19, 2016

I think the ideal solution requires sinon-core and maybe even sinon-sandbox to be standalone so that this module can depend on them. Then there is no need for injections and potential incompatibilities.

@cjohansen
Copy link
Contributor

I'm not sure I agree. Those modules would still come with the version conundrum. I think injection is the ideal solution, as it would allow sinon-test to be slapped with a 1.0.0 and basically never be touched again. It's been stable for years.

@mantoni
Copy link
Member

mantoni commented Jan 19, 2016

Well, I was thinking of using the default npm versioning and depend on ^1.0.0 which essentially means all minor and patch versions are fine. In case of a major version change, two major versions could even co-exist - at least in node and browserify. With the injection, the API dependency is implicit and it's not possible to upgrade one Sinon module without also upgrading the others.

One example might help to illustrate my point:
Imagine this module would depend on sinon-sandbox and we would release a major version of that library. A Sinon user could opt-in to use the new sandbox version without the need to also upgrade sinon-test, which could still depend on ^1.0. If the breaking change does not affect users of sinon-test, we're even free to release a minor version to upgrade to ^2.0 without forcing this version on users.

On the other hand, with the injection, a major upgrade of either module most likely requires the other one to be upgraded too.

@cjohansen
Copy link
Contributor

I still think the problem that if using sinon and sinon-test alongside each other, it will be difficult to ensure all areas of your test suite are using the same version of sinon (or smaller constituents, but that's beside the point). Also, if sinon-test depends on any other Sinon module, it will require meaningless version bumps and pushes everytime a dependency fixes a bug etc. This is busy work we should strive to avoid.

With injection, sure there might be problems when sinon and/or sinon-test have major version upgrades, although I don't expect our public APIs to change on a very regular basis. There is for example little reason for the sandbox API to change. All in all, injection offers the most flexibility and predictability while also reducing busy-work on our side, while having very good odds for staying quite stable.

@mantoni
Copy link
Member

mantoni commented Jan 19, 2016

Sorry @cjohansen, but I think you misunderstand my suggestion. If we use carets in the version numbers, e.g. ^1.0.0, then there is no meaningless busy work going on. Any bumps would propagate implicitly with the exception of a breaking change.

@jonnyreeves
Copy link
Contributor Author

Gents, I have updated the API so it no longer has an NPM dependency on sinon; however the packaged tests are now failing as (I believe) they're picking up the sinon instance shipped with buster that gets exported onto the window which causes three of the tests to fail.

Any input would be greatly appreciated; I would love to just bundle up the tests themselves using browserify (and thereby not have to reference the window object in any of the tests); but I have no idea how to get buster and browserify to play nice :( Are there any buster experts in the room (paging @mroderick )

@jonnyreeves
Copy link
Contributor Author

Anyone? Can't help but think things would be much simpler to test if were using a less opinionated test-runner (like mocha) instead - would there be any objections to me migrating these tests over? Then I can just browserify all the tests and run them through phantom.

@mroderick
Copy link
Member

@cjohansen is the buster expert ;-)

I am returning from vacation and still have tourist mode engaged. Once I am back to daily life, I can look into the discussion of test runners

Anyway, I think we should discuss test runners in it's own thread

Use browserify-shim to replace require calls with references to `window.buster`; this allows us to remove all the IIFE shims from the test-cases and use `require` in the packaged tests.
@jonnyreeves
Copy link
Contributor Author

Thanks for the reply @mroderick. So after my rant above I set out to figure out how to fix this; and hopefully I now have a working solution.

The browserify-shim package allows us to replace require() calls with global references; this allows us to require sinon modules but not buster.

Had to drop one test as it was tightly coupled to the old `sinon.test` global.
@jonnyreeves
Copy link
Contributor Author

Hey all, so the tests are passing on travis, but the Node 0.8 build is hanging / failing on buster; I copied the config straight from the sinon repo; anyone have any idea what's causing this? Any objections to turning off the 0.8 build?

@fatso83
Copy link
Contributor

fatso83 commented Jan 25, 2016

Hmm ... I restarted the 0.8 build, and it still failed. I do not really see why we should keep on to the 0.8 version of Node as it is almost 4 years old.

@cjohansen
Copy link
Contributor

My opinion on two issues raised:

  1. Do we have to use Buster? IMO, no. As long as npm test does something useful I don't care too much about what is powering it. As we're now using Browserify (yay!) there are probably better options than Buster. I also don't think we need to use the exact same stack on every module. Personally, I have had decent luck with @mantoni's mochify, combined with referee (Buster's assertions).
  2. The only 0.x node we should spend time on is 0.12. We can keep 0.10 around for as long as it doesn't cause problems, but honestly, I don't think it's worth the trouble if/when it stops working.

@mantoni
Copy link
Member

mantoni commented Jan 25, 2016

+1 for removing old node support. It goes without saying, if we're switching to Mochify I'm keen to support whatever is needed in the Sinon context.

@jonnyreeves
Copy link
Contributor Author

OK, dropped Node 0.8 builds from Travis and everything is green. This PR is ready for review, please take a look.

@fatso83
Copy link
Contributor

fatso83 commented Jan 25, 2016

LGTM 👍

@@ -0,0 +1,17 @@
/**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to keep all this boilerplate in all files? If we're providing a built version using Browserify, can't we just add a banner during the build step?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I was under the impression this was the copy's standard copyright / description block. I have no issue with leaving it in, or taking it out - just say the word :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure whether it's good enough to prepend this in the browserified version. This is also shipped and executed as-is in node.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no idea why it's there in the first place. We do have a LICENSE, so repeating it in every file seems superfluous. It should be enough with a short description of the module. The rest is redundant.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair point.

@mroderick
Copy link
Member

Other than the comment about the boilerplate, I have no comments. Excellent work @jonnyreeves

@jonnyreeves
Copy link
Contributor Author

Gents, anything stopping this one from landing? Once it's merged we can merge sinonjs/sinon#973 and I can get the ball rolling on migrating all the sinon tests over to using CommonJS.

cjohansen added a commit that referenced this pull request Jan 31, 2016
Migrate sinon-test from sinon package.
@cjohansen cjohansen merged commit 0714282 into sinonjs:master Jan 31, 2016
@cjohansen
Copy link
Contributor

👍 Sorry for the delay.

@jonnyreeves jonnyreeves deleted the feature/hello-world branch February 2, 2016 07:06
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

Successfully merging this pull request may close these issues.

5 participants