Ember.js - Acceptance tests UnrecognizedURLError: /tests

Ember.js - Acceptance tests UnrecognizedURLError: /tests

最近将 Ember CLI 从 2.15.0 迁移到 3.7.0,验收测试严重倒退。 运行 qunit codemod,以下问题似乎仍然存在:UnrecognizedURLError: /tests

我已通过以下验收测试对问题进行了最小再现:

import { module, test } from 'qunit';
import { visit, currentURL } from '@ember/test-helpers';
import { setupApplicationTest } from 'ember-qunit';
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';


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

  test('visiting /poc', async function(assert) {
    await visit('/');

    assert.equal(currentURL(), '/');
  });
});

这导致以下三个问题:

Promise rejected before "visiting /poc": /tests?filter=poc
Source:     UnrecognizedURLError: /tests?filter=poc 
beforeEach failed on visiting /poc: You must call one of the ember-qunit setupTest(), setupRenderingTest() or setupApplicationTest() methods before calling setupMirage()
Source:     Error: You must call one of the ember-qunit setupTest(), setupRenderingTest() or setupApplicationTest() methods before calling setupMirage()
Promise rejected after "visiting /poc": Cannot use 'in' operator to search for 'destroy' in undefined@ 80 ms
Source:     TypeError: Cannot use 'in' operator to search for 'destroy' in undefined

如有任何建议,我们将不胜感激!

正如@jelhan 在上面的评论中指出的,这里的问题是 environment.js 配置中缺少 test 环境设置。

修复UnrecognizedURLError,添加ENV.locationType = 'none'满足testem的要求。

我还替换了链接 block 中找到的其他环境变量。

我的测试环境配置现在如下所示:

else if(environment === 'test') {
    ENV.locationType = 'none';
    ENV.APP.LOG_ACTIVE_GENERATION = false;
    ENV.APP.LOG_VIEW_LOOKUPS = false;
    ENV.APP.rootElement = '#ember-testing';
    ENV.APP.autoboot = false;
  }