Mxl_Test.ts 1.6 KB

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