Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EmberJS tests that require data files

I am writing a test in Ember-cli 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();
});
like image 713
Asagohan Avatar asked Mar 26 '26 22:03

Asagohan


1 Answers

I placed the files under public/tests/testFiles in the ember-cli project and it merged it with the "tests" directory that was already in the dist folder. I also changed my url to tests/testFiles/exceltest.xls

I am not sure if this is the proper way to do it or not.

like image 102
Asagohan Avatar answered Mar 31 '26 10:03

Asagohan