Browse Source

fix karma tests (npm test) by excluding util folder

sschmid 5 years ago
parent
commit
c25bb45800
2 changed files with 18 additions and 9 deletions
  1. 7 2
      karma.conf.js
  2. 11 7
      test/Util/DiffImages_Test_Experimental.ts

+ 7 - 2
karma.conf.js

@@ -15,6 +15,10 @@ module.exports = function (config) {
 
         files: [
             {
+                pattern: 'test/Util/*.ts',
+                included: false
+            },
+            {
                 pattern: 'test/**/*.ts',
                 included: true
             }, {
@@ -28,7 +32,8 @@ module.exports = function (config) {
                 included: false,
                 watched: false,
                 served: true
-            }],
+            }
+        ],
 
         // preprocess matching files before serving them to the browser
         // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
@@ -53,7 +58,7 @@ module.exports = function (config) {
             resolve: common.resolve
         },
 
-        // Required for Firefox and Chorme to work
+        // Required for Firefox and Chrome to work
         // see https://github.com/webpack-contrib/karma-webpack/issues/188
         mime: {
             'text/x-typescript': ['ts']

+ 11 - 7
test/Util/DiffImages_Test_Experimental.ts

@@ -1,6 +1,8 @@
 import { OpenSheetMusicDisplay, CanvasVexFlowBackend } from "../../src";
 import { TestUtils } from "./TestUtils";
-import * as fs from "fs";
+//import * as fs from "fs";
+
+// experimental code, shouldn't be included in Karma test suite
 
 describe("GeneratePNGImages", () => {
     // Test all the following xml files:
@@ -25,11 +27,12 @@ describe("GeneratePNGImages", () => {
         // "TelemannWV40.102_Sonate-Nr.1.2-Allegro-F-Dur.xml",
     ];
     for (const score of sampleFilenames) {
-        testFile(score);
+        generatePNG(score);
     }
 
-    // Generates a test for a mxl file name
-    function testFile(sampleFilename: string): void {
+    // TODO This is just example code for now.
+    // generate PNG. TODO fs doesn't work with Karma. This is the big problem that needs to be worked around with ts/Karma.
+    function generatePNG(sampleFilename: string): void {
         it(sampleFilename, (done: MochaDone) => {
             // Load the xml file content
             const score: Document = TestUtils.getScore(sampleFilename);
@@ -39,19 +42,20 @@ describe("GeneratePNGImages", () => {
             openSheetMusicDisplay.load(score);
 
             const testDir: string = "../data/images";
-            fs.mkdirSync(testDir, { recursive: true });
+            //fs.mkdirSync(testDir, { recursive: true });
 
             const fileName: string = `${testDir}/${sampleFilename}.png`;
+            console.log("fileName: " + fileName);
 
             console.log("before buffer");
             const canvasBackend: CanvasVexFlowBackend = openSheetMusicDisplay.Drawer.Backends[0] as CanvasVexFlowBackend;
             const imageData: string = (canvasBackend.getCanvas() as HTMLCanvasElement).toDataURL().split(";base64,").pop();
             const imageBuffer: Buffer = Buffer.from(imageData, "base64");
+            console.log("imageBuffer.length: " + imageBuffer.length);
             //console.log("after buffer");
             //let arraybuffer = Uint8Array.from(imageBuffer, 'base64').buffer;
 
-            // TODO doesn't work with Karma. This is the big problem that needs to be worked around with ts/Karma.
-            fs.writeFileSync(fileName, imageBuffer, { encoding: "base64" });
+            //fs.writeFileSync(fileName, imageBuffer, { encoding: "base64" });
 
             done();
             }).timeout(10000);