elwayman02 / ember-sinon-qunit Goto Github PK
View Code? Open in Web Editor NEWSinon sandbox test integration for QUnit
License: MIT License
Sinon sandbox test integration for QUnit
License: MIT License
Hi,
Love the package! Was just wondering if there's a reason sinon.match isn't being added as a property? Happy to make a PR if it's just oversight.
Thanks for your time.
Sinon lets you specify the promise library used by stub.resolves
. It would be nice if this wrapper could automatically set it to RSVP
. I had a quick look through the code but I wasn't sure where to add something like this...
I am getting the following when attempting to use sinon to spy on a method
Attempted to wrap undefined property jsonSettingToSetting as function
It turns out the culprit is the method is decorated with @action. How do you use sinon with actions? The action is on a service btw.
Branch | Build failing ๐จ |
---|---|
Dependency | loader.js |
Current Version | 4.1.0 |
Type | devDependency |
This version is covered by your current version range and after updating it in your project the build failed.
As loader.js is โonlyโ a devDependency of this project it might not break production or downstream projects, but โonlyโ your build or test tools โ preventing new deploys or publishes.
I recommend you give this issue a high priority. Iโm sure you can resolve this ๐ช
The new version differs by 14 commits .
cc53069
release v4.2.0
1a453d3
Merge pull request #104 from trentmwillis/redefine
93478ef
Improve redefinition scenarios
e289916
Fix test:dev command
287a487
Merge pull request #105 from trentmwillis/clarify
cda1c29
Clarify prime comment
562ecf1
Merge pull request #100 from jrowlingson/master
6a9b916
remove petal references
b609262
Merge pull request #95 from chadhietala/heimdall-instrumentation
c49296d
Instrument with heimdall
453fe8c
Merge pull request #97 from Turbo87/ci-deploy
37fef79
CI: Enable automatic NPM deployment for tags
c4f0755
Merge pull request #96 from chadhietala/dict-registry
8a34296
Use dict for registery and seen to avoid filling IC cache
See the full diff.
There is a collection of frequently asked questions and of course you may always ask my humans.
Your Greenkeeper Bot ๐ด
6.2.0
to 6.3.0
.๐จ View failing branch.
This version is covered by your current version range and after updating it in your project the build failed.
eslint-plugin-ember is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.
no-unnecessary-service-injection-argument
rule (@bmish)closure-action
rule examples (@Caltor)There is a collection of frequently asked questions. If those donโt help, you can always ask the humans behind Greenkeeper.
Your Greenkeeper Bot ๐ด
Looks like after bumping ember-sinon-qunit
from 6.0.0
to 7.0.0
we are seeing sinon
, qunit
and some other packages getting included in one of ember-auto-import
generated chunks for production builds.
I was able to reproduce this https://github.com/vstefanovic97/ember-sinon-qunit-bug-reproduction, repository is new ember app with just ember-sinon-qunit
added.
Steps to reproduce
git clone https://github.com/vstefanovic97/ember-sinon-qunit-bug-reproduction
npm i
npm run build
After build if we inspect dist/index.html
and chunks included we will see that one of the chunks contains sinon
and qunit
code.
After investigation it seems that this is the root cause https://github.com/elwayman02/ember-sinon-qunit/blob/master/index.js#L14-L30
Something we are doing here is not sitting well with ember-auto-import
and because of that it includes test deps in prod bundle.
Since preprocessJs is a private method we probably shouldn't be using it in the first place.
I propose just removing this code and having users import setupSinon
as
import setupSinon from 'ember-sinon-qunit/test-support';
Currently we reference self.QUnit
, but I honestly don't remember if that was necessary or if I just didn't think about importing it back then. ๐
https://github.com/elwayman02/ember-sinon-qunit/blob/master/addon-test-support/index.js#L11
An explicit import seems much better, if it works.
It looks like the ternary on this line doesn't do anything? Both sides of the colon are the same...
Love the add-on. Do you have any plans add support for using sinon in moduleFor
as well?
ember-sinon-qunit > ember-sinon > sinon > build > [email protected]: wrench.js is deprecated! You should check out fs-extra (https://github.com/jprichardson/node-fs-extra) for any operations you were using wrench for. Thanks for all the usage over the years.
๐๐ป thanks for this addon, it's super easy to integrate sinon with ember + qunit tests.
I haven't run into the issue personally, but it looks like v3.4.0
which was released recently introduced a breaking change where sinon
was updated from v6
to v7
.
I think the difference the between breaking vs minor changes is a little mirky here so I don't want to get too bogged down in the specifics... I do want to help make this less of an issue for people upgrading in the near future!
Have you considered making sinon
a peerDependency
for this addon? That way consumers can pick and choose the version they want to use. It would require consumers install both ember-sinon-qunit
and sinon
. I can put up a PR with an example of how this would work?
I get this in all my tests that use this plugin.
---
Log: |
{ type: 'info',
text: '\'sinon.getConfig is deprecated and will be removed from the public API in a future version of sinon.\'\n' }
Also there are numerous dependencies that are out of date.
Just upgraded to latest and getting the following error:
ERROR in ./node_modules/sinon/pkg/sinon-esm.js 405:74-81
Module not found: Error: Can't resolve 'process/browser' in '/Users/eric/Projects/sqwok/ember-sqwok/node_modules/sinon/pkg'
Any suggestions or ideas?
With ember-qunit, in my beforeEach
I can assign to this, and these assigned attributes will be available inside my test callbacks, ex:
moduleForComponent(..., function () {
beforeEach() {
this.demo = 'string';
});
test('test name', function (assert) {
assert.equal(this.demo, 'string');
});
The following works with ember-qunit, but not when using ember-sinon-qunit.
Ideally ember-sinon-qunit would work the same as ember-qunit, so replace all usages of ember-qunit with the sinon variant.
I originally reported that the @action
wrapper turned the method into a property here and that is true, and what I documented got me through a simple use case, but as I have used it more I have found that it isnt correct.
Since the action is now a property, the get has to return a function that is the stub or spy if you wanted to do something like stub.withArgs we couldnt. We stubbed the getter, not the actual function. However stub.calledOnce works because accessing the method is basically the same as calling it in this case, so it worked for the use case I was doing at the time.
Here is take 2 on the documentation
the code to stub is actually
// my fake function
let stub = sinon.stub().callsFake(function() {
return null;
});
// the getter has to return the actual stub of the method,
sinon.stub(object, "method").get(function() {
return stub;
});
In this way you have stubbed the method returned, not just the getter.
Same goes for the spy.
let spy = sinon.spy(object, "method");
// the getter has to return the actual spy of the method,
sinon.stub(object, "action").get(function() {
return spy;
});
Given the additional complexities, I wrote some helper methods.
import sinon from 'sinon';
/**
* Stubs a method decorated with @action
*
* @param {object} object - object that has the action
* @param {string} action - name of the method that is an action
* @param {function | sinon.stub} [fakeOrStub=sinon.stub] - this is the function you want the stub to call
* or a sinon.stub you have already created (this allows sinon.stub().withArgs for ex
* or if not passed, will be sinon.stub()
* @returns {sinon.stub}
*/
export function actionStub(object, action, fakeOrStub = sinon.stub()) {
let fakeStub = fakeOrStub.callsFake ? fakeOrStub : sinon.stub().callsFake(function() { return fakeOrStub; });
sinon.stub(object, action).get(fakeStub);
return fakeStub;
}
/**
* Spies on a method decorated with @action
*
* @param {object} object - object that has the action
* @param {string} action - name of the method that is an action
* @param {sinon.spy} [spy=sinon.spy] - a spy you have already created, allows for sinon.spy().withArgs for ex
* @returns {sinon.spy}
*/
export function actionSpy(object, action, spy) {
let actionSpy = spy || sinon.spy(object[action]);
let s = actionStub(object, action, actionSpy);
return actionSpy;
}
Still validating that the helper methods will work for more complex use cases. Will hope for a PR eventually, that amends the readme and supplies these helpers but wanted to get this out there in case someone needed it.
@action is usually used in components, and as such the integration test should not be stub/spying the actual actions. This is most useful when actions are used in services.
ember-sinon
is a dependency of this project. It is also added to the host app in the blueprint install addAddonToProject('ember-sinon')
. This is unnecessary and could cause confusion when the versions get out of sync.
TypeError: log.gauge.isEnabled is not a function on ember install ember-sinon-qunit with ember-cli: 2.11.1
Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.
I was wondering if there was a way of using the "Fake timers" of Sinon with this plugin. I'm guessing it's possible at the moment, but requires the usual manual cleanup. Would it be possible to integrate it with this plugin?
To see what happens to your code in Node.js 10, Greenkeeper has created a branch with the following changes:
.travis.yml
package.json
files, so that was left aloneIf youโre interested in upgrading this repo to Node.js 10, you can open a PR with these changes. Please note that this issue is just intended as a friendly reminder and the PR as a possible starting point for getting your code running on Node.js 10.
Greenkeeper has checked the engines
key in any package.json
file, the .nvmrc
file, and the .travis.yml
file, if present.
engines
was only updated if it defined a single version, not a range..nvmrc
was updated to Node.js 10.travis.yml
was only changed if there was a root-level node_js
that didnโt already include Node.js 10, such as node
or lts/*
. In this case, the new version was appended to the list. We didnโt touch job or matrix configurations because these tend to be quite specific and complex, and itโs difficult to infer what the intentions were.For many simpler .travis.yml
configurations, this PR should suffice as-is, but depending on what youโre doing it may require additional work or may not be applicable at all. Weโre also aware that you may have good reasons to not update to Node.js 10, which is why this was sent as an issue and not a pull request. Feel free to delete it without comment, Iโm a humble robot and wonโt feel rejected ๐ค
There is a collection of frequently asked questions. If those donโt help, you can always ask the humans behind Greenkeeper.
Your Greenkeeper Bot ๐ด
I noticed in some embroider builds I'm doing, sinon does not seem to automatically restore between tests, when I stub certain values
For example
import config from 'my-application/config/environment'
import sinon from 'sinon'
...
test('it does a thing', async function (assert) {
sinon.stub(config, 'showThing').value(true)
await render('<MyComponent />')
assert.dom('.thing').exists()
})
test('it does something else', async function (assert) {
// config.showThing is still true from the above test!
await render('<MyComponent />')
})
If I place a sinon.restore()
at the end of the first test, or place it in an afterEach, both tests will pass (regardless of test order).
My test-helper.js file looks like this
import config from 'my-application/config/environment'
import Application from 'my-application/app'
import { setApplication } from '@ember/test-helpers'
import * as QUnit from 'qunit'
import { setup as setupQunitDom } from 'qunit-dom'
import setupSinon from 'ember-sinon-qunit'
import start from 'ember-exam/test-support/start'
setupQunitDom(QUnit.assert)
setApplication(Application.create(config.APP))
setupSinon()
start({
setupTestIsolationValidation: true,
})
Is this a misconfiguration on my part, or an issue with the addon under embroider?
Very cool project.
I was trying it out in an addon, and I noticed that the import statement described in the README doesn't work. Instead of
import test from 'my-addon/tests/ember-sinon-qunit/test';
addons must use
import test from 'dummy/tests/ember-sinon-qunit/test';
Could you update the README to include this information please?
https://github.com/elwayman02/ember-sinon-qunit/actions/runs/6699988924/job/18205121851
addon-test-support/sinon-sandbox.ts:1:17 - error TS1484: 'SinonFakeTimers' is a type and must be imported using a type-only import when 'verbatimModuleSyntax' is enabled.
1 import sinon, { SinonFakeTimers, SinonSandbox } from 'sinon';
~~~~~~~~~~~~~~~
addon-test-support/sinon-sandbox.ts:1:34 - error TS1484: 'SinonSandbox' is a type and must be imported using a type-only import when 'verbatimModuleSyntax' is enabled.
1 import sinon, { SinonFakeTimers, SinonSandbox } from 'sinon';
~~~~~~~~~~~~
addon-test-support/sinon-sandbox.ts:2:10 - error TS1484: 'FakeTimerInstallOpts' is a type and must be imported using a type-only import when 'verbatimModuleSyntax' is enabled.
2 import { FakeTimerInstallOpts } from '@sinonjs/fake-timers';
Branch | Build failing ๐จ |
---|---|
Dependency | loader.js |
Current Version | 4.4.1 |
Type | devDependency |
This version is covered by your current version range and after updating it in your project the build failed.
As loader.js is โonlyโ a devDependency of this project it might not break production or downstream projects, but โonlyโ your build or test tools โ preventing new deploys or publishes.
I recommend you give this issue a high priority. Iโm sure you can resolve this ๐ช
The new version differs by 7 commits.
094e20b
release v4.5.0 ๐
db2f6a6
Merge pull request #126 from ember-cli/moduleId
204838b
rename mod.name => mod.id
4fa0fe0
add require.moduleId to allow a module to know its ID
f62bc54
Merge pull request #121 from ember-cli/define-exports
d963886
Update README.md
928e18f
add define.exports
See the full diff
There is a collection of frequently asked questions and of course you may always ask my humans.
Your Greenkeeper Bot ๐ด
In the past the use of the wrapped test/only would setup sinon to use QUnit's assertions for sinon's assertions. This was a big win as sinons assertion API is far superior, more readable, and offered better messaging then doing so manually via QUnit.assert.
However these helpers have been deprecated and the official documentation is to use the setupSinon
which does not call commonConfig
and therefor does not setup the assertion methods. This means that use of sinon's assertion API will not reflect in the QUnit reporting when they pass and will halt a test from continuing asserts because the default is to throw instead of fail like QUnit usually does.
Can setupSinon
include this very minor but much wanted setup. It follows the same pattern as sinon's qunit integration guidelines.
Thank you.
Is there any reason we couldn't use ember-auto-import to pull in sinon instead of ember-sinon? Since we're making a large overhaul to the package, this seems like a good time to revisit whether that dependency is still necessary. @scalvert do you have thoughts on this?
Filed over there as well: csantero/ember-sinon#181
We need to run this addon against the latest Ember blueprint with ember-cli-update.
Hey I notice that this lib isn't exposing the lodex module from sinon so e.g. I can't do this.useFakeTimers()
or this.clock.<tick|etc>
Would it make sense to expose this as it's part of sinon? (despite also being an external module)
I can probably fix this and send a PR, but I wanted to log it somewhere before I forget.
try {
result = callback.apply(this, args);
} catch (e) {
exception = e;
}
if (!doneIsWrapped) {
if (typeof exception !== "undefined") {
sandbox.restore();
throw exception;
} else {
sandbox.verifyAndRestore();
}
}
I'm on a component integration test, I return a promise, I would expect things to wait, however, sinon restores all my stubs before my tests completes.
When the addon/ package gets published to NPM, it has no README, since the README lives at the root of this repo. We should ensure there's a symlink in addon/
which makes the README contents accessible to when publishing to npm (or vice versa, move the README to addon/
and symlink it up to the root).
Hello, not sure if this is specific to using this package or not but Im having trouble accessing my app's config from inside a unit test...
import { moduleFor } from 'ember-qunit'
import test from 'client-web/tests/ember-sinon-qunit/test'
import config from 'client-web/config/environment'
import startApp from '../../helpers/start-app'
moduleFor 'service:wamp',
beforeEach: =>
App = startApp()
App.config = config
test 'it gets a new connection when `getConnection` method is called', (assert)->
service = @subject()
service.getConnection()
debugger
assert.ok service
It seems like it is being set inside my beforeEach
but neither App
nor the config
itself are available from inside my test... any ideas on why or how to get it in there?
Thanks
Qunit provides an only
function to run a single test. This would be really helpful.
I was upgrading this addon on an app that uses ember-cli-deprecation-workflow to error on deprecation by default. I noticed our app uses import test from 'ember-sinon-qunit/test-support/test';
but this was not raising a deprecation.
It looks like the deprecation syntax is being used incorrectly - as it stands now, the options
object is being used as the test
boolean and will always be truthy (no deprecation raised):
deprecate(
'This pattern is now deprecated. Please import the `setupSinon` method instead.',
{
id: 'ember-sinon-qunit.test'
}
);
Should be:
deprecate(
'This pattern is now deprecated. Please import the `setupSinon` method instead.',
false,
{
id: 'ember-sinon-qunit.test'
}
);
I'm happy to submit a PR, just wanted to confirm in case this was deliberate.
7.4.2
to 7.4.3
.๐จ View failing branch.
This version is covered by your current version range and after updating it in your project the build failed.
ember-cli-babel is a direct dependency of this project, and it is very likely causing it to break. If other packages depend on yours, this update is probably also breaking those in turn.
There is a collection of frequently asked questions. If those donโt help, you can always ask the humans behind Greenkeeper.
Your Greenkeeper Bot ๐ด
@SergeAstapov now that we moved to the workspace format, our release-it config isn't working properly. It only bumped the root package.json and not the sub-packages to the new version, and it didn't run npm publish
for the package at all. Any idea what needs to be done to keep our release scripts working with this new project layout?
Hello,
I have installed this and then done the following but it doesn't seem to be importing...
import { moduleFor } from 'ember-qunit'
import test from 'clientweb/tests/ember-sinon-qunit/test'
moduleFor 'service:wamp', {}
# Replace this with your real tests.
test 'it gets a new connection when `initiate` method is called', (assert)->
service = @subject()
debugger
assert.ok service
why is the import app/tests/ember-sinon-qunit/test
? that folder doesnt exist
I am trying to get started with ember-sinon-quint
I have an auto-generated controller test, and running ember test passes all tests
I replaced 'test' with ember-sinon-qunit, so my imports now look like this:
import moduleFor from 'ember-qunit'; import test from 'ember-sinon-qunit/test-support/test';
That's the only change I've made.
I run ember test again and I get:
not ok 27 PhantomJS 2.1 - Global error: Error: TypeError: Object is not a function (evaluating '(0, _emberQunit['default'])') at http://localhost:7357/assets/test-support.js, line 4614 --- Log: | { type: 'error', text: 'Error: \nTypeError: Object is not a function (evaluating \'(0, _emberQunit[\'default\'])\') at http://localhost:7357/assets/test-support.js, line 4614\n' }
I'm using Ember-CLI 2.11.1 (Ember 2.11.0, Ember Data 2.11.1, node: 6.9.5)
When installing:
warning " > [email protected]" has incorrect peer dependency "ember-source@^3.28.0 || ^4.0.0".
Suggested fix for package.json:
"peerDependencies": {
"ember-source": "^3.28.0 || ^4.0.0 || >=5.0.0",
"qunit": "^2.0.0",
"sinon": "^15.0.3 || ^16.0.0"
},
after upgrading ember-qunit to 8.0.1 I get the following error when trying to run the tests for our app
Uncaught Error: QUnit has already been defined.
I've tried reproducing this in a fresh ember app - ember-qunit 8.0.1 works until I installed ember-sinon-qunit (7.1.4).
In vanilla ember + qunit once can do:
moduleForComponent('my-component', 'Integration | Component | my component', {
integration: true,
beforeEach() {
this.register('service:thing', thingService);
this.inject.service('thing', { as: 'thingService' });
}
});
test('it renders', function(assert) {
// this.subject has thingService injected into it
});
How can we achieve this with ember-sinon-qunit where thingService is a spy/stub?
Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.
7.3.0
to 7.3.1
.๐จ View failing branch.
This version is covered by your current version range and after updating it in your project the build failed.
sinon is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.
The new version differs by 6 commits.
3812a7d
Update docs/changelog.md and set new release id in docs/_config.yml
93bef55
Add release documentation for v7.3.1
e02c192
7.3.1
8ee1d35
Update CHANGELOG.md and AUTHORS for new release
bc53d82
Fix security issues
1a09166
Update @sinonjs/samsam to v3.3.1
See the full diff
There is a collection of frequently asked questions. If those donโt help, you can always ask the humans behind Greenkeeper.
Your Greenkeeper Bot ๐ด
Notice the Service Mixin name is not mentioned but instead the generic label: "TestLoader Failures".
Tried both replacing test
as well as having both test
and sinonTest
but both report without the correct label and the module can't be found with its correct label, in this case: "Unit | Service | i18n", in the module list dropdown.
It does however, show up under "TestLoader Failures".
Also rebooted the app in case that was the issue.
Running
Ember: 2.4.3
jQuery: 2.2.2
ember-sinon-qunit: 1.3.0
ember-sinon: 0.5.0
Not sure, if I'm missing something in my setup but I followed the install steps on the README.
https://github.com/scalvert/ember-sinon-sandbox
This addon has great awareness of the latest Ember testing patterns, and ember-sinon-qunit can benefit from adopting some of these approaches.
We should probably detail a few things to understand better how to merge:
Ping @scalvert for thoughts here. :)
cc: @scalvert
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.