it('should use original range if not set', function() { var opts = {}; var wb1 = X.readFile(paths.fst1, opts); var wb2 = X.readFile(paths.fst2, opts); [wb1, wb2].forEach(function(wb) { assert.equal(wb.Sheets.Text["!ref"],"A1:F49"); }); });
before(function() { wb1 = X.readFile(paths.cp1); wb2 = X.readFile(paths.cp2); fullex.forEach(function(p) { X.writeFile(wb1, base + '.xlsm' + p); X.writeFile(wb2, base + '.xlsb' + p); }); });
it('should adjust range if set', function() { var opts = {sheetRows:10}; var wb1 = X.readFile(paths.fst1, opts); var wb2 = X.readFile(paths.fst2, opts); [wb1, wb2].forEach(function(wb) { assert.equal(wb.Sheets.Text["!fullref"],"A1:F49"); assert.equal(wb.Sheets.Text["!ref"],"A1:F10"); }); });
it('should not generate comment cells', function() { var opts = {sheetRows:10}; var wb1 = X.readFile(paths.cst1, opts); var wb2 = X.readFile(paths.cst2, opts); [wb1, wb2].forEach(function(wb) { assert.equal(wb.Sheets.Sheet7["!fullref"],"A1:N34"); assert.equal(wb.Sheets.Sheet7["!ref"],"A1"); }); });
var readFileSync = function(filename, options) { var f = fs.readFileSync(filename); switch(f[0]) { /* CFB container */ case 0xd0: return [XLS, XLS.readFile(filename, options)]; /* XML container (assumed 2003/2004) */ case 0x3c: return [XLS, XLS.readFile(filename, options)]; /* Zip container */ case 0x50: return [XLSX, XLSX.readFile(filename, options)]; /* Unknown */ default: return [undefined, f]; } };
it('should have comment as part of cell properties', function(){ var X = require(modp); var sheet = 'Sheet1'; var wb1=X.readFile(paths.swc1); var wb2=X.readFile(paths.swc2); [wb1,wb2].map(function(wb) { return wb.Sheets[sheet]; }).forEach(function(ws, i) { assert.equal(ws.B1.c.length, 1,"must have 1 comment"); assert.equal(ws.B1.c[0].a, "Yegor Kozlov","must have the same author"); assert.equal(ws.B1.c[0].t.replace(/\r\n/g,"\n").replace(/\r/g,"\n"), "Yegor Kozlov:\nfirst cell", "must have the concatenated texts"); if(i > 0) return; assert.equal(ws.B1.c[0].r, '<r><rPr><b/><sz val="8"/><color indexed="81"/><rFont val="Tahoma"/></rPr><t>Yegor Kozlov:</t></r><r><rPr><sz val="8"/><color indexed="81"/><rFont val="Tahoma"/></rPr><t xml:space="preserve">\r\nfirst cell</t></r>', "must have the rich text representation"); assert.equal(ws.B1.c[0].h, '<span style="font-weight: bold;">Yegor Kozlov:</span><span style=""><br/>first cell</span>', "must have the html representation"); }); });
it('should fail if ' + t + ' is missing', function() { var wb = X.readFile(paths.fst1); assert.throws(function() { delete wb[t]; X.write(wb, {type:'binary'}); }); });
// Record hash info to file async function recordHash(line) { try { // Check wether path exist const _exist = await ut.pathExist(hashListFile); const _hashList = _exist ? await ut.readFile(hashListFile) : ""; let _hasHash = false; for (let _line of _hashList.split('\n')) { if (line == _line) { _hasHash = true; break; } } if (!_hasHash) { console.log(line); await ut.appendFile(hashListFile, line+'\n'); } return; } catch(e) { throw e; } }
new Promise((resolve, reject) => { confPath = path.resolve(confPath); const processContent = (err, content) => { // Can't simulate something else than inexisting file on windows /* istanbul ignore next */ if (err) { // no file ? no conf, no problem if (err.message.indexOf(`ENOENT`) !== -1) { return resolve({}); } return reject(err); } resolve(ini.decode(content.toString('utf8'))); }; if (sync) { try { processContent(null, fs.readFileSync(confPath)); } catch (err) { processContent(err); } } else { fs.readFile(confPath, processContent); } }).
async parseFile(file: string): Promise<?DocumentNode> { let text try { text = await fs.readFile(file, `utf8`) } catch (err) { report.error(`There was a problem reading the file: ${file}`, err) return null } if (text.indexOf(`graphql`) === -1) return null const hash = crypto .createHash(`md5`) .update(file) .update(text) .digest(`hex`) try { let astDefinitions = cache[hash] || (cache[hash] = await findGraphQLTags(file, text)) return astDefinitions.length ? { kind: `Document`, definitions: astDefinitions, } : null } catch (err) { report.error( `There was a problem parsing the GraphQL query in file: ${file}`, err ) return null } }
exp: function () { //should only get both test-1 & test-2 stlyes -> compiled together -> basic.css const res = ctr.getResult(); _h.cleanCSS(res).should.equal(_h.readFile(__filename)); //since the set is reset ctr should now be empty of results and return empty string ctr.getResult().length.should.equal(0); }
it('should generate HTML by default', function() { var wb = X.readFile(paths.cst1); var ws = wb.Sheets.Sheet1; Object.keys(ws).forEach(function(addr) { if(addr[0] === "!" || !ws.hasOwnProperty(addr)) return; assert(html_cell_types.indexOf(ws[addr].t) === -1 || ws[addr].h); }); });
it('should not generate HTML when requested', function() { var wb = X.readFile(paths.cst1, {cellHTML:false}); var ws = wb.Sheets.Sheet1; Object.keys(ws).forEach(function(addr) { if(addr[0] === "!" || !ws.hasOwnProperty(addr)) return; assert(typeof ws[addr].h === 'undefined'); }); });
it('merge cells', function() { var wb1 = X.readFile(paths.mc1); var wb2 = X.read(X.write(wb1, {type:'binary'}), {type:'binary'}); var m1 = wb1.Sheets.Merge['!merges'].map(X.utils.encode_range); var m2 = wb2.Sheets.Merge['!merges'].map(X.utils.encode_range); assert.equal(m1.length, m2.length); for(var i = 0; i < m1.length; ++i) assert.equal(m1[i], m2[i]); });
new Promise((resolve, reject) => { fs.readFile(path.resolve(file), encoding || 'utf8', (err, content) => { if (err) { return reject(new Error(`Failed to load file: ${err.message}`)); } resolve(content); }); });
}, () => { gulp .src(Support.resolveSupportPath('tmp', 'models')) .pipe(helpers.readFile('user.js')) .pipe(helpers.ensureContent(targetContent)) .pipe(helpers.ensureContent('.associate')) .pipe(helpers.teardown(done)); });
load: function (path) { this.path = path = Path.resolve(System.Configs.physicalPath + System.Configs.dplbuildFilesPath, path); var content = IO.readFile(path); if (content) { this._loadDplSource(content); } },
return new Promise((resolve, reject) => { fs.readFile(pathName, 'utf8', (err, content) => { if (content) { let file = {} file[path.parse(pathName).name] = content resolve(file) } else if (err) reject(err) }) })
/** * Makes sure sauce stays running for the duration of the test suite * @param {Server} server * @param {Object} cfg * @returns {Promise} */ async function watchSauce(server, cfg) { try { debug(`reading sauce pid`); const pid = parseInt(await readFile(process.env.SC_PID_FILE), 10); debug(`sauce pid is ${pid}`); let done = false; server.once(`run_complete`, () => { debug(`run complete`); done = true; }); const delay = 1000; // eslint-disable-next-line no-unmodified-loop-condition while (!done) { debug(`waiting ${delay}ms`); await new Promise((resolve) => setTimeout(resolve, delay)); debug(`waited ${delay}ms`); await new Promise((resolve, reject) => { debug(`checking if ${pid} is running`); ps.lookup({ psargs: `-A`, pid }, (err, resultList) => { if (err) { debug(`ps-node produced an error`, err); reject(err); return; } if (resultList.length === 0) { debug(`pid ${pid} is not running`); reject(new Error(`pid ${pid} is not running`)); return; } debug(`pid ${pid} is running`); resolve(); }); }); } } catch (err) { console.error(err); console.error(`Sauce Tunnel is not running, stopping server and exiting`); stopper.stop(cfg); // so, this is a bit harsh, but due to karma's api,there's no great way to // communicate back to test.js that karma failed because the tunnel // disappeared. By exiting here, cmd.sh should restart sauce and run the // suite again // eslint-disable-next-line no-process-exit process.exit(65); } }
}, function() { gulp .src(Support.resolveSupportPath("tmp", "models")) .pipe(helpers.readFile("user.js")) .pipe(helpers.ensureContent("sequelize.define(\"User\"")) .pipe(helpers.ensureContent("first_name: DataTypes.STRING")) .pipe(helpers.ensureContent("last_name: DataTypes.STRING")) .pipe(helpers.ensureContent("bio: DataTypes.TEXT")) .pipe(helpers.teardown(done)); });
topic: function () { var self = this, filePath = path.join(RESOURCE_DIR, 'test.ext'), report = { returnValue: fs.readFile(filePath, function (error, result) { report.result = result.toString('utf8'); self.callback(null, report); }) }; },
it('should not generate formulae when requested', function() { var wb =X.readFile(paths.fstb,{cellFormula:false}); wb.SheetNames.forEach(function(s) { var ws = wb.Sheets[s]; Object.keys(ws).forEach(function(addr) { if(addr[0] === "!" || !ws.hasOwnProperty(addr)) return; assert(typeof ws[addr].f === 'undefined'); }); }); });
prepare(function() { gulp .src(Support.resolveSupportPath("tmp", "migrations")) .pipe(helpers.readFile("*-" + migrationFile)) .pipe(helpers.ensureContent("done()")) .pipe(helpers.expect(function(stdout) { expect(stdout.match(/(done\(\))/)).to.have.length(2); })) .pipe(helpers.teardown(done)); });
it('should not generate cell styles by default', function() { var wb = X.readFile(paths.css1); wb.SheetNames.forEach(function(s) { var ws = wb.Sheets[s]; Object.keys(ws).forEach(function(addr) { if(addr[0] === "!" || !ws.hasOwnProperty(addr)) return; assert(typeof ws[addr].s === 'undefined'); }); }); });
}, function(err, stdout) { gulp .src(Support.resolveSupportPath('tmp', 'models')) .pipe(helpers.readFile('user.js')) .pipe(helpers.ensureContent("sequelize.define('User'")) .pipe(helpers.ensureContent("first_name: DataTypes.STRING")) .pipe(helpers.ensureContent("last_name: DataTypes.STRING")) .pipe(helpers.ensureContent("bio: DataTypes.TEXT")) .pipe(helpers.teardown(done)) })
}, function () { gulp .src(Support.resolveSupportPath('tmp', 'models')) .pipe(helpers.readFile('user.js')) .pipe(helpers.ensureContent('sequelize.define(\'User\'')) .pipe(helpers.ensureContent('first_name: DataTypes.STRING')) .pipe(helpers.ensureContent('last_name: DataTypes.STRING')) .pipe(helpers.ensureContent('bio: DataTypes.TEXT')) .pipe(helpers.teardown(done)); });
exp: function() { //should not be empty string since reset only resets the last set //as in it should have .test-dont-reset stlyes const exp = ctr.getRes(); _h.cleanCSS(exp).should.equal(_h.readFile(__filename)); //since its returns a raw set both should have a size of 1 one.size.should.be.exactly(1); two.size.should.be.exactly(1); }
it('should generate number formats when requested', function() { var wb = X.readFile(paths.nf1, {cellNF: true}); wb.SheetNames.forEach(function(s) { var ws = wb.Sheets[s]; Object.keys(ws).forEach(function(addr) { if(addr[0] === "!" || !ws.hasOwnProperty(addr)) return; assert(ws[addr].t!== 'n' || typeof ws[addr].z !== 'undefined'); }); }); });
prepare(() => { gulp .src(Support.resolveSupportPath('tmp', 'seeders')) .pipe(helpers.readFile('*-' + seedFile)) .pipe(helpers.expect(stdout => { expect(stdout).to.contain('up: (queryInterface, Sequelize) => {'); expect(stdout).to.contain('down: (queryInterface, Sequelize) => {'); })) .pipe(helpers.teardown(done)); });
exp: function() { //should equal css file const res = one + two; _h.cleanCSS(res).should.equal(_h.readFile(__filename)); //should not be empty string since reset only resets the last set //as in it should have .test-dont-reset stlyes const exp = ctr.getRes(); exp.length.should.be.exactly(37); }