Ember Acceptance Test Failing in PhantomJS but Passing in Chrome

笑着哭i 提交于 2019-12-10 19:27:51

问题


I'm trying to write an acceptance test for my Ember app and I seem to be having some trouble when it comes to PhantomJS and the Ember test server.

I'm running the following versions:

Ember      : v1.13.6
Ember Data : v1.13.7

PhantomJS is failing with the following error:

Died on test #1     at http://localhost:7357/assets/test-support.js:2934
            at http://localhost:7357/assets/test-support.js:6640
            at http://localhost:7357/assets/test-loader.js:31
            at http://localhost:7357/assets/test-loader.js:21
            at http://localhost:7357/assets/test-loader.js:40
            at http://localhost:7357/assets/test-support.js:6647: Can't find variable: DS

Is this a known issue?

The test is running fine within the chrome runner.

Here is my ember-cli-build.js (Brocfile):

/* global require, module */
var EmberApp = require('ember-cli/lib/broccoli/ember-app');

module.exports = function(defaults) {
  // Build Options
  var options = {
    // Build for development (ember s)
    development: {
      sassOptions: {
        includePaths: ['bower_components/materialize/sass']
      }
    },

    // Build for deployments
    dev_deploy: {
      sassOptions: {
        includePaths: ['bower_components/materialize/sass']
      },

      fingerprint: {
        enabled: true,
        prepend: 'redacted',
        extensions: ['js', 'css', 'png', 'jpg', 'gif', 'woff', 'ttf']
      }
    },

    // Build for deployments
    staging_deploy: {
      sassOptions: {
        includePaths: ['bower_components/materialize/sass']
      },

      fingerprint: {
        enabled: true,
        prepend: 'redacted',
        extensions: ['js', 'css', 'png', 'jpg', 'gif', 'woff', 'ttf']
      }
    },

    prod_deploy: {
      sassOptions: {
        includePaths: ['bower_components/materialize/sass']
      },

      fingerprint: {
        enabled: true,
        prepend: 'redacted',
        extensions: ['js', 'css', 'png', 'jpg', 'gif', 'woff', 'ttf']
      }
    }
  };

  var env = process.env.EMBER_ENV || 'development';

  var app = new EmberApp(defaults, options[env]);

  // IMPORTED LIBRARIES
  app.import('vendor/js/ember-uploader.named-amd.js', {
    exports: {
      'ember-uploader': [ 'default' ]
    }
  });

  app.import('vendor/js/faye-browser.js');
  app.import('vendor/js/Util.js');
  app.import('vendor/js/CanvasVirtualJoyStick.js');
  app.import('vendor/js/CanvasZoomController.js');
  app.import('vendor/js/chosen.jquery.js');

  app.import('vendor/css/chosen.css');

  return app.toTree();
};

Here is my test:

import Ember from 'ember';
import { module, test } from 'qunit';
import startApp from 'teal-turtle/tests/helpers/start-app';

var application;

module('Acceptance | platforms', {
  beforeEach: function() {
    application = startApp();
  },

  afterEach: function() {
    Ember.run(application, 'destroy');
  }
});

test('visiting /platforms', function(assert) {
  authenticateSession();
  visit('/platforms');

  andThen(function() {
    assert.equal(currentURL(), '/platforms');
  });
});

Thanks!


回答1:


I noticed you were using .bind in the route file (platform) and .bind isn't very phantomJS friendly :( so I did the following...

Added the es5 shim and broccoli funnel to your package.json

"broccoli-funnel": "^0.2.3",
"es5-shim": "^4.0.5"

Next I opened the ember-cli-build.js (prev known as the Brocfile)

var funnel = require('broccoli-funnel');
var es5Shim = funnel('node_modules/es5-shim', {
    files: ['es5-shim.js'],
    destDir: '/assets'
});

return app.toTree([es5Shim]);

And finally I added the es5 shim to your tests/index.html above vendor.js

<script src="assets/es5-shim.js"></script>

Below is a full commit on github showing all the files changed (note: Brocfile in this commit example because I'm using an older ember-cli version)

https://github.com/toranb/ember-cli-simple-store/commit/4f46a392b3be0ec93864342ba2edddbd3430e293



来源:https://stackoverflow.com/questions/31837891/ember-acceptance-test-failing-in-phantomjs-but-passing-in-chrome

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!