expect(() => { DFrotzInterface.validateOptions({ executable: 'test' }); expect(fs.statSync).toHaveBeenCalled(); }).toThrowError(Error, 'Invalid file - test');
it('should skip saveFile', () => { spyOn(fs, 'statSync'); DFrotzInterface.validateOptions({ saveFile: './test.sav' }); expect(fs.statSync).not.toHaveBeenCalled(); });
/** * called to generate a pre-compiled native metabase library */ function generateLibrary(options, callback) { log.info('Generating library'); var library = loadLibrary(options); // set the global platform in the typelib typelib.platform = options.platform_dir; // put the files as a child directory of the destination dir options.srcdir = path.join(options.dest,'src'); var outdir = options.outdir = path.join(options.dest,'build'); if (!fs.existsSync(options.srcdir)) { wrench.mkdirSyncRecursive(options.srcdir); } if (!fs.existsSync(options.outdir)) { wrench.mkdirSyncRecursive(options.outdir); } // by default, this is the hyperloop library options.libname = options.libname || library.getDefaultLibraryName(); var header_name = 'hyperloop' + library.getFileExtension(true) header = path.join(options.dest, header_name), header_dir = options.dest; // if we already have a header, make sure we regenerate since we have dynamic headers/source if (fs.existsSync(header)){ fs.unlinkSync(header); if (fs.existsSync(options.srcdir)) { wrench.rmdirSyncRecursive(options.srcdir); } } function proceed () { // delete any files that already exist util.filelisting(options.dest,/\.(a|so|dylib|dll|lib)$/).forEach(fs.unlinkSync); // start the generation and compilation library.prepareLibrary(options,function(err, archs, details, settings) { if (err) return callback(err); var i = 0, arch_results = {}; (function nextArch() { var arch = archs[i++]; if (arch) { // put the files as a child directory of the destination dir options.srcdir = path.join(options.dest,'src',arch); options.outdir = path.join(outdir,arch); loadSourceCache(options); // generate for each architecture library.prepareArchitecture(options, arch, details, settings, function(err, metabase) { if (err) return callback(err); // file which we are going to compile options.srcfiles = []; options.arch = arch; // set the metabase typelib.metabase = metabase; // reset to remove any cached types since we're changing metabase typelib.reset(); generateBuiltinClasses(options, arch, metabase, library); // save our source cache saveSourceCache(options); library.compileLibrary(options, arch, metabase, function(err, libfile){ if (err) return callback(err); arch_results[arch] = libfile; nextArch(); }); }); } else { library.generateLibrary(options, arch_results, settings, callback); // write out the symbol map for the library var symmap = jsgen.getSymbolMap(); fs.writeFileSync(path.join(options.dest,'library_symbols.json'),JSON.stringify(symmap,null,'\t'),'utf8'); } })(); }); } // allow the library to validate options library.validateOptions ? library.validateOptions(options, proceed) : proceed(); }
expect(() => { DFrotzInterface.validateOptions({ outputFilter: 'string' }); }).toThrowError(TypeError, 'Expected type function, got type string');
it('should not do anything for default params', () => { spyOn(fs, 'statSync'); DFrotzInterface.validateOptions({}); expect(fs.statSync).not.toHaveBeenCalled(); });