-
-
Notifications
You must be signed in to change notification settings - Fork 69
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
Add support for new RFC268 based testing API #190
Conversation
@@ -1,7 +1,6 @@ | |||
/* eslint-env node */ | |||
module.exports = { | |||
browsers: [ | |||
'ie 9', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just to run our test suite with native async/await. Without that change, it would get transpiled, but then it failes because of the missing regenerator runtime. As we are testing in Chrome anyways, I though to just use the native implementation. FWIW, ember-qunit does the same
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, but changing the support matrix would need a major version bump and I'd like to avoid that for now.
we can't use async/await in this lib because then we would require that our users also support it natively or via regenerator. we can use it in the test suite (of the test suite 🙈), but then we should use ember-maybe-import-regenerator-for-testing
and the corresponding linting to make sure that we definitely do not use it in prod code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added async/await only to the test suite, so users should not be affected by this! And this is the targets.js
file of the dummy app, so only affecting our test builds, not that of users. So I think that should be fine?
I agree we have to make sure linting catches accidental use of async/await in the lib code itself, I will check this...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to write that removing it would prevent us from catching IE9 bugs in CI, but then I realized how much bullshit that was... 😆
seems fine, thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, unless you want to enter a world of pain, and use saucelabs, that would not really work! 😉
(heard browserstack would be better, but never tried it)
tests/unit/setup-unit-test-test.js
Outdated
|
||
describe('setupUnitTest', function() { | ||
|
||
describe('comtext setup', function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo
tests/unit/setup-unit-test-test.js
Outdated
|
||
setTimeout(resumeTest, 200); // resume test after timeout | ||
// make sure pauseTest does not wait forever, if resumeTest fails | ||
let timer = setTimeout(() => expect(false, 'resumeTest() did not work').to.be.true, 300); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
did you check that this assertion works as expected if resumeTest()
does indeed not work?
I think we should just throw new Error('resumeTest() did not work')
instead of the always-failing assertion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
did you check that this assertion works as expected if resumeTest() does indeed not work?
Yes, kind of. I removed the previous line (setTimeout(resumeTest, 200);
), so not calling resumeTest()
, and the assertion catched that.
I think we should just throw new Error('resumeTest() did not work') instead of the always-failing assertion
Yeah, I tried that before, but somehow it was not working. Do you know, does chai just throw if the assertion fails, or is there some other magic going on? If not, I can try again...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
chai just throws exceptions (AssertionError
), nothing else as far as I'm aware. It's a relatively simple system compared to QUnit.
@@ -27,3 +40,59 @@ export { | |||
it, | |||
setResolver | |||
}; | |||
|
|||
export function setupUnitTest(options) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we move these implementations to dedicated files?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure
import { | ||
TestModule, | ||
TestModuleForModel, | ||
TestModuleForComponent, | ||
TestModuleForAcceptance | ||
} from 'ember-test-helpers'; | ||
import { assign } from '@ember/polyfills'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is not available yet in Ember 2.0 and 2.4. I would prefer to make this a non-breaking change so if we can work around it by falling back to merge
that would be great.
this is causing the CI failure btw :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I saw that. Will fix it.
2f6dfc9
to
bc164f2
Compare
so we could export a shared |
@Turbo87 your comments should have been addressed now! Ember 2.0/2.4 is still failing, but now unrelated to the |
|
||
afterEach(function() { | ||
return teardownApplicationContext(this); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wouldn't this have to be written before the setupUnitTest()
call due to the FIFO ordering?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, maybe yes, good catch! Right now it does not make a difference I think, because the implementation of teardownApplicationContext
does not depend on it. But we should probably not rely on this...
I suppose we won't have a solution that "just works" for the general ordering problem? (other than to document it properly)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose we won't have a solution that "just works" for the general ordering problem?
I do have an idea...
let hooks = setupTest();
hooks.beforeEach(function() { ... });
hooks.afterEach(function() { ... });
setupTest()
maintains its own FIFO/LIFO queues and exposes them by returning an object with before/afterEach
functions. The additional advantage is that the API becomes even closer to QUnit.
The disadvantage is that for Mocha users calling hooks.afterEach
is unusual, but since this feature is only needed as an escape valve and probably shouldn't be needed by most endusers this might be fine 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As the user has to be made aware of the problem anyway, and be told to use this (as you also mention) rather unusual way, I wonder if it is not equally appropriate and less "magic" to just tell them to move their afterEach
calls before the setupTest()
call?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move their afterEach calls before the setupTest() call?
that is not an option if you want to provide e.g. a setupPretender(hooks)
helper that needs to setup both hooks
and it puts the hooks entirely out of order which isn't particularly nice to read :(
good point. yes, I guess in that case we can just skip those tests for now until we drop support for those Ember versions. |
Seems you can skip the name, and just supply an options object: https://github.com/emberjs/ember-mocha/blob/master/addon-test-support/ember-mocha/setup-test-factory.js#L9-L12 And as |
1ab1f6e
to
9368345
Compare
@Turbo87 finally green! 😀 recent changes:
|
} | ||
|
||
// copy over the original values | ||
_assign(this, originalContext); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we have to reset originalContext
to {}
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just fixed this in beforeEach
, to prevent accidental leaks. Though I don't think it makes much of a difference in practice. I tried for quite some time to find a test case that would have been affected by this, but somehow didn't succeed ;)
9368345
to
eae10ac
Compare
eae10ac
to
cf73491
Compare
@rwjblue @Turbo87 here's a first attempt at implementing the new testing APIs for Mocha, as we discussed recently on Slack.
@rwjblue your gist was working almost perfectly! 👍
I added few tests, for application and rendering more or less based on the existing ones. For
setupUnitTest
some more specific cases. Tell me if you feel there is something missing!Nevertheless there are some problems:
setupTest()
, as it is called inember-qunit
, is already taken byember-mocha
for the old APIs. I named the function for nowsetupUnitTest
. Would have been nice to having matching names, but seems we cannot do this in this case.setup*Test()
, see here. I think that's what you were chatting about at the end of the recent conversation, right? 🤔