Incompatible with Embroider 's `staticAddonTestSupportTrees` optimized mode
See original GitHub issueI’ve been testing out various addons we use in our app against Embroider and I’ve found an incompatibility between it and ember-cli-page-object.
Reproduction
Just setting up a simple page object and trying to use it in a test causes for the following test error:
Looks like you attempt to access page object property outside of test context. If that’s not the case, please make sure you use the latest version of “@ember/test-helpers”
// tests/pages/users.js
import {
create,
visitable
} from 'ember-cli-page-object';
export default create({
visit: visitable('/')
});
// tests/acceptance/index-test.js
import { module, test } from 'qunit';
import { visit, currentURL } from '@ember/test-helpers';
import { setupApplicationTest } from 'ember-qunit';
import page from 'embroider-spike/tests/pages/users';
module('Acceptance | index', function (hooks) {
setupApplicationTest(hooks);
test('visiting /index', async function (assert) {
await page.visit();
assert.equal(currentURL(), '/');
});
});
I have a branch here which recreates the issue.
- Run
yarn test:ember -s -f=visiting
. This uses Embroider and the test fails ❌ - Run
CLASSIC=true yarn test:ember -s -f=visiting
. This uses the existing build pipeline and test passes ✅
Problem
The problem looks to stem from when you enable Embroider’s staticAddonTestSupportTrees
setting.
From Embroider’s README
Enable
staticAddonTestSupportTrees
andstaticAddonTrees
and test your application. This is usually safe, because most code in these trees gets consumed via import statements that we can analyze. But you might find exceptional cases where some code is doing a more dynamic thing.
If I set this setting to false
the tests pass fine.
The error mentions to make sure to have the latest version of @ember/test-helpers
but doing a check it appears I am:
> yarn list ember-qunit
└─ ember-qunit@5.1.2
> yarn list @ember/test-helpers
└─ @ember/test-helpers@2.1.4
Some other info
I tried setting the context by calling page.setContext(this)
in the test. This progresses the test but it then fails for another reason.
Ember.emberDeprecate is not a function
I don’t think this is related to ember-cli-page-object though. I think there’s an issue with the aliasing of the function to emberDeprecate
. I’ve been able to replicate this exact thing in app code outside the context of ember-cli-page-object. I’m going to log an issue for that elsewhere.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:10 (1 by maintainers)
Keep pushing it slowly. I think I’d like to make it work on the v2 branch first, cause there should be just a bit less magic, and if there are some blockers, we’re a bit safer to adjust it there.
Currently, it’s blocked with some issues related to
buildEmberPlugins(
, which we’ve started to use in the #531. Reported it to the ember-cli-babel for now(https://github.com/babel/ember-cli-babel/issues/398).A quick update. I’ve started looking into this. The first blocker appeared is TS tests. Created a ticket for this(https://github.com/embroider-build/embroider/issues/691), Hopefuly, it’d be easy to fix.