Mxl.ts 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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 hack to
  17. // make Mocha work asynch. with "done()"
  18. extractSheetFromMxl(
  19. mxl,
  20. (score: IXmlElement) => {
  21. try {
  22. chai.expect(score).to.not.be.undefined;
  23. chai.expect(score.name).to.equal("score-partwise");
  24. } catch (e) {
  25. return done(e);
  26. }
  27. done();
  28. },
  29. (reason: any) => {
  30. done(reason.message);
  31. }
  32. )
  33. });
  34. }
  35. // Test all the following mxl files:
  36. let scores: string[] = ["MozartTrio"];
  37. for (let score of scores) {
  38. testFile(score);
  39. }
  40. });