2017-03-15 2 views
0

Ich brauche Hilfe von JS-Experte. I'v bekam eine js-Datei:Javascript - Test lesen Datei mit Karma + PhantomJS

'use strict'; 

var fs = require('fs'); 

var Conf = {  
    read: read, 
}; 

function read() { 
    try { 
     var conf = JSON.parse(fs.readFileSync(__dirname + '/../resources/conf.json', 'utf-8')); 
     return conf; 
    } 
    catch (err) { 
     console.log('There has been an error parsing your JSON.'); 
     console.log(err); 
    } 
} 

module.exports = Conf; 

ich es testen möchten. Ich benutze Karma + Mokka. Ich habe Testdatei

'use strict'; 

var Conf = require('../../lib/Conf'); 

describe('My test', function() { 

    describe('json config', function() { 
     it('should display initially', function() { 
      console.log(Conf.read()); 
     }); 
    }); 
}); 

Aber ich immer Typeerror-Fehler, wenn Testlauf mit PhantomJS 2.1.1, wenn ich PhantomJS Chrome wechsle ich nicht definiert Fehler.

Unterstützt das Testframework require('fs');? Wenn ja, hilf mir bitte, es zu tun.

ist mein Karma Config

'use strict'; 
// Karma configuration 
// Generated on Wed Mar 15 2017 00:21:08 GMT+0300 (RTZ 2 (зима)) 

module.exports = function (config) { 
    config.set({ 

     // base path that will be used to resolve all patterns (eg. files, exclude) 
     basePath: '../../', 


     // frameworks to use 
     // available frameworks: https://npmjs.org/browse/keyword/karma-adapter 
     frameworks: ['browserify', 'mocha', 'chai', 'sinon-chai'], 


     // list of files/patterns to load in the browser 
     files: [ 
      'test/spec/**/*Spec.js' 
     ], 


     // list of files to exclude 
     exclude: [], 


     // preprocess matching files before serving them to the browser 
     // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor 
     preprocessors: {'test/spec/**/*Spec.js': [ 'browserify' ]}, 


     // test results reporter to use 
     // possible values: 'dots', 'progress' 
     // available reporters: https://npmjs.org/browse/keyword/karma-reporter 
     reporters: ['spec'], 


     // web server port 
     port: 9876, 


     // enable/disable colors in the output (reporters and logs) 
     colors: true, 


     // level of logging 
     // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG 
     logLevel: config.LOG_INFO, 


     // enable/disable watching file and executing tests whenever any file changes 
     autoWatch: false, 


     // start these browsers 
     // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher 
     browsers: ['PhantomJS'], 


     // Continuous Integration mode 
     // if true, Karma captures browsers, runs the tests and exits 
     singleRun: false, 

     // Concurrency level 
     // how many browser should be started simultaneous 
     concurrency: Infinity, 

     browserify: { 
      debug: true, 
      transform: [ [ 'stringify', { global: true, extensions: [ '.bpmn', '.xml', '.css' ] } ] ] 
     } 
    }) 
} 

mein package.json dev

deps
"devDependencies": { 
    "brfs": "^1.2.0", 
    "browserify": "^14.1.0", 
    "chai": "^3.5.0", 
    "grunt": "~1.0.1", 
    "grunt-browserify": "^5.0.0", 
    "grunt-contrib-connect": "~1.0.2", 
    "grunt-contrib-copy": "~1.0.0", 
    "grunt-contrib-jshint": "~1.0.0", 
    "grunt-contrib-less": "^1.0.1", 
    "grunt-contrib-watch": "~1.0.0", 
    "grunt-karma": "^2.0.0", 
    "karma": "^1.5.0", 
    "karma-browserify": "^5.1.1", 
    "karma-chai": "^0.1.0", 
    "karma-chrome-launcher": "^2.0.0", 
    "karma-jasmine": "^1.1.0", 
    "karma-mocha": "^1.3.0", 
    "karma-phantomjs-launcher": "^1.0.4", 
    "karma-sinon-chai": "^1.2.4", 
    "karma-spec-reporter": "0.0.30", 
    "load-grunt-tasks": "^3.5.2", 
    "mocha": "^3.2.0", 
    "sinon": "^1.17.7", 
    "sinon-chai": "^2.8.0", 
    "stringify": "^5.1.0" 
    }, 

Antwort

0

ich dieser Wert verwandeln durch Änderung Fixed:

browserify: { debug: true, transform: [ [ 'stringify', { global: true, extensions: [ '.bpmn', '.xml', '.css' ] } ] ] }

zu

browserify: { debug: true, transform: [ 'brfs' ] }

Verwandte Themen