mardi 4 août 2015

EmberJS tests that require data files

I am writing a test in Ember to test that my class can read xlsx files. However, I don't know how to tell Ember/qUnit to export the test file to the dist folder with the tests so my tests can find it when running in the browser. This is what my test looks like. But it cannot find "url" when executed because it hasn't copied the file to the dist folder. How do I tell Ember to copy the test file?

import { module, test } from 'qunit';
import Ember from 'ember';
import XlsxParser from '../../../objects/sheetParsers/XlsxParser';

module('Unit | XLSX Parser');

test('it works', function(assert) {
  var sheetParser = XlsxParser.create();
  var done1 = assert.async();
  var url = "/testFiles/excelTest.xlsx";

  var oReq = new XMLHttpRequest();
  oReq.open("GET", url, true);
  oReq.responseType = "arraybuffer";

  oReq.onload = function(e) {
    var arraybuffer = oReq.response;

    /* convert data to binary string */
    var data = new Uint8Array(arraybuffer);
    var arr = new Array();
    for(var i = 0; i != data.length; ++i) arr[i] = String.fromCharCode(data[i]);
    var binaryData = arr.join("");

    /* DO SOMETHING WITH workbook HERE */
    sheetParser.parseSheet(binaryData);
  }

  oReq.send();

  assert.ok("done");
  done1();
});




Aucun commentaire:

Enregistrer un commentaire