question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support for new test syntax

See original GitHub issue

Has anyone got integration tests working for their (lazy) engine, with the new test syntax?

I get the error that xxxx is not a helper. I guess it is because setApplication sets the dummy app, in which the components themselves are not directly registered?

I somehow got it to work with this pretty hacky code:

import Resolver from '../../resolver';
import { setResolver } from '@ember/test-helpers';

const modulePrefix = 'my-engine-name';
const resolver = Resolver.create();

export default function setupResolver(hooks) {
  // Manually fix the entries for the engines so they can be found by the resolver
  // Put everything from the my-engine-name namespace into dummy as well
  // E.g. my-engine-name/components/my-component becomes dummy/components/my-component
  let modules = resolver._moduleRegistry._entries;

  let newModules = {};
  let overwriteModules = {};
  let originalModules = {};

  Object.keys(modules).forEach((module) => {
    if (module.startsWith(modulePrefix)) {
      let newName = `dummy/${module.substr(modulePrefix.length + 1)}`;

      if (!modules[newName]) {
        newModules[newName] = modules[module];
      } else {
        originalModules[newName] = modules[module];
        overwriteModules[newName] = modules[module];
      }
    }
  });

  hooks.beforeEach(function() {
    Object.keys(newModules).forEach((module) => {
      modules[module] = newModules[module];
    });
    Object.keys(overwriteModules).forEach((module) => {
      modules[module] = overwriteModules[module];
    });
  });

  hooks.afterEach(function() {
    Object.keys(newModules).forEach((module) => {
      delete modules[module];
    });
    Object.keys(overwriteModules).forEach((module) => {
      modules[module] = originalModules[module];
    });
  });

  return setResolver(resolver);
}

and then, in my integration tests:

import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import setResolver from 'dummy/tests/helpers/set-resolver';
// ... other dependencies

module('Integration | Component | my test component', function(hooks) {
  setupRenderingTest(hooks);
  setResolver(hooks);

  // actual tests go here
});

I’m sure there is a better way, but I’m not sure what it is 😉

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:12 (9 by maintainers)

github_iconTop GitHub Comments

4reactions
buschtoenscommented, Aug 14, 2018

I was just about to paste this code based on the ember-asset-loader README:

import Application from '../app';
import config from '../config/environment';
import { setApplication } from '@ember/test-helpers';
import { start } from 'ember-qunit';
import preloadAssets from 'ember-asset-loader/test-support/preload-assets';
import manifest from 'dummy/config/asset-manifest';

preloadAssets(manifest);
setApplication(Application.create(config.APP));

start();

Didn’t know that this is a promise, thanks!

For the impatient Googler, the correct code is:

// tests/test-helper.js
import Application from '../app';
import config from '../config/environment';
import { setApplication } from '@ember/test-helpers';
import { start } from 'ember-qunit';
import preloadAssets from 'ember-asset-loader/test-support/preload-assets';
import manifest from 'dummy/config/asset-manifest';

setApplication(Application.create(config.APP));

preloadAssets(manifest).then(start); // This ensures all engine resources are loaded before the tests
2reactions
SergeAstapovcommented, Mar 24, 2020

Once we upgraded Ember Data and Ember.js to 3.16, using setupTest(hooks, { resolver }); approach in engine unit/rendering tests results in deprecation message being triggered by Ember Data:

This test relies on a deprecated test setup that is no longer supported by EmberData. To resolve this you will need to be on a recent version of @ember/test-helpers AND your tests must use `setApplication()` instead of `setResolver()` and `module()` with `setup*Test()`instead of `moduleFor*()`. [deprecation id: ember-data:legacy-test-helper-support]

triggered from here https://github.com/emberjs/data/blob/85dbc55e7989157307ab897ac0b126bd777a724b/packages/-ember-data/addon/setup-container.js#L13

Looking into what happens when resolver is provided to setupTest, looks like it cases buildOwner function to use legacyBuildRegistry function:

https://github.com/emberjs/ember-test-helpers/blob/master/addon-test-support/%40ember/test-helpers/setup-context.ts#L197 https://github.com/emberjs/ember-test-helpers/blob/master/addon-test-support/%40ember/test-helpers/build-owner.ts#L54

Looks like with new Ember versions using the approach suggested in above comment is not gonna work moving forward and we need to find a new solution that would work with New Testing Style helpers (which should happen with #653).

Read more comments on GitHub >

github_iconTop Results From Across the Web

test — Regression tests package for Python — Python 3.11.1 ...
The test package contains all regression tests for Python as well as the modules test.support and test.regrtest. test.support is used to enhance your...
Read more >
Testing - Spring
This chapter covers Spring's support for integration testing and best practices for unit testing. The Spring team advocates test-driven ...
Read more >
New-Service (Microsoft.PowerShell.Management)
The New-Service cmdlet creates a new entry for a Windows service in the registry ... Service" StartupType = "Manual" Description = "This is...
Read more >
Writing and Organizing Tests - Cypress Documentation
What you'll learn How to organize your test and support files. ... After adding a new project, Cypress will automatically scaffold out a...
Read more >
BDD test syntax | Developer Guide - Nightwatch.js
test() / it() / specify(); before(); after(); beforeEach(); afterEach(). Nightwatch doesn't support ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found