Skip to content

Commit

Permalink
stop using rfc268 adapter if not set
Browse files Browse the repository at this point in the history
While it feels natural to auto-select an offcial RFC268 test mode,
if no adapter was specified; it adds some extra internal complexity,
because of eager import of the `@ember/test-helpers`.
In theory, it's possible to not have `@ember/test-helpers` installed,
which is demonstrated in "with-ember-test-helpers" ember-try scenario.

To solve this we could use `window.require(`, to lazily import needed helpers,
only in case if `@ember/test-helpers` installed. But this aproach may leads
to some issues in Node.js envs, since `window.require` is not a thibng there.
Also I'm not sure if `window.require(` is supposed to work fine with Emberoider.

So, we go an explicit way for now, and require to import,
and set a desired adapter on the test suite side manually.
  • Loading branch information
ro0gr committed Jan 6, 2021
1 parent 7263154 commit daa0ba0
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
5 changes: 3 additions & 2 deletions addon-test-support/adapters/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import Adapter from "../adapter";
import RFC268Adapter from "./rfc268";

let _adapter;

Expand All @@ -8,7 +7,9 @@ let _adapter;
*/
export function getAdapter() {
if (!_adapter) {
return new RFC268Adapter();
throw new Error(`Adapter is required.
Please use \`setAdapter(\`, to instruct "ember-cli-page-object" about the adapter you want to use.`);
}

return _adapter;
Expand Down
6 changes: 2 additions & 4 deletions tests/acceptance/rfc268-actions-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@ import {
} from 'ember-cli-page-object';
import { alias } from 'ember-cli-page-object/macros';

import { setupApplicationTest } from 'dummy/tests/helpers'

if (require.has('@ember/test-helpers')) {
const { settled, waitUntil } = require('@ember/test-helpers');

// intentionally not using our local extension in order to make
// sure, RFC268 works by default, w/o Adapter being set.
const { setupApplicationTest } = require('ember-qunit');

module('Acceptance | actions [rfc268]', function(hooks) {
setupApplicationTest(hooks);

Expand Down
3 changes: 2 additions & 1 deletion tests/acceptance/rfc268-test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { module, test } from 'qunit';
import require from 'require';
import Rfc268Adapter from 'ember-cli-page-object/adapters/rfc268';
import { setAdapter } from 'ember-cli-page-object/adapters';
import { create, value, visitable } from 'ember-cli-page-object';

Expand All @@ -9,6 +8,8 @@ if (require.has('@ember/test-helpers')) {
// sure, RFC268 works by default, w/o Adapter being set.
const { setupApplicationTest } = require('ember-qunit');

const Rfc268Adapter = require('ember-cli-page-object/adapters/rfc268').default;

module('Acceptance | rfc268', function(hooks) {
setupApplicationTest(hooks);

Expand Down

0 comments on commit daa0ba0

Please sign in to comment.