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

Replace blueprint with explicit test helpers #392

Merged

Conversation

gilest
Copy link
Contributor

@gilest gilest commented Oct 23, 2023

Old world 🌐

Previously the following was added to an Ember CLI app when installed via ember install ember-cli-flash.

// tests/helpers/flash-message.js
import FlashObject from 'ember-cli-flash/flash/object';

FlashObject.reopen({ init() {} });
// tests/test-helper.js
import './helpers/flash-message';

Essentially importing this helper would cause the init hook of the FlashObject to become a no-op and disable the timeout running in consuming apps test runs.

It wasn't very explicit or obvious that what was happening as a result of this import. Looking at apps that I maintain, some do and some don't have this...

New world 🌏

Blueprints are not supported in V2 addons, so this PR ships two new test helpers instead.

import { disableTimeout, enableTimeout } from 'ember-cli-flash/test-support';

To get the same behaviour as "Old world 🌐 " a consuming app needs only to remove the blueprint import. ✅

However this can be changed at any time with the enableTimers function. This allows consuming apps to choose on a per-test basis whether Flash timeouts should occur – as demonstrated by the included tests.

Why not disable timeouts for all test runs? 🤔

There are many existing apps with test suites that both do and do not have timeouts disabled at present I think it's important that this is configurable for compatibility reasons.

Even this addon's own test suite tests with the timeout functionality enabled.

Other options 🤷🏻

Very open to suggestions here. Just wanted to have a known way forward to replace the existing blueprint.

Documentation

@gilest gilest force-pushed the chore/replace-blueprint branch from bcb9294 to b639f47 Compare October 23, 2023 02:06
module('FlashMessageObject disableTimeout', function (hooks) {
hooks.beforeEach(function () {
disableTimeout();
flash = FlashMessage.create({
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

@gilest gilest Oct 23, 2023

Choose a reason for hiding this comment

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

I wasn't specifically, although that will be a breaking change at some point...

Actually I'm not sure that this object is public API 🤔 so migrating it may not be a breaking change. Haven't looked into it deeply though

@gilest
Copy link
Contributor Author

gilest commented Oct 23, 2023

Self-reivew: I think we can reduce the configuration a bit here by disabling timers by default.

Edit: Yeah – adjusted so that there's no installation config needed and the upgrading steps are simpler for most users (remove a single import).

Comment on lines +7 to +9
import { enableTimeout } from 'ember-cli-flash/test-support';

enableTimeout();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The test app needs to dogfood the enableTimeout helper since it tests timeout functionality of the addon itself.

@gilest gilest requested a review from NullVoxPopuli October 23, 2023 04:12
@gilest
Copy link
Contributor Author

gilest commented Oct 23, 2023

@NullVoxPopuli please add breaking

@NullVoxPopuli NullVoxPopuli merged commit 9445543 into adopted-ember-addons:master Oct 24, 2023
@gilest gilest deleted the chore/replace-blueprint branch October 24, 2023 03:04
This was referenced Oct 24, 2023
@github-actions github-actions bot mentioned this pull request Feb 2, 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.

2 participants