1

My PhantomJS Runner does not seem to be aware of esModules.

my es2015 code is parsed by babel.js and turned into es5 code When i run the qunit-phantomjs-runner, I get this error

..../myapp/node_modules/phantomjs/lib/phantom/bin/phantomjs ..../myapp/node_modules/qunit-phantomjs-runner/runner.js file:////..../myapp/tests/index.html
ReferenceError: Can't find variable: require

  file:////..../myapp/.tmp/js/app.js:5

Test failed: global failure
    Failed assertion: TypeError: 'undefined' is not an object (evaluating 'App.rootElement = '#ember-testing'')
file:////..../myapp/tests/tests.js:2

Here is the 'TestSuite' That i pass into phantomjs through this command in the runner:

page = require('webpage').create();
...
...
page.open(url, function (status) { ... }); //url is the test/index.html file

Here is the index.html file itself:

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Ember Starter Kit</title>
  <link rel="stylesheet" href="runner.css">
  <link rel="stylesheet" href="../bower_components/qunit/qunit/qunit.css">
</head>
<body>
  <div id="qunit"></div>
  <div id="qunit-fixture"></div>
  <div id="ember-testing-container">
    <div id="ember-testing"></div>
  </div>

  <script src="../bower_components/jquery/dist/jquery.js"></script>
  <script src="../bower_components/ember/ember.debug.js"></script>
  <script src="../.tmp/js/compiled-templates.js"></script>
  <script src="../.tmp/js/app.js"></script>
  <script src="../bower_components/qunit/qunit/qunit.js"></script>
  <script src="tests.js"></script>
</body>
</html>

and the code causing the problem:

/* global Ember */

'use strict';

var _ember = require('ember'); // <--- breaks at this line, also if i try to access exports variable

var _ember2 = _interopRequireDefault(_ember);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var App = _ember2.default.Application.create();

App.Router.map(function () {});

App.IndexRoute = _ember2.default.Route.extend({
  model: function model() {
    return ['red', 'yellow', 'blue'];
  }
});

similar questions aren't much help to me.

I'm using

  • "babel-core": "^6.4.5"
  • "babel-preset-es2015": "^6.3.13"
  • "gulp-qunit": "^1.3.0"
  • "gulp": "^3.9.0"
  • "phantomjs": "^1.9.0"
Community
  • 1
  • 1
coderatchet
  • 8,120
  • 17
  • 69
  • 125

0 Answers0