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

Make test context reusable during a test #1511

Merged
merged 3 commits into from
Nov 8, 2024
Merged

Conversation

eliasdawson
Copy link
Contributor

@eliasdawson eliasdawson commented Oct 22, 2024

In v2.0.0 @ember/test-helpers refactored to use @ember/destroyable for teardown which also meant
that the application context was destroyed during teardown, where previously it was only cleaned up
and the application (context.owner) was destroyed.

In our application tests we simulate a page refresh by calling teardownContext and
setupContext. The destroyable change broke this functionality because the context is now marked
as destroyed.

This commit effectively reverts the change to use @ember/destroyable and adds tests to ensure that
the context is not destroyed so that it can be reset during a test.

This addresses #1452 raised by @mixonic

The @ember/destroyable change was made in #914

In v2.0.0 @ember/test-helpers refactored to use
@ember/destroyable for teardown which also meant
that the application context was destroyed during
teardown, where previously it was only cleaned up
and the application was destroyed.

In our application tests we simulate a page
refresh by calling `teardownContext`` and
`setupContext`. The destroyable change broke this
functionality because the context is now marked
as destroyed.

This commit effectively reverts the change to use
@ember/destroyable and adds tests to ensure that
the context is not destroyed so that it can be
reset during a test.
@@ -1,5 +1,7 @@
import type { TestContext } from './setup-context';
import settled from './settled.ts';
import Ember from 'ember';
Copy link
Collaborator

Choose a reason for hiding this comment

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

we cannot import from ember as it's planned to be deprecated soonish in the v6 series.

See: emberjs/rfcs#1003

the RFC also has a big list of alternate ways to get what you need though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good to know. This isn't new though, just moved from setup-context.ts and there are several other imports currently in the repo.

Also this project is setting Ember.testing, I only see an alternative for checking it.

@NullVoxPopuli
Copy link
Collaborator

NullVoxPopuli commented Oct 22, 2024

first, hello!!!!

second,

wouldn't we want "refresh" to mean you get a whole new context?

a destroy + new one?

(as close to actual page refresh as possible?)

@eliasdawson
Copy link
Contributor Author

first, hello!!!!

second,

wouldn't we want "refresh" to mean you get a whole new context?

a destroy + new one?

(as close to actual page refresh as possible?)

Hello, yourself :)

I don't think we do want a new context. We only want a new app (context.owner). The context is the qunit context passed in from ember-qunit and has things like pauseTest and other test setup which we would want to preserve.

@NullVoxPopuli
Copy link
Collaborator

that makes sense!

*/
if (isChrome) {
clickSteps.push('selectionchange');
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is unrelated to the context reuse issue but fixes test failures currently on master. Since tests are running on Chrome 130 now, I assume this is safe to remove.

@@ -30,7 +32,14 @@ export default function teardownContext(
.then(() => {
_cleanupOnerror(context);

destroy(context);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think the only potential impact of this change would be that if consumers are calling registerDestructor on the context for their own cleanup, then that would break and they would need to call it on context.owner instead.

_teardownAJAXHooks();

// SAFETY: this is intimate API *designed* for us to override.
(Ember as any).testing = false;
Copy link
Collaborator

Choose a reason for hiding this comment

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

since this wasn't here before, can we remove it 😅

Copy link
Collaborator

Choose a reason for hiding this comment

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

oh apologies, you said it was from here: https://github.com/emberjs/ember-test-helpers/pull/1511/files#diff-93af636d6cd5ada55ea13d76db06d4e9447f451caae3fd2dc83a7cd4783bd385L223

ok. nevermind.

This needs some thinking unrelated to this PR

@eliasdawson
Copy link
Contributor Author

Any updates/concerns on merging this?

Copy link
Collaborator

@NullVoxPopuli NullVoxPopuli left a comment

Choose a reason for hiding this comment

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

Approved, and marked as a breaking change (due to the risk of folks registering destructors on context)

@mixonic mixonic merged commit cbbadbe into emberjs:master Nov 8, 2024
24 checks passed
@github-actions github-actions bot mentioned this pull request Nov 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants