Mxl.ts 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import { IXmlElement } from "../../../src/Common/FileIO/Xml";
  2. import { extractSheetFromMxl } from "../../../src/Common/FileIO/Mxl.ts";
  3. describe("MXL Tests", () => {
  4. // Load the mxl file
  5. function getSheet(filename: string): string {
  6. return ((window as any).__mxl__)[filename];
  7. }
  8. // Generates a test for a mxl file name
  9. function testFile(scoreName: string): void {
  10. it(scoreName, (done: MochaDone) => {
  11. // Load the xml file content
  12. let mxl: string = getSheet("test/data/" + scoreName + ".mxl");
  13. chai.expect(mxl).to.not.be.undefined;
  14. // Extract XML from MXL
  15. // Warning: the sheet is loaded asynchronously,
  16. // (with Promises), thus we need a little fix
  17. // in the end with 'then(null, done)' to
  18. // make Mocha work asynchronously
  19. extractSheetFromMxl(mxl).then(
  20. (score: IXmlElement) => {
  21. chai.expect(score).to.not.be.undefined;
  22. chai.expect(score.name).to.equal("score-partwise");
  23. done();
  24. },
  25. (exc: any) => { throw exc; }
  26. ).then(undefined, done);
  27. });
  28. }
  29. // Test all the following mxl files:
  30. let scores: string[] = ["MozartTrio"];
  31. for (let score of scores) {
  32. testFile(score);
  33. }
  34. });