0
我一直在這一整天,並且幾乎沒有取得任何進展。我有一個採用文本代碼的Javascript解釋器,我試圖用Karma-Jasmine測試來測試這個。因爲我不想在每個規範中嵌入代碼,所以我試圖從外部文本文件中加載這些項目。在Karma-Jasmine測試中獲取外部文本文件的內容
到目前爲止,我已經在karma.config.json中創建了一個文件夾,但我似乎無法弄清楚如何實際將其讀入到Javascript字符串中。
這裏有一個樣品規格:
jasmine.getFixtures().fixturesPath = 'base/codeFiles';
var testCode = loadFixtures("base/codeFiles/correct_1.txt");
console.log(f);
describe("#interpreter_load_test", function() {
it("loads the code correctly", function() {
var INTERPRETER = getInterpreter();
INTERPRETER.initialize();
INTERPRETER.loadCode(testCode);
var codeObj = INTERPRETER.code;
var numLines = codeObj.codeLength;
var loadedCode = codeObj.codeString;
expect(numLines).toBe(16);
expect(loadedCode).toBe(testCode);
});
});
這裏是我的karma.config.json
// Karma configuration
// Generated on Sat Jun 20 2015 21:46:22 GMT+0000 (UTC)
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: ['jasmine-jquery', 'jasmine'],
// list of files/patterns to load in the browser
files: [
'js/build/production.min.js',
'js/tests/*.js',
{
pattern: 'codeFiles/*.txt',
watched: true,
served: true,
included: false,
}
],
// 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 results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['progress'],
// 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: true,
// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['PhantomJS', 'Chrome', 'Firefox', 'IE', 'Safari'],
// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: false,
proxies: {
'/codeFiles': 'http://localhost:9876/base/codeFiles',
},
});
};
我敲我的頭靠在牆上,在這一點上,所以任何幫助將不勝感激。