Mxl.ts 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import { IXmlElement } from "../../../src/Common/FileIO/Xml";
  2. import { MXLtoIXmlElement } from "../../../src/Common/FileIO/Mxl.ts";
  3. import { TestUtils } from "../../Util/TestUtils";
  4. describe("MXL Tests", () => {
  5. // Generates a test for a mxl file name
  6. function testFile(scoreName: string): void {
  7. it(scoreName, (done: MochaDone) => {
  8. // Load the xml file content
  9. let mxl: string = TestUtils.getMXL(scoreName);
  10. chai.expect(mxl).to.not.be.undefined;
  11. // Extract XML from MXL
  12. // Warning: the sheet is loaded asynchronously,
  13. // (with Promises), thus we need a little fix
  14. // in the end with 'then(null, done)' to
  15. // make Mocha work asynchronously
  16. MXLtoIXmlElement(mxl).then(
  17. (score: IXmlElement) => {
  18. chai.expect(score).to.not.be.undefined;
  19. chai.expect(score.name).to.equal("score-partwise");
  20. done();
  21. },
  22. (exc: any) => { throw exc; }
  23. ).then(undefined, done);
  24. });
  25. }
  26. // Test all the following mxl files:
  27. let scores: string[] = ["MozartTrio"];
  28. for (let score of scores) {
  29. testFile(score);
  30. }
  31. // Test failure
  32. it("Corrupted file", (done: MochaDone) => {
  33. MXLtoIXmlElement("").then(
  34. (score: IXmlElement) => {
  35. chai.expect(score).to.not.be.undefined;
  36. chai.expect(score.name).to.equal("score-partwise");
  37. done(new Error("Empty zip file was loaded correctly. How is that even possible?"));
  38. },
  39. (exc: any) => { done(); }
  40. );
  41. });
  42. });