How to use fs.readFileAsync method in Cypress

Best JavaScript code snippet using cypress

Excel.test.js

Source:Excel.test.js Github

copy

Full Screen

...8const xml2js = require('xml2js');9const builder = new xml2js.Builder();10const readFiles = (template) => {11 return Promise.props({12 template: fs.readFileAsync(`${config.TEST_DIRS.TEMPLATE}${template}`)13 });14};15describe('Excel.js', () => {16 describe('sharedStrings()', () => {17 it('should read each strings on template', () => {18 return fs.readFileAsync(`${config.TEST_DIRS.TEMPLATE}Template.xlsx`)19 .then((template) => {20 let sharedStrings = new Excel(template).sharedStrings();21 assert.isOk(typeof sharedStrings === 'string');22 assert.isOk(_.includeString(sharedStrings, '{{AccountName__c}}'));23 assert.isOk(_.includeString(sharedStrings, '{{AccountAddress__c}}'));24 assert.isOk(_.includeString(sharedStrings, '{{SalaryDate__c}}'));25 }).catch((err) => {26 console.log(err);27 assert.isOk(false);28 });29 });30 it('should read with no error in case no strings defined', () => {31 return fs.readFileAsync(`${config.TEST_DIRS.TEMPLATE}TemplateNoStrings.xlsx`)32 .then((template) => {33 let sharedStrings = new Excel(template).sharedStrings();34 assert.isOk(typeof sharedStrings === 'string');35 }).catch((err) => {36 console.log(err);37 assert.isOk(false);38 });39 });40 it('should read Japanese strings on template', () => {41 return fs.readFileAsync(`${config.TEST_DIRS.TEMPLATE}Template.xlsx`)42 .then((template) => {43 let sharedStrings = new Excel(template).sharedStrings();44 assert.isOk(_.includeString(sharedStrings, '雇用期間'));45 }).catch((err) => {46 console.log(err);47 assert.isOk(false);48 });49 });50 it('should read as encoded string', () => {51 return fs.readFileAsync(`${config.TEST_DIRS.TEMPLATE}TemplateWithXmlEntity.xlsx`)52 .then((template) => {53 let sharedStrings = new Excel(template).sharedStrings();54 assert.isOk(_.includeString(sharedStrings, '\&lt;\&gt;\"\\\&amp;\''));55 }).catch((err) => {56 console.log(err);57 assert.isOk(false);58 });59 });60 });61 describe('parseSharedStrings()', () => {62 it('should parse each strings on template', () => {63 return fs.readFileAsync(`${config.TEST_DIRS.TEMPLATE}Template.xlsx`)64 .then((template) => {65 return new Excel(template).parseSharedStrings();66 }).then((stringModels) => {67 let si = stringModels.sst.si;68 assert.notStrictEqual(si, undefined);69 assert.isOk(si instanceof Array);70 si = _.map(si, (e) => _.stringValue(e.t));71 assert.isOk(_.containsAsPartial(si, '{{AccountName__c}}'));72 assert.isOk(_.containsAsPartial(si, '{{AccountAddress__c}}'));73 assert.isOk(_.containsAsPartial(si, '{{SalaryDate__c}}'));74 }).catch((err) => {75 console.log(err);76 assert.isOk(false);77 });78 });79 it('should parse with no error in case no strings defined', () => {80 return fs.readFileAsync(`${config.TEST_DIRS.TEMPLATE}TemplateNoStrings.xlsx`)81 .then((template) => {82 return new Excel(template).parseSharedStrings();83 }).then((stringModels) => {84 assert.isOk(!stringModels.sst || !stringModels.sst.si);85 }).catch((err) => {86 console.log(err);87 assert.isOk(false);88 });89 });90 it('should parse Japanese with no error', () => {91 return fs.readFileAsync(`${config.TEST_DIRS.TEMPLATE}Template.xlsx`)92 .then((template) => {93 return new Excel(template).parseSharedStrings();94 }).then((stringModels) => {95 let si = stringModels.sst.si;96 assert.notStrictEqual(si, undefined);97 assert.isOk(si instanceof Array);98 si = _.map(si, (e) => _.stringValue(e.t));99 assert.isOk(_.containsAsPartial(si, '雇用期間'));100 }).catch((err) => {101 console.log(err);102 assert.isOk(false);103 });104 });105 it('should parse as decoded string', () => {106 return fs.readFileAsync(`${config.TEST_DIRS.TEMPLATE}TemplateWithXmlEntity.xlsx`)107 .then((template) => {108 return new Excel(template).parseSharedStrings();109 }).then((stringModels) => {110 let si = stringModels.sst.si;111 assert.notStrictEqual(si, undefined);112 assert.isOk(si instanceof Array);113 si = _.map(si, (e) => _.stringValue(e.t));114 assert.isOk(_.containsAsPartial(si, '<>\"\\\&\''));115 }).catch((err) => {116 console.log(err);117 assert.isOk(false);118 });119 });120 });121 describe('setSharedStrings()', () => {122 it('should return this instance', () => {123 return fs.readFileAsync(`${config.TEST_DIRS.TEMPLATE}Template.xlsx`)124 .then((template) => {125 let test = new Excel(template).setSharedStrings();126 assert.notStrictEqual(test, undefined);127 assert.notStrictEqual(test, null);128 assert.isOk(test instanceof Excel);129 }).catch((err) => {130 console.log(err);131 assert.isOk(false);132 });133 });134 it('should set value as xml string', () => {135 return fs.readFileAsync(`${config.TEST_DIRS.TEMPLATE}Template.xlsx`)136 .then((template) => {137 let sharedStrings = new Excel(template).setSharedStrings({138 anyKey: 'anyValue'139 }).sharedStrings();140 assert.isOk(_.includeString(sharedStrings, '<anyKey>anyValue</anyKey>'));141 }).catch((err) => {142 console.log(err);143 assert.isOk(false);144 });145 });146 it('should set Japanese value as xml string', () => {147 return fs.readFileAsync(`${config.TEST_DIRS.TEMPLATE}Template.xlsx`)148 .then((template) => {149 let sharedStrings = new Excel(template).setSharedStrings({150 anyKey: '日本語'151 }).sharedStrings();152 assert.isOk(_.includeString(sharedStrings, '<anyKey>日本語</anyKey>'));153 }).catch((err) => {154 console.log(err);155 assert.isOk(false);156 });157 });158 it('should set value with encoding', () => {159 return fs.readFileAsync(`${config.TEST_DIRS.TEMPLATE}Template.xlsx`)160 .then((template) => {161 let sharedStrings = new Excel(template).setSharedStrings({162 anyKey: '<>\"\\\&\''163 }).sharedStrings();164 assert.isOk(165 _.includeString(sharedStrings, '<anyKey>\&lt;\&gt;\"\\\&amp;\'</anyKey>')166 );167 }).catch((err) => {168 console.log(err);169 assert.isOk(false);170 });171 });172 });173 describe('parseWorkbookRels()', () => {174 it('should parse relation files, styles/sharedStrings/worksheets/theme', () => {175 return fs.readFileAsync(`${config.TEST_DIRS.TEMPLATE}Template.xlsx`)176 .then((template) => {177 return new Excel(template).parseWorkbookRels();178 }).then((workbookRels) => {179 let relationships = workbookRels.Relationships.Relationship;180 relationships = _.map(relationships, (e) => e['$'].Target);181 assert.isOk(_.containsAsPartial(relationships, 'styles.xml'));182 assert.isOk(_.containsAsPartial(relationships, 'sharedStrings.xml'));183 assert.isOk(_.containsAsPartial(relationships, 'worksheets/'));184 assert.isOk(_.containsAsPartial(relationships, 'theme/'));185 }).catch((err) => {186 console.log(err);187 assert.isOk(false);188 });189 });190 it('should parse each relation', () => {191 return fs.readFileAsync(`${config.TEST_DIRS.TEMPLATE}Template3Sheet.xlsx`)192 .then((template) => {193 return new Excel(template).parseWorkbookRels();194 }).then((workbookRels) => {195 let sheetCount = _.chain(workbookRels.Relationships.Relationship)196 .map((e) => e['$'].Target)197 .filter((e) => _.includeString(e, 'worksheets/'))198 .value()199 .length;200 assert.strictEqual(sheetCount, 3);201 }).catch((err) => {202 console.log(err);203 assert.isOk(false);204 });205 });206 });207 describe('setWorkbookRels()', () => {208 it('should return this instance', () => {209 return fs.readFileAsync(`${config.TEST_DIRS.TEMPLATE}Template.xlsx`)210 .then((template) => {211 let test = new Excel(template).setWorkbookRels({});212 assert.notStrictEqual(test, undefined);213 assert.notStrictEqual(test, null);214 assert.isOk(test instanceof Excel);215 }).catch((err) => {216 console.log(err);217 assert.isOk(false);218 });219 });220 it('should set value as xml string', () => {221 return fs.readFileAsync(`${config.TEST_DIRS.TEMPLATE}Template.xlsx`)222 .then((template) => {223 let workbookRels = new Excel(template)224 .setWorkbookRels({anyKey: 'anyValue'})225 .file(config.EXCEL_FILES.FILE_WORKBOOK_RELS)226 .asText();227 assert.isOk(_.includeString(workbookRels, '<anyKey>anyValue</anyKey>'));228 }).catch((err) => {229 console.log(err);230 assert.isOk(false);231 });232 });233 it('should set Japanese value as xml string', () => {234 return fs.readFileAsync(`${config.TEST_DIRS.TEMPLATE}Template.xlsx`)235 .then((template) => {236 let workbookRels = new Excel(template)237 .setWorkbookRels({anyKey: '日本語'})238 .file(config.EXCEL_FILES.FILE_WORKBOOK_RELS)239 .asText();240 assert.isOk(_.includeString(workbookRels, '<anyKey>日本語</anyKey>'));241 }).catch((err) => {242 console.log(err);243 assert.isOk(false);244 });245 });246 it('should set value with encoding', () => {247 return fs.readFileAsync(`${config.TEST_DIRS.TEMPLATE}Template.xlsx`)248 .then((template) => {249 let workbookRels = new Excel(template)250 .setWorkbookRels({anyKey: '<>\"\\\&\''})251 .file(config.EXCEL_FILES.FILE_WORKBOOK_RELS)252 .asText();253 assert.isOk(254 _.includeString(workbookRels, '<anyKey>\&lt;\&gt;\"\\\&amp;\'</anyKey>')255 );256 }).catch((err) => {257 console.log(err);258 assert.isOk(false);259 });260 });261 });262 describe('parseWorkbook()', () => {263 it('should parse information of sheet', () => {264 return fs.readFileAsync(`${config.TEST_DIRS.TEMPLATE}Template.xlsx`)265 .then((template) => {266 return new Excel(template).parseWorkbook();267 }).then((workbook) => {268 let sheets = workbook.workbook.sheets[0].sheet;269 assert.notStrictEqual(sheets, undefined);270 assert.notStrictEqual(sheets, null);271 assert.strictEqual(sheets.length, 1);272 assert.strictEqual(sheets[0]['$'].name, 'Sheet1');273 }).catch((err) => {274 console.log(err);275 assert.isOk(false);276 });277 });278 it('should parse each sheet', () => {279 return fs.readFileAsync(`${config.TEST_DIRS.TEMPLATE}Template3Sheet.xlsx`)280 .then((template) => {281 return new Excel(template).parseWorkbook();282 }).then((workbook) => {283 let sheets = workbook.workbook.sheets[0].sheet;284 assert.notStrictEqual(sheets, undefined);285 assert.notStrictEqual(sheets, null);286 assert.strictEqual(sheets.length, 3);287 assert.strictEqual(sheets[0]['$'].name, 'Sheet1');288 assert.strictEqual(sheets[1]['$'].name, 'Sheet2');289 assert.strictEqual(sheets[2]['$'].name, 'Sheet3');290 }).catch((err) => {291 console.log(err);292 assert.isOk(false);293 });294 });295 });296 describe('setWorkbook()', () => {297 it('should return this instance', () => {298 return fs.readFileAsync(`${config.TEST_DIRS.TEMPLATE}Template.xlsx`)299 .then((template) => {300 let test = new Excel(template).setWorkbook({});301 assert.notStrictEqual(test, undefined);302 assert.notStrictEqual(test, null);303 assert.isOk(test instanceof Excel);304 }).catch((err) => {305 console.log(err);306 assert.isOk(false);307 });308 });309 it('should set value as xml string', () => {310 return fs.readFileAsync(`${config.TEST_DIRS.TEMPLATE}Template.xlsx`)311 .then((template) => {312 let workbookRels = new Excel(template)313 .setWorkbook({anyKey: 'anyValue'})314 .file(config.EXCEL_FILES.FILE_WORKBOOK)315 .asText();316 assert.isOk(_.includeString(workbookRels, '<anyKey>anyValue</anyKey>'));317 }).catch((err) => {318 console.log(err);319 assert.isOk(false);320 });321 });322 it('should set Japanese value as xml string', () => {323 return fs.readFileAsync(`${config.TEST_DIRS.TEMPLATE}Template.xlsx`)324 .then((template) => {325 let workbookRels = new Excel(template)326 .setWorkbook({anyKey: '日本語'})327 .file(config.EXCEL_FILES.FILE_WORKBOOK)328 .asText();329 assert.isOk(_.includeString(workbookRels, '<anyKey>日本語</anyKey>'));330 }).catch((err) => {331 console.log(err);332 assert.isOk(false);333 });334 });335 it('should set value with encoding', () => {336 return fs.readFileAsync(`${config.TEST_DIRS.TEMPLATE}Template.xlsx`)337 .then((template) => {338 let workbookRels = new Excel(template)339 .setWorkbook({anyKey: '<>\"\\\&\''})340 .file(config.EXCEL_FILES.FILE_WORKBOOK)341 .asText();342 assert.isOk(343 _.includeString(workbookRels, '<anyKey>\&lt;\&gt;\"\\\&amp;\'</anyKey>')344 );345 }).catch((err) => {346 console.log(err);347 assert.isOk(false);348 });349 });350 });351 describe('parseWorksheetsDir()', () => {352 it('should parse relation and contents', () => {353 return fs.readFileAsync(`${config.TEST_DIRS.TEMPLATE}Template.xlsx`)354 .then((template) => {355 return new Excel(template).parseWorksheetsDir();356 }).then((worksheets) => {357 let files = _.filter(worksheets, (e) => !!e.worksheet);358 assert.strictEqual(files.length, 1);359 let relations = _.filter(worksheets, (e) => !!e.Relationships);360 assert.strictEqual(relations.length, 1);361 assert.strictEqual(`${files[0].name}.rels`, relations[0].name);362 }).catch((err) => {363 console.log(err);364 assert.isOk(false);365 });366 });367 it('should parse each relation and contents', () => {368 return fs.readFileAsync(`${config.TEST_DIRS.TEMPLATE}Template3Sheet.xlsx`)369 .then((template) => {370 return new Excel(template).parseWorksheetsDir();371 }).then((worksheets) => {372 let files = _.filter(worksheets, (e) => !!e.worksheet);373 assert.strictEqual(files.length, 3);374 let relations = _.filter(worksheets, (e) => !!e.Relationships);375 assert.strictEqual(relations.length, 3);376 let fileNameInRelations = _.map(relations, (e) => e.name);377 assert.isOk(_.contains(fileNameInRelations, `${files[0].name}.rels`));378 assert.isOk(_.contains(fileNameInRelations, `${files[1].name}.rels`));379 assert.isOk(_.contains(fileNameInRelations, `${files[2].name}.rels`));380 }).catch((err) => {381 console.log(err);382 assert.isOk(false);383 });384 });385 });386 describe('setWorksheet()', () => {387 it('should return this instance', () => {388 return fs.readFileAsync(`${config.TEST_DIRS.TEMPLATE}Template.xlsx`)389 .then((template) => {390 let test = new Excel(template).setWorksheet('someSheet.xml', {});391 assert.notStrictEqual(test, undefined);392 assert.notStrictEqual(test, null);393 assert.isOk(test instanceof Excel);394 }).catch((err) => {395 console.log(err);396 assert.isOk(false);397 });398 });399 it('should set value as xml string', () => {400 return fs.readFileAsync(`${config.TEST_DIRS.TEMPLATE}Template.xlsx`)401 .then((template) => {402 let workSheet = new Excel(template)403 .setWorksheet('someSheet.xml', {anyKey: 'anyValue'})404 .file(`${config.EXCEL_FILES.DIR_WORKSHEETS}/someSheet.xml`)405 .asText();406 assert.isOk(_.includeString(workSheet, '<anyKey>anyValue</anyKey>'));407 }).catch((err) => {408 console.log(err);409 assert.isOk(false);410 });411 });412 it('should set Japanese value as xml string', () => {413 return fs.readFileAsync(`${config.TEST_DIRS.TEMPLATE}Template.xlsx`)414 .then((template) => {415 let workSheet = new Excel(template)416 .setWorksheet('someSheet.xml', {anyKey: '日本語'})417 .file(`${config.EXCEL_FILES.DIR_WORKSHEETS}/someSheet.xml`)418 .asText();419 assert.isOk(_.includeString(workSheet, '<anyKey>日本語</anyKey>'));420 }).catch((err) => {421 console.log(err);422 assert.isOk(false);423 });424 });425 it('should set value with encoding', () => {426 return fs.readFileAsync(`${config.TEST_DIRS.TEMPLATE}Template.xlsx`)427 .then((template) => {428 let workSheet = new Excel(template)429 .setWorksheet('someSheet.xml', {anyKey: '<>\"\\\&\''})430 .file(`${config.EXCEL_FILES.DIR_WORKSHEETS}/someSheet.xml`)431 .asText();432 assert.isOk(433 _.includeString(workSheet, '<anyKey>\&lt;\&gt;\"\\\&amp;\'</anyKey>')434 );435 }).catch((err) => {436 console.log(err);437 assert.isOk(false);438 });439 });440 });441 describe('setWorksheets()', () => {442 it('should return this instance', () => {443 return fs.readFileAsync(`${config.TEST_DIRS.TEMPLATE}Template.xlsx`)444 .then((template) => {445 let test = new Excel(template).setWorksheets([]);446 assert.notStrictEqual(test, undefined);447 assert.notStrictEqual(test, null);448 assert.isOk(test instanceof Excel);449 }).catch((err) => {450 console.log(err);451 assert.isOk(false);452 });453 });454 it('should set value as xml string', () => {455 return fs.readFileAsync(`${config.TEST_DIRS.TEMPLATE}Template.xlsx`)456 .then((template) => {457 let workSheet = new Excel(template)458 .setWorksheets([459 {name: 'sheet1.xml', data: {anyKey: 'anyValue'}}460 ])461 .file(`${config.EXCEL_FILES.DIR_WORKSHEETS}/sheet1.xml`)462 .asText();463 assert.isOk(_.includeString(workSheet, '<anyKey>anyValue</anyKey>'));464 }).catch((err) => {465 console.log(err);466 assert.isOk(false);467 });468 });469 it('should set each value', () => {470 return fs.readFileAsync(`${config.TEST_DIRS.TEMPLATE}Template.xlsx`)471 .then((template) => {472 let excelTemplate = new Excel(template)473 .setWorksheets([474 {name: 'sheet1.xml', data: {key1: 'value1'}},475 {name: 'sheet2.xml', data: {key2: 'value2'}},476 {name: 'sheet3.xml', data: {key3: 'value3'}}477 ]);478 let sheet1 = excelTemplate479 .file(`${config.EXCEL_FILES.DIR_WORKSHEETS}/sheet1.xml`)480 .asText();481 assert.isOk(_.includeString(sheet1, '<key1>value1</key1>'));482 let sheet2 = excelTemplate483 .file(`${config.EXCEL_FILES.DIR_WORKSHEETS}/sheet2.xml`)484 .asText();485 assert.isOk(_.includeString(sheet2, '<key2>value2</key2>'));486 let sheet3 = excelTemplate487 .file(`${config.EXCEL_FILES.DIR_WORKSHEETS}/sheet3.xml`)488 .asText();489 assert.isOk(_.includeString(sheet3, '<key3>value3</key3>'));490 }).catch((err) => {491 console.log(err);492 assert.isOk(false);493 });494 });495 it('should set Japanese value as xml string', () => {496 return fs.readFileAsync(`${config.TEST_DIRS.TEMPLATE}Template.xlsx`)497 .then((template) => {498 let workSheet = new Excel(template)499 .setWorksheets([500 {name: 'sheet1.xml', data: {anyKey: '日本語'}}501 ])502 .file(`${config.EXCEL_FILES.DIR_WORKSHEETS}/sheet1.xml`)503 .asText();504 assert.isOk(_.includeString(workSheet, '<anyKey>日本語</anyKey>'));505 }).catch((err) => {506 console.log(err);507 assert.isOk(false);508 });509 });510 it('should set value with encoding', () => {511 return fs.readFileAsync(`${config.TEST_DIRS.TEMPLATE}Template.xlsx`)512 .then((template) => {513 let workSheet = new Excel(template)514 .setWorksheets([515 {name: 'sheet1.xml', data: {anyKey: '<>\"\\\&\''}}516 ])517 .file(`${config.EXCEL_FILES.DIR_WORKSHEETS}/sheet1.xml`)518 .asText();519 assert.isOk(520 _.includeString(workSheet, '<anyKey>\&lt;\&gt;\"\\\&amp;\'</anyKey>')521 );522 }).catch((err) => {523 console.log(err);524 assert.isOk(false);525 });526 });527 });528 describe('removeWorksheet()', () => {529 it('should return this instance', () => {530 return fs.readFileAsync(`${config.TEST_DIRS.TEMPLATE}Template.xlsx`)531 .then((template) => {532 let templateObj = new Excel(template)533 .setWorksheets([534 {name: 'sheet1.xml', data: {anyKey: 'anyValue'}}535 ]);536 let test = templateObj.removeWorksheet('sheet1.xml');537 assert.notStrictEqual(test, undefined);538 assert.notStrictEqual(test, null);539 assert.isOk(test instanceof Excel);540 }).catch((err) => {541 console.log(err);542 assert.isOk(false);543 });544 });545 it('should remove the file', () => {546 return fs.readFileAsync(`${config.TEST_DIRS.TEMPLATE}Template.xlsx`)547 .then((template) => {548 let templateObj = new Excel(template)549 .setWorksheets([550 {name: 'sheet1.xml', data: {anyKey: 'anyValue'}}551 ]);552 templateObj.removeWorksheet('sheet1.xml');553 assert.strictEqual(templateObj.file(554 `${config.EXCEL_FILES.DIR_WORKSHEETS}/sheet1.xml`555 ), null);556 }).catch((err) => {557 console.log(err);558 assert.isOk(false);559 });560 });561 it('should not remove other files', () => {562 return fs.readFileAsync(`${config.TEST_DIRS.TEMPLATE}Template.xlsx`)563 .then((template) => {564 let templateObj = new Excel(template)565 .setWorksheets([566 {name: 'sheet1.xml', data: {anyKey: 'anyValue'}},567 {name: 'sheet2.xml', data: {anyKey: 'anyValue'}},568 {name: 'sheet3.xml', data: {anyKey: 'anyValue'}}569 ]);570 templateObj.removeWorksheet('sheet1.xml');571 assert.notStrictEqual(templateObj.file(572 `${config.EXCEL_FILES.DIR_WORKSHEETS}/sheet2.xml`573 ), null);574 assert.notStrictEqual(templateObj.file(575 `${config.EXCEL_FILES.DIR_WORKSHEETS}/sheet3.xml`576 ), null);577 }).catch((err) => {578 console.log(err);579 assert.isOk(false);580 });581 });582 it('should return with no error even if not existing', () => {583 return fs.readFileAsync(`${config.TEST_DIRS.TEMPLATE}Template.xlsx`)584 .then((template) => {585 let templateObj = new Excel(template);586 let test = templateObj.removeWorksheet('invalid sheet name');587 assert.isOk(test instanceof Excel);588 }).catch((err) => {589 console.log(err);590 assert.isOk(false);591 });592 });593 });594 describe('parseWorksheetRelsDir()', () => {595 it('should parse relation file', () => {596 return fs.readFileAsync(`${config.TEST_DIRS.TEMPLATE}Template.xlsx`)597 .then((template) => {598 return new Excel(template).parseWorksheetRelsDir();599 }).then((worksheetRels) => {600 assert.notStrictEqual(worksheetRels, undefined);601 assert.notStrictEqual(worksheetRels, null);602 assert.isOk(_.isArray(worksheetRels));603 assert.strictEqual(1, worksheetRels.length);604 assert.isOk(_.consistOf(605 worksheetRels, ['Relationships', 'name']606 ));607 }).catch((err) => {608 console.log(err);609 assert.isOk(false);610 });611 });612 it('should parse each relation file', () => {613 return fs.readFileAsync(`${config.TEST_DIRS.TEMPLATE}Template3Sheet.xlsx`)614 .then((template) => {615 return new Excel(template).parseWorksheetRelsDir();616 }).then((worksheetRels) => {617 assert.notStrictEqual(worksheetRels, undefined);618 assert.notStrictEqual(worksheetRels, null);619 assert.isOk(_.isArray(worksheetRels));620 assert.strictEqual(3, worksheetRels.length);621 assert.isOk(_.consistOf(622 worksheetRels, ['Relationships', 'name']623 ));624 }).catch((err) => {625 console.log(err);626 assert.isOk(false);627 });628 });629 });630 describe('setTemplateSheetRel()', () => {631 it('should return this instance', () => {632 return fs.readFileAsync(`${config.TEST_DIRS.TEMPLATE}Template.xlsx`)633 .then((template) => {634 return new Excel(template).setTemplateSheetRel();635 }).then((templateObj) => {636 assert.notStrictEqual(templateObj, undefined);637 assert.notStrictEqual(templateObj, null);638 assert.isOk(templateObj instanceof Excel);639 }).catch((err) => {640 console.log(err);641 assert.isOk(false);642 });643 });644 it('should set relation file as template sheet', () => {645 return fs.readFileAsync(`${config.TEST_DIRS.TEMPLATE}Template.xlsx`)646 .then((template) => {647 return new Excel(template).setTemplateSheetRel();648 }).then((templateObj) => {649 assert.notStrictEqual(templateObj.templateSheetRel, undefined);650 assert.notStrictEqual(templateObj.templateSheetRel.Relationships, undefined);651 }).catch((err) => {652 console.log(err);653 assert.isOk(false);654 });655 });656 });657 describe('setWorksheetRel()', () => {658 it('should return this instance', () => {659 return fs.readFileAsync(`${config.TEST_DIRS.TEMPLATE}Template.xlsx`)660 .then((template) => {661 let test = new Excel(template).setWorksheetRel('someSheet.xml', {});662 assert.notStrictEqual(test, undefined);663 assert.notStrictEqual(test, null);664 assert.isOk(test instanceof Excel);665 }).catch((err) => {666 console.log(err);667 assert.isOk(false);668 });669 });670 it('should set value as xml string', () => {671 return fs.readFileAsync(`${config.TEST_DIRS.TEMPLATE}Template.xlsx`)672 .then((template) => {673 let workSheetRels = new Excel(template)674 .setWorksheetRel('someSheet.xml', {anyKey: 'anyValue'})675 .file(`${config.EXCEL_FILES.DIR_WORKSHEETS_RELS}/someSheet.xml.rels`)676 .asText();677 assert.isOk(_.includeString(workSheetRels, '<anyKey>anyValue</anyKey>'));678 }).catch((err) => {679 console.log(err);680 assert.isOk(false);681 });682 });683 it('should set Japanese value as xml string', () => {684 return fs.readFileAsync(`${config.TEST_DIRS.TEMPLATE}Template.xlsx`)685 .then((template) => {686 let workSheetRels = new Excel(template)687 .setWorksheetRel('someSheet.xml', {anyKey: '日本語'})688 .file(`${config.EXCEL_FILES.DIR_WORKSHEETS_RELS}/someSheet.xml.rels`)689 .asText();690 assert.isOk(_.includeString(workSheetRels, '<anyKey>日本語</anyKey>'));691 }).catch((err) => {692 console.log(err);693 assert.isOk(false);694 });695 });696 it('should set value with encoding', () => {697 return fs.readFileAsync(`${config.TEST_DIRS.TEMPLATE}Template.xlsx`)698 .then((template) => {699 let workSheetRels = new Excel(template)700 .setWorksheetRel('someSheet.xml', {anyKey: '<>\"\\\&\''})701 .file(`${config.EXCEL_FILES.DIR_WORKSHEETS_RELS}/someSheet.xml.rels`)702 .asText();703 assert.isOk(704 _.includeString(workSheetRels, '<anyKey>\&lt;\&gt;\"\\\&amp;\'</anyKey>')705 );706 }).catch((err) => {707 console.log(err);708 assert.isOk(false);709 });710 });711 });712 describe('setWorksheetRels()', () => {713 it('should return this instance if template is not set', () => {714 return fs.readFileAsync(`${config.TEST_DIRS.TEMPLATE}Template.xlsx`)715 .then((template) => {716 let test = new Excel(template).setWorksheetRels(['someSheet']);717 assert.notStrictEqual(test, undefined);718 assert.notStrictEqual(test, null);719 assert.isOk(test instanceof Excel);720 }).catch((err) => {721 console.log(err);722 assert.isOk(false);723 });724 });725 it('relation file should be the same with template', () => {726 return fs.readFileAsync(`${config.TEST_DIRS.TEMPLATE}Template.xlsx`)727 .then((template) => {728 return new Excel(template).setTemplateSheetRel();729 }).then((templateObj) => {730 let test = templateObj.setWorksheetRels(['someSheet']);731 let workSheetRels = templateObj732 .setWorksheetRels(['someSheet'])733 .file(`${config.EXCEL_FILES.DIR_WORKSHEETS_RELS}/someSheet.rels`)734 .asText();735 let templateString = builder.buildObject(templateObj.templateSheetRel);736 assert.strictEqual(workSheetRels, templateString);737 }).catch((err) => {738 console.log(err);739 assert.isOk(false);740 });741 });742 it('all relation files should be the same with template', () => {743 return fs.readFileAsync(`${config.TEST_DIRS.TEMPLATE}Template.xlsx`)744 .then((template) => {745 return new Excel(template).setTemplateSheetRel();746 }).then((templateObj) => {747 templateObj = templateObj.setWorksheetRels([748 'someSheet1', 'someSheet2', 'someSheet3'749 ]);750 let templateString = builder.buildObject(templateObj.templateSheetRel);751 _.each(['someSheet1', 'someSheet2', 'someSheet3'], (sheetName) => {752 let sheetStr = templateObj753 .file(`${config.EXCEL_FILES.DIR_WORKSHEETS_RELS}/${sheetName}.rels`)754 .asText();755 assert.strictEqual(sheetStr, templateString);756 });757 }).catch((err) => {758 console.log(err);759 assert.isOk(false);760 });761 });762 });763 describe('parseFile()', () => {764 it('should parse async by returning Promise', () => {765 return fs.readFileAsync(`${config.TEST_DIRS.TEMPLATE}Template.xlsx`)766 .then((template) => {767 let promise = new Excel(template)768 .parseFile(config.EXCEL_FILES.FILE_SHARED_STRINGS);769 assert.notStrictEqual(promise, undefined);770 assert.notStrictEqual(promise, null);771 assert.isOk(promise instanceof Promise);772 }).catch((err) => {773 console.log(err);774 assert.isOk(false);775 });776 });777 it('should parse from xml string', () => {778 return fs.readFileAsync(`${config.TEST_DIRS.TEMPLATE}Template.xlsx`)779 .then((template) => {780 return new Excel(template)781 .parseFile(config.EXCEL_FILES.FILE_SHARED_STRINGS);782 }).then((stringModel) => {783 assert.isNotOk(stringModel instanceof String);784 }).catch((err) => {785 console.log(err);786 assert.isOk(false);787 });788 });789 });790 describe('parseDir()', () => {791 it('should parse async by returning Promise', () => {792 return fs.readFileAsync(`${config.TEST_DIRS.TEMPLATE}Template.xlsx`)793 .then((template) => {794 let promise = new Excel(template)795 .parseDir(config.EXCEL_FILES.DIR_WORKSHEETS);796 assert.notStrictEqual(promise, undefined);797 assert.notStrictEqual(promise, null);798 assert.isOk(promise instanceof Promise);799 }).catch((err) => {800 console.log(err);801 assert.isOk(false);802 });803 });804 it('should parse each file in the directory', () => {805 return fs.readFileAsync(`${config.TEST_DIRS.TEMPLATE}Template.xlsx`)806 .then((template) => {807 return new Excel(template)808 .parseDir(config.EXCEL_FILES.DIR_WORKSHEETS);809 }).then((fileModels) => {810 assert.isOk(_.consistOf(fileModels, ['name']));811 }).catch((err) => {812 console.log(err);813 assert.isOk(false);814 });815 });816 });...

Full Screen

Full Screen

server.js

Source:server.js Github

copy

Full Screen

...63 var viewWidgets = ["VIEW", "GRAPHICS-WINDOW"];64 var widget = "";65 var zip;66 var gbccTeacherArray;67 fs.readFileAsync(nlogoFilename1, "utf8").then(function(data) {68 zip = new JSZip();69 zip.file(title, data);70 if (activityType === "legacyHubnet") {71 var sanitizedFileContents = data.toString();//removeUnimplementedPrimCalls(data.toString());72 array = sanitizedFileContents.split("\n");73 nlogoFile = "";74 arrayIndex = 0;75 var newWidget = false;76 var lastWidgetType = "";77 var label;78 var widgetList = [];79 for(i in array) {80 // buttons on the client need a client-procedure, to avoid a console error81 if (arrayIndex === 0 && array[i] === "@#$#@#$#@") { nlogoFile = nlogoFile + "\n\nto client-procedure\nend\n"; }82 nlogoFile += array[i] + "\n";83 if (arrayIndex === 1) { if (widgets.indexOf(array[i]) > -1) { numTeacherWidgets++; } }84 if (arrayIndex === 8) {85 if ((widgets.indexOf(array[i]) > -1) || (array[i]==="@#$#@#$#@")) {86 if ((array[i] != "VIEW") && (array[i]!="@#$#@#$#@")) { numStudentWidgets++; }87 switch (lastWidgetType) {88 case "BUTTON":89 widget = widget.substr(0,widget.lastIndexOf("NIL"))+"NIL\nNIL\nNIL\n"+widget.lastIndexOf("NIL")+"\n\n";90 widget = widget.replace("NIL","client-procedure");91 if (widget.split("NIL").length === 5) { widget = widget.replace("NIL\nNIL","NIL\nNIL\nNIL"); }92 break;93 case "MONITOR":94 widget = widget.substr(0,widget.indexOf("NIL"))+'""'+"\n0\n1\n11\n";95 //widget = widget.replace("NIL",label+"\n0");96 break;97 case "CHOOSER":98 var widgetLines = widget.split("\n");99 widgetLines[7] = widgetLines[7].replace(/\\"/g, "\"");100 widget = widgetLines.join("\n");101 break;102 case "VIEW":103 var widgetParts = widget.split("\n");104 secondView.push(parseInt(widgetParts[1]));105 secondView.push(parseInt(widgetParts[2]));106 secondView.push(parseInt(widgetParts[3]));107 secondView.push(parseInt(widgetParts[4]));108 widget = "";109 break;110 }111 if ((widget != "") && (viewWidgets.indexOf(lastWidgetType) === -1)) {112 widgetList.push(widget);113 widget = "";114 }115 lastWidgetType = array[i];116 label = array[(parseInt(i) + 5).toString()];117 }118 widget += array[i] + "\n"; 119 }120 if (array[i] === "@#$#@#$#@") { arrayIndex++; }121 }122 teacherWidgetRange = [0, numTeacherWidgets - 1];123 studentWidgetRange = (numStudentWidgets === 0) ? teacherWidgetRange : [numTeacherWidgets, numTeacherWidgets + numStudentWidgets - 1];124 loginWidgetRange = [(numTeacherWidgets + numStudentWidgets), (numTeacherWidgets + numStudentWidgets)];125 var oldNlogoFile = nlogoFile;126 array = oldNlogoFile.toString().split("\n");127 nlogoFile = "";128 arrayIndex = 0;129 for (i in array) {130 if (array[i] === "@#$#@#$#@") {131 arrayIndex++;132 if (arrayIndex === 2) {133 for (var j=0; j<widgetList.length; j++) {134 nlogoFile += widgetList[j] + "\n";135 }136 }137 }138 nlogoFile += array[i] + "\n";139 }140 } else {141 //console.log("uploading first file");142 array = data.toString().split("\n");143 gbccTeacherArray = array;144 arrayIndex = 0;145 for(i in array) {146 if (arrayIndex === 1) { if (widgets.indexOf(array[i]) > -1) { numTeacherWidgets++; } }147 if (array[i] === "@#$#@#$#@") { arrayIndex++; }148 }149 teacherWidgetRange = [0, numTeacherWidgets - 1];150 studentWidgetRange = teacherWidgetRange;151 loginWidgetRange = [numTeacherWidgets, numTeacherWidgets];152 nlogoFile = "";153 arrayIndex = 0;154 for (i in array) {155 if (array[i] === "@#$#@#$#@") {156 arrayIndex++;157 }158 nlogoFile += array[i] + "\n";159 }160 }161 }).then(function() {162 if (nlogoFilename2 === undefined) { nlogoFilename2 = nlogoFilename1; }; //secondView = 'false'; }163 fs.readFileAsync(nlogoFilename2, "utf8").then(function(data) {164 if (activityType === "gbccHierarchical") {165 zip.file(title+"-student", data);166 array = data.toString().split("\n");167 arrayIndex = 0;168 nlogoCode = "";169 widgetCode = "";170 var graphicsWindowPosition = 0;171 for(i in array) {172 if ((arrayIndex === 0) && (array[i] != "@#$#@#$#@")) {173 nlogoCode += array[i] + "\n"; 174 }175 if (arrayIndex === 1) { 176 if (widgets.indexOf(array[i]) > -1) { numStudentWidgets++; } 177 if (graphicsWindowPosition > 0 && graphicsWindowPosition < 6) {178 if (graphicsWindowPosition > 1) { secondView+= ", "; }179 secondView+= array[i];180 graphicsWindowPosition++;181 }182 if (graphicsWindowPosition === 5) {183 secondView+= "";184 graphicsWindowPosition = 6;185 } 186 if (graphicsWindowPosition === 6 && array[i].length === 0) {187 graphicsWindowPosition = 0;188 } 189 if (array[i] === "GRAPHICS-WINDOW") {190 graphicsWindowPosition = 1;191 secondView ="";192 }193 if ((array[i] != "@#$#@#$#@") && (graphicsWindowPosition === 0)) {194 widgetCode += array[i] + "\n";195 }196 }197 if (array[i] === "@#$#@#$#@") { arrayIndex++; }198 }199 studentWidgetRange = (numStudentWidgets === 0) ? teacherWidgetRange : [numTeacherWidgets, numTeacherWidgets + numStudentWidgets - 1];200 loginWidgetRange = [(numTeacherWidgets + numStudentWidgets), (numTeacherWidgets + numStudentWidgets)];201 nlogoFile = "";202 array = gbccTeacherArray;203 arrayIndex = 0;204 for (i in array) {205 if (array[i] === "@#$#@#$#@") {206 arrayIndex++;207 if (arrayIndex === 1) { //console.log(nlogoFile); 208 nlogoFile += nlogoCode; }209 if (arrayIndex === 2) { //console.log(nlogoFile);210 nlogoFile += widgetCode; }211 }212 nlogoFile += array[i] + "\n";213 }214 }215 }).then(function() {216 fs.readFileAsync("gbcc/config.json", "utf8").then(function(data) {217 var array = data.toString().split("\n");218 var configData = data;219 configFile = "";220 for(var i in array) {221 configFile += array[i] + "\n";222 if (array[i].includes("loginComponents")) { configFile += ' "componentRange": [' +loginWidgetRange + "]\n" }223 if (array[i].includes("teacherComponents")) { configFile += ' "componentRange": [' +teacherWidgetRange + "]\n" }224 if (array[i].includes("studentComponents")) { configFile += ' "componentRange": [' +studentWidgetRange + "]\n" }225 if (array[i].includes("galleryJs")) {226 configFile += (fields["allowTabs"]) ? ' "allowTabs": true, \n' : ' "allowTabs": false, \n';227 configFile += (fields["allowMultipleLayers"]) ? ' "allowMultipleLayers": true, \n' : ' "allowMultipleLayers": false, \n';228 configFile += (fields["allowMultipleSelections"]) ? ' "allowMultipleSelections": true, \n' : ' "allowMultipleSelections": false, \n';229 configFile += (fields["allowCanvasForeverButtons"]) ? ' "allowCanvasForeverButtons": true, \n' : ' "allowCanvasForeverButtons": false, \n';230 configFile += (fields["allowGalleryControls"]) ? ' "allowGalleryControls": true, \n' : ' "allowGalleryControls": false, \n';231 configFile += (fields["allowTeacherControls"]) ? ' "allowTeacherControls": true, \n' : ' "allowTeacherControls": false, \n';232 configFile += (fields["allowMirrorControl"]) ? ' "allowMirrorControl": true, \n' : ' "allowMirrorControl": false, \n';233 configFile += (fields["legacyHubnet"]) ? ' "legacyHubnet": true, \n' : ' "legacyHubnet": false, \n';234 configFile += ' "secondView": [' +secondView + ']\n';235 } 236 }237 }).then(function() {238 fs.readFileAsync("gbcc/index1.html", "utf8").then(function(data) {239 indexFile = "";240 var array = data.toString().split("\n");241 for (i in array) { indexFile += array[i] + "\n"; }242 //indexFile += "\ndocument.title = '"+title+"';\n</script>";243 indexFile += "\n<script type='text/nlogo' id='nlogo-code' data-filename='"+title+"'>";244 indexFile += nlogoFile;245 }).then(function() {246 fs.readFileAsync("gbcc/index3.html", "utf8").then(function(data) {247 var array = data.toString().split("\n");248 for (i in array) { indexFile += array[i] + "\n"; }249 }).then(function() {250 //console.log(configFile);251 zip.file("config.json", configFile);252 zip.file("index.html", indexFile);253 254 fs.readFileAsync("gbcc/app/gbcc/exportworld.js", "utf8").then(function(data) {255 zip.file("app/gbcc/exportworld.js", data);256 }).then(function() {257 fs.readFileAsync("gbcc/app/gbcc/font-awesome.min.css", "utf8").then(function(data) {258 zip.file("app/gbcc/font-awesome.min.css", data);259 }).then(function() {260 fs.readFileAsync("gbcc/app/gbcc/fontawesome-webfont.eot").then(function(data) {261 zip.file("app/gbcc/fontawesome-webfont.eot", data);262 }).then(function() {263 fs.readFileAsync("gbcc/app/gbcc/fontawesome-webfont.svg").then(function(data) {264 zip.file("app/gbcc/fontawesome-webfont.svg", data);265 }).then(function() {266 fs.readFileAsync("gbcc/app/gbcc/fontawesome-webfont.ttf").then(function(data) {267 zip.file("app/gbcc/fontawesome-webfont.ttf", data);268 }).then(function() {269 fs.readFileAsync("gbcc/app/gbcc/fontawesome-webfont.woff").then(function(data) {270 zip.file("app/gbcc/fontawesome-webfont.woff", data);271 }).then(function() {272 fs.readFileAsync("gbcc/app/gbcc/fontawesome-webfont.woff2").then(function(data) {273 zip.file("app/gbcc/fontawesome-webfont.woff2", data);274 }).then(function() {275 fs.readFileAsync("gbcc/app/gbcc/gbcc-client.js", "utf8").then(function(data) {276 zip.file("app/gbcc/gbcc-client.js", data);277 }).then(function() {278 fs.readFileAsync("gbcc/app/gbcc/gbcc-events.js", "utf8").then(function(data) {279 zip.file("app/gbcc/gbcc-events.js", data);280 }).then(function() {281 fs.readFileAsync("gbcc/app/gbcc/gbcc-export.js", "utf8").then(function(data) {282 zip.file("app/gbcc/gbcc-export.js", data);283 }).then(function() {284 fs.readFileAsync("gbcc/app/gbcc/gbcc-files.js", "utf8").then(function(data) {285 zip.file("app/gbcc/gbcc-files.js", data);286 }).then(function() {287 fs.readFileAsync("gbcc/app/gbcc/gbcc-gallery.js", "utf8").then(function(data) {288 zip.file("app/gbcc/gbcc-gallery.js", data);289 }).then(function() {290 fs.readFileAsync("gbcc/app/gbcc/gbcc-gallery.css", "utf8").then(function(data) {291 zip.file("app/gbcc/gbcc-gallery.css", data);292 }).then(function() {293 fs.readFileAsync("gbcc/app/gbcc/gbcc-interface.js", "utf8").then(function(data) {294 zip.file("app/gbcc/gbcc-interface.js", data);295 }).then(function() {296 fs.readFileAsync("gbcc/app/gbcc/graph.js", "utf8").then(function(data) {297 zip.file("app/gbcc/graph.js", data);298 }).then(function() {299 fs.readFileAsync("gbcc/app/gbcc/html2canvas.min.js", "utf8").then(function(data) {300 zip.file("app/gbcc/html2canvas.min.js", data);301 }).then(function() {302 fs.readFileAsync("gbcc/app/gbcc/gbcc-image.js", "utf8").then(function(data) {303 zip.file("app/gbcc/gbcc-image.js", data);304 }).then(function() {305 fs.readFileAsync("gbcc/app/gbcc/jquery.min.js", "utf8").then(function(data) {306 zip.file("app/gbcc/jquery.min.js", data);307 }).then(function() {308 fs.readFileAsync("gbcc/app/gbcc/maps.js", "utf8").then(function(data) {309 zip.file("app/gbcc/maps.js", data);310 }).then(function() {311 fs.readFileAsync("gbcc/app/gbcc/physics-api.js", "utf8").then(function(data) {312 zip.file("app/gbcc/physics-api.js", data);313 }).then(function() {314 fs.readFileAsync("gbcc/app/gbcc/physics-box2d.js", "utf8").then(function(data) {315 zip.file("app/gbcc/physics-box2d.js", data);316 }).then(function() {317 fs.readFileAsync("gbcc/app/gbcc/physics-ui/a1.png").then(function(data) {318 zip.file("app/gbcc/physics-ui/a1.png", data);319 }).then(function() {320 fs.readFileAsync("gbcc/app/gbcc/physics-ui/a2.png").then(function(data) {321 zip.file("app/gbcc/physics-ui/a2.png", data);322 }).then(function() {323 fs.readFileAsync("gbcc/app/gbcc/physics-ui/a3.png").then(function(data) {324 zip.file("app/gbcc/physics-ui/a3.png", data);325 }).then(function() {326 fs.readFileAsync("gbcc/app/gbcc/physics-ui/a4.png").then(function(data) {327 zip.file("app/gbcc/physics-ui/a4.png", data);328 }).then(function() {329 fs.readFileAsync("gbcc/app/gbcc/physics-ui/a5.png").then(function(data) {330 zip.file("app/gbcc/physics-ui/a5.png", data);331 }).then(function() {332 fs.readFileAsync("gbcc/app/gbcc/physics-ui/a6.png").then(function(data) {333 zip.file("app/gbcc/physics-ui/a6.png", data);334 }).then(function() {335 fs.readFileAsync("gbcc/app/gbcc/physics-ui/a7.png").then(function(data) {336 zip.file("app/gbcc/physics-ui/a7.png", data);337 }).then(function() {338 fs.readFileAsync("gbcc/app/gbcc/physics-ui/a8.png").then(function(data) {339 zip.file("app/gbcc/physics-ui/a8.png", data);340 }).then(function() {341 fs.readFileAsync("gbcc/app/gbcc/physics-ui/a22.png").then(function(data) {342 zip.file("app/gbcc/physics-ui/a22.png", data);343 }).then(function() {344 fs.readFileAsync("gbcc/app/gbcc/physics-ui/a23.png").then(function(data) {345 zip.file("app/gbcc/physics-ui/a23.png", data);346 }).then(function() {347 fs.readFileAsync("gbcc/app/gbcc/physics.js", "utf8").then(function(data) {348 zip.file("app/gbcc/physics.js", data);349 }).then(function() {350 fs.readFileAsync("gbcc/app/gbcc/style.css", "utf8").then(function(data) {351 zip.file("app/gbcc/style.css", data);352 }).then(function() {353 fs.readFileAsync("gbcc/app/netlogoweb/alert.css", "utf8").then(function(data) {354 zip.file("app/netlogoweb/alert.css", data);355 }).then(function() {356 fs.readFileAsync("gbcc/app/netlogoweb/babybehaviorspace.js", "utf8").then(function(data) {357 zip.file("app/netlogoweb/babybehaviorspace.js", data);358 }).then(function() {359 fs.readFileAsync("gbcc/app/netlogoweb/button.js", "utf8").then(function(data) {360 zip.file("app/netlogoweb/button.js", data);361 }).then(function() {362 fs.readFileAsync("gbcc/app/netlogoweb/checkbox.js", "utf8").then(function(data) {363 zip.file("app/netlogoweb/checkbox.js", data);364 }).then(function() {365 fs.readFileAsync("gbcc/app/netlogoweb/chooser.js", "utf8").then(function(data) {366 zip.file("app/netlogoweb/chooser.js", data);367 }).then(function() {368 fs.readFileAsync("gbcc/app/netlogoweb/chosen.css", "utf8").then(function(data) {369 zip.file("app/netlogoweb/chosen.css", data);370 }).then(function() {371 fs.readFileAsync("gbcc/app/netlogoweb/chosen.jquery.js", "utf8").then(function(data) {372 zip.file("app/netlogoweb/chosen.jquery.js", data);373 }).then(function() {374 fs.readFileAsync("gbcc/app/netlogoweb/classes.css", "utf8").then(function(data) {375 zip.file("app/netlogoweb/classes.css", data);376 }).then(function() {377 fs.readFileAsync("gbcc/app/netlogoweb/code-container.js", "utf8").then(function(data) {378 zip.file("app/netlogoweb/code-container.js", data);379 }).then(function() {380 fs.readFileAsync("gbcc/app/netlogoweb/code-editor.js", "utf8").then(function(data) {381 zip.file("app/netlogoweb/code-editor.js", data);382 }).then(function() {383 fs.readFileAsync("gbcc/app/netlogoweb/codemirror-mode.js", "utf8").then(function(data) {384 zip.file("app/netlogoweb/codemirror-mode.js", data);385 }).then(function() {386 fs.readFileAsync("gbcc/app/netlogoweb/codemirror.css", "utf8").then(function(data) {387 zip.file("app/netlogoweb/codemirror.css", data);388 }).then(function() {389 fs.readFileAsync("gbcc/app/netlogoweb/codemirror.js", "utf8").then(function(data) {390 zip.file("app/netlogoweb/codemirror.js", data);391 }).then(function() {392 fs.readFileAsync("gbcc/app/netlogoweb/color-input.js", "utf8").then(function(data) {393 zip.file("app/netlogoweb/color-input.js", data);394 }).then(function() {395 fs.readFileAsync("gbcc/app/netlogoweb/colors.js", "utf8").then(function(data) {396 zip.file("app/netlogoweb/colors.js", data);397 }).then(function() {398 fs.readFileAsync("gbcc/app/netlogoweb/config-shims.js", "utf8").then(function(data) {399 zip.file("app/netlogoweb/config-shims.js", data);400 }).then(function() {401 fs.readFileAsync("gbcc/app/netlogoweb/console.js", "utf8").then(function(data) {402 zip.file("app/netlogoweb/console.js", data);403 }).then(function() {404 fs.readFileAsync("gbcc/app/netlogoweb/context-menu.js", "utf8").then(function(data) {405 zip.file("app/netlogoweb/context-menu.js", data);406 }).then(function() {407 fs.readFileAsync("gbcc/app/netlogoweb/default-shapes.js", "utf8").then(function(data) {408 zip.file("app/netlogoweb/default-shapes.js", data);409 }).then(function() {410 fs.readFileAsync("gbcc/app/netlogoweb/dialog.css", "utf8").then(function(data) {411 zip.file("app/netlogoweb/dialog.css", data);412 }).then(function() {413 fs.readFileAsync("gbcc/app/netlogoweb/dialog.js", "utf8").then(function(data) {414 zip.file("app/netlogoweb/dialog.js", data);415 }).then(function() {416 fs.readFileAsync("gbcc/app/netlogoweb/draggable.js", "utf8").then(function(data) {417 zip.file("app/netlogoweb/draggable.js", data);418 }).then(function() {419 fs.readFileAsync("gbcc/app/netlogoweb/draw-shape.js", "utf8").then(function(data) {420 zip.file("app/netlogoweb/draw-shape.js", data);421 }).then(function() {422 fs.readFileAsync("gbcc/app/netlogoweb/dropdown.js", "utf8").then(function(data) {423 zip.file("app/netlogoweb/dropdown.js", data);424 }).then(function() {425 fs.readFileAsync("gbcc/app/netlogoweb/edit-form.js", "utf8").then(function(data) {426 zip.file("app/netlogoweb/edit-form.js", data);427 }).then(function() {428 fs.readFileAsync("gbcc/app/netlogoweb/element-overrides.css", "utf8").then(function(data) {429 zip.file("app/netlogoweb/element-overrides.css", data);430 }).then(function() {431 fs.readFileAsync("gbcc/app/netlogoweb/event-traffic-control.js", "utf8").then(function(data) {432 zip.file("app/netlogoweb/event-traffic-control.js", data);433 }).then(function() {434 fs.readFileAsync("gbcc/app/netlogoweb/export-data.js", "utf8").then(function(data) {435 zip.file("app/netlogoweb/export-data.js", data);436 }).then(function() {437 fs.readFileAsync("gbcc/app/netlogoweb/exporting.js", "utf8").then(function(data) {438 zip.file("app/netlogoweb/exporting.js", data);439 }).then(function() {440 fs.readFileAsync("gbcc/app/netlogoweb/FileSaver.js", "utf8").then(function(data) {441 zip.file("app/netlogoweb/FileSaver.js", data);442 }).then(function() {443 fs.readFileAsync("gbcc/app/netlogoweb/font-size.js", "utf8").then(function(data) {444 zip.file("app/netlogoweb/font-size.js", data);445 }).then(function() {446 fs.readFileAsync("gbcc/app/netlogoweb/global-noisy-things.js", "utf8").then(function(data) {447 zip.file("app/netlogoweb/global-noisy-things.js", data);448 }).then(function() {449 fs.readFileAsync("gbcc/app/netlogoweb/handle-context-menu.js", "utf8").then(function(data) {450 zip.file("app/netlogoweb/handle-context-menu.js", data);451 }).then(function() {452 fs.readFileAsync("gbcc/app/netlogoweb/handle-widget-selection.js", "utf8").then(function(data) {453 zip.file("app/netlogoweb/handle-widget-selection.js", data);454 }).then(function() {455 fs.readFileAsync("gbcc/app/netlogoweb/help-dialog.js", "utf8").then(function(data) {456 zip.file("app/netlogoweb/help-dialog.js", data);457 }).then(function() {458 fs.readFileAsync("gbcc/app/netlogoweb/highcharts.js", "utf8").then(function(data) {459 zip.file("app/netlogoweb/highcharts.js", data);460 }).then(function() {461 fs.readFileAsync("gbcc/app/netlogoweb/highcharts(1).js", "utf8").then(function(data) {462 zip.file("app/netlogoweb/highcharts(1).js", data);463 }).then(function() {464 fs.readFileAsync("gbcc/app/netlogoweb/html-sanitizer-minified.js", "utf8").then(function(data) {465 zip.file("app/netlogoweb/html-sanitizer-minified.js", data);466 }).then(function() {467 fs.readFileAsync("gbcc/app/netlogoweb/info.js", "utf8").then(function(data) {468 zip.file("app/netlogoweb/info.js", data);469 }).then(function() {470 fs.readFileAsync("gbcc/app/netlogoweb/initialize-ui.js", "utf8").then(function(data) {471 zip.file("app/netlogoweb/initialize-ui.js", data);472 }).then(function() {473 fs.readFileAsync("gbcc/app/netlogoweb/input.js", "utf8").then(function(data) {474 zip.file("app/netlogoweb/input.js", data);475 }).then(function() {476 fs.readFileAsync("gbcc/app/netlogoweb/jquery.js", "utf8").then(function(data) {477 zip.file("app/netlogoweb/jquery.js", data);478 }).then(function() {479 fs.readFileAsync("gbcc/app/netlogoweb/jquery.min.js", "utf8").then(function(data) {480 zip.file("app/netlogoweb/jquery.min.js", data);481 }).then(function() {482 fs.readFileAsync("gbcc/app/netlogoweb/keywords.js", "utf8").then(function(data) {483 zip.file("app/netlogoweb/keywords.js", data);484 }).then(function() {485 fs.readFileAsync("gbcc/app/netlogoweb/label.js", "utf8").then(function(data) {486 zip.file("app/netlogoweb/label.js", data);487 }).then(function() {488 fs.readFileAsync("gbcc/app/netlogoweb/labeled-input.js", "utf8").then(function(data) {489 zip.file("app/netlogoweb/labeled-input.js", data);490 }).then(function() {491 fs.readFileAsync("gbcc/app/netlogoweb/link-drawer.js", "utf8").then(function(data) {492 zip.file("app/netlogoweb/link-drawer.js", data);493 }).then(function() {494 fs.readFileAsync("gbcc/app/netlogoweb/markdown.js", "utf8").then(function(data) {495 zip.file("app/netlogoweb/markdown.js", data);496 }).then(function() {497 fs.readFileAsync("gbcc/app/netlogoweb/models.js", "utf8").then(function(data) {498 zip.file("app/netlogoweb/models.js", data);499 }).then(function() {500 fs.readFileAsync("gbcc/app/netlogoweb/monitor.js", "utf8").then(function(data) {501 zip.file("app/netlogoweb/monitor.js", data);502 }).then(function() {503 fs.readFileAsync("gbcc/app/netlogoweb/mousetrap.js", "utf8").then(function(data) {504 zip.file("app/netlogoweb/mousetrap.js", data);505 }).then(function() {506 fs.readFileAsync("gbcc/app/netlogoweb/netlogo-engine.js", "utf8").then(function(data) {507 zip.file("app/netlogoweb/netlogo-engine.js", data);508 }).then(function() {509 fs.readFileAsync("gbcc/app/netlogoweb/netlogo-syntax.css", "utf8").then(function(data) {510 zip.file("app/netlogoweb/netlogo-syntax.css", data);511 }).then(function() {512 fs.readFileAsync("gbcc/app/netlogoweb/netlogoweb.css", "utf8").then(function(data) {513 zip.file("app/netlogoweb/netlogoweb.css", data);514 }).then(function() {515 fs.readFileAsync("gbcc/app/netlogoweb/new-model.js", "utf8").then(function(data) {516 zip.file("app/netlogoweb/new-model.js", data);517 }).then(function() {518 fs.readFileAsync("gbcc/app/netlogoweb/output.js", "utf8").then(function(data) {519 zip.file("app/netlogoweb/output.js", data);520 }).then(function() {521 fs.readFileAsync("gbcc/app/netlogoweb/plot.js", "utf8").then(function(data) {522 zip.file("app/netlogoweb/plot.js", data);523 }).then(function() {524 fs.readFileAsync("gbcc/app/netlogoweb/print-area.js", "utf8").then(function(data) {525 zip.file("app/netlogoweb/print-area.js", data);526 }).then(function() {527 fs.readFileAsync("gbcc/app/netlogoweb/ractive.js", "utf8").then(function(data) {528 zip.file("app/netlogoweb/ractive.js", data);529 }).then(function() {530 fs.readFileAsync("gbcc/app/netlogoweb/resizer.js", "utf8").then(function(data) {531 zip.file("app/netlogoweb/resizer.js", data);532 }).then(function() {533 fs.readFileAsync("gbcc/app/netlogoweb/search.js", "utf8").then(function(data) {534 zip.file("app/netlogoweb/search.js", data);535 }).then(function() {536 fs.readFileAsync("gbcc/app/netlogoweb/searchcursor.js", "utf8").then(function(data) {537 zip.file("app/netlogoweb/searchcursor.js", data);538 }).then(function() {539 fs.readFileAsync("gbcc/app/netlogoweb/session-lite.js", "utf8").then(function(data) {540 zip.file("app/netlogoweb/session-lite.js", data);541 }).then(function() {542 fs.readFileAsync("gbcc/app/netlogoweb/set-up-widgets.js", "utf8").then(function(data) {543 zip.file("app/netlogoweb/set-up-widgets.js", data);544 }).then(function() {545 fs.readFileAsync("gbcc/app/netlogoweb/simple.js", "utf8").then(function(data) {546 zip.file("app/netlogoweb/simple.js", data);547 }).then(function() {548 fs.readFileAsync("gbcc/app/netlogoweb/skeleton.js", "utf8").then(function(data) {549 zip.file("app/netlogoweb/skeleton.js", data);550 }).then(function() {551 fs.readFileAsync("gbcc/app/netlogoweb/slider.js", "utf8").then(function(data) {552 zip.file("app/netlogoweb/slider.js", data);553 }).then(function() {554 fs.readFileAsync("gbcc/app/netlogoweb/spacer.js", "utf8").then(function(data) {555 zip.file("app/netlogoweb/spacer.js", data);556 }).then(function() {557 fs.readFileAsync("gbcc/app/netlogoweb/spinner.css", "utf8").then(function(data) {558 zip.file("app/netlogoweb/spinner.css", data);559 }).then(function() {560 fs.readFileAsync("gbcc/app/netlogoweb/switch.js", "utf8").then(function(data) {561 zip.file("app/netlogoweb/switch.js", data);562 }).then(function() {563 fs.readFileAsync("gbcc/app/netlogoweb/theme.css", "utf8").then(function(data) {564 zip.file("app/netlogoweb/theme.css", data);565 }).then(function() {566 fs.readFileAsync("gbcc/app/netlogoweb/tick-counter.js", "utf8").then(function(data) {567 zip.file("app/netlogoweb/tick-counter.js", data);568 }).then(function() {569 fs.readFileAsync("gbcc/app/netlogoweb/title.js", "utf8").then(function(data) {570 zip.file("app/netlogoweb/title.js", data);571 }).then(function() {572 fs.readFileAsync("gbcc/app/netlogoweb/topbar.js", "utf8").then(function(data) {573 zip.file("app/netlogoweb/topbar.js", data);574 }).then(function() {575 fs.readFileAsync("gbcc/app/netlogoweb/tortoise-compiler.js", "utf8").then(function(data) {576 zip.file("app/netlogoweb/tortoise-compiler.js", data);577 }).then(function() {578 fs.readFileAsync("gbcc/app/netlogoweb/tortoise.css", "utf8").then(function(data) {579 zip.file("app/netlogoweb/tortoise.css", data);580 }).then(function() {581 fs.readFileAsync("gbcc/app/netlogoweb/tortoise.js", "utf8").then(function(data) {582 zip.file("app/netlogoweb/tortoise.js", data);583 }).then(function() {584 fs.readFileAsync("gbcc/app/netlogoweb/ui-editor.css", "utf8").then(function(data) {585 zip.file("app/netlogoweb/ui-editor.css", data);586 }).then(function() {587 fs.readFileAsync("gbcc/app/netlogoweb/variable.js", "utf8").then(function(data) {588 zip.file("app/netlogoweb/variable.js", data);589 }).then(function() {590 fs.readFileAsync("gbcc/app/netlogoweb/view-controller.js", "utf8").then(function(data) {591 zip.file("app/netlogoweb/view-controller.js", data);592 }).then(function() {593 fs.readFileAsync("gbcc/app/netlogoweb/view.js", "utf8").then(function(data) {594 zip.file("app/netlogoweb/view.js", data);595 }).then(function() {596 fs.readFileAsync("gbcc/app/netlogoweb/web.html", "utf8").then(function(data) {597 zip.file("app/netlogoweb/web.html", data);598 }).then(function() {599 fs.readFileAsync("gbcc/app/netlogoweb/widget-controller.js", "utf8").then(function(data) {600 zip.file("app/netlogoweb/widget-controller.js", data);601 }).then(function() {602 fs.readFileAsync("gbcc/app/netlogoweb/widget.js", "utf8").then(function(data) {603 zip.file("app/netlogoweb/widget.js", data);604 }).then(function() {605 fs.readFileAsync("gbcc/app/netlogoweb/widgets.css", "utf8").then(function(data) {606 zip.file("app/netlogoweb/widgets.css", data);607 }).then(function() {608 fs.readFileAsync("gbcc/geogebra-default.ggb").then(function(data) {609 zip.file("geogebra-default.ggb", data);610 }).then(function() {611 fs.readFileAsync("gbcc/ocean.png").then(function(data) {612 zip.file("ocean.png", data);613 }).then(function() {614 fs.readFileAsync("gbcc/package.json", "utf8").then(function(data) {615 zip.file("package.json", data);616 }).then(function() {617 fs.readFileAsync("gbcc/readme.md", "utf8").then(function(data) {618 zip.file("readme.md", data);619 }).then(function() {620 fs.readFileAsync("gbcc/server.js", "utf8").then(function(data) {621 zip.file("server.js", data);622 }).then(function() {623 fs.readFileAsync("gbcc/app/netlogoweb/async-user-dialog.js").then(function(data) {624 zip.file("app/netlogoweb/async-user-dialog.js", data);625 }).then(function() {626 fs.readFileAsync("gbcc/app/netlogoweb/jscolor.js", "utf8").then(function(data) {627 zip.file("app/netlogoweb/jscolor.js", data);628 }).then(function() {629 fs.readFileAsync("gbcc/app/netlogoweb/synchrodecoder.min.js", "utf8").then(function(data) {630 zip.file("app/netlogoweb/synchrodecoder.min.js", data);631 }).then(function() {632 fs.readFileAsync("gbcc/app/netlogoweb/localforage.min.js", "utf8").then(function(data) {633 zip.file("app/netlogoweb/localforage.min.js", data);634 }).then(function() {635 fs.readFileAsync("gbcc/app/gbcc/geogebra_defaults2d.xml", "utf8").then(function(data) {636 zip.file("app/gbcc/geogebra_defaults2d.xml", data);637 }).then(function() {638 fs.readFileAsync("gbcc/app/gbcc/geogebra_defaults3d.xml", "utf8").then(function(data) {639 zip.file("app/gbcc/geogebra_defaults3d.xml", data);640 }).then(function() {641 fs.readFileAsync("gbcc/app/gbcc/geogebra_javascript.js", "utf8").then(function(data) {642 zip.file("app/gbcc/geogebra_javascript.js", data);643 }).then(function() {644 fs.readFileAsync("gbcc/app/gbcc/geogebra_thumbnail.png").then(function(data) {645 zip.file("app/gbcc/geogebra_thumbnail.png ", data);646 }).then(function() {647 fs.readFileAsync("gbcc/app/netlogoweb/comment.js", "utf8").then(function(data) {648 zip.file("app/netlogoweb/comment.js", data);649 }).then(function() {650 fs.readFileAsync("gbcc/app/netlogoweb/show-hint.js", "utf8").then(function(data) {651 zip.file("app/netlogoweb/show-hint.js", data);652 }).then(function() {653 fs.readFileAsync("gbcc/app/netlogoweb/show-hint.css").then(function(data) {654 zip.file("app/netlogoweb/show-hint.css", data);655 }).then(function() {656 zip.generateNodeStream({type:'nodebuffer',streamFiles:true})657 .pipe(fs.createWriteStream(filename+'.zip'))658 .on('finish', function () {659 res.download(filename+'.zip', function() {660 var fullPath= __dirname + '/'+filename+'.zip';661 console.log(fullPath);662 fs.unlink(fullPath, function() {663 console.log(fullPath + " deleted");664 });665 });666 });667 }).catch(function(e) {...

Full Screen

Full Screen

ingest.js

Source:ingest.js Github

copy

Full Screen

...20 resolve(data);21 });22 });23};24fs.readFileAsync(rootPath + 'timesteps.csv')25 // read time series then start parsing and storing demand 26 .then((data) => {27 timeseries = _.map(data.split("\n").slice(1, data.split("\n").length - 1), (d) => d.split(",")[1].split(" ")[0]);28 return fs.readFileAsync(rootPath + 'demand_base.csv');29 })30 .then((data) => createMultiple(parseDemand(data, model, 'base', 'base')))31 .then((data) => fs.readFileAsync(rootPath + 'demand_five_increase.csv'))32 .then((data) => createMultiple(parseDemand(data, model, 'five', 'increase')))33 .then((data) => fs.readFileAsync(rootPath + 'demand_ten_increase.csv'))34 .then((data) => createMultiple(parseDemand(data, model, 'ten', 'increase')))35 .then((data) => fs.readFileAsync(rootPath + 'demand_five_decrease.csv'))36 .then((data) => createMultiple(parseDemand(data, model, 'five', 'decrease')))37 .then((data) => fs.readFileAsync(rootPath + 'demand_ten_decrease.csv'))38 .then((data) => createMultiple(parseDemand(data, model, 'ten', 'decrease')))39 // start parsing and storing inflow 40 .then((data) => fs.readFileAsync(rootPath + 'inflow_base.csv'))41 .then((data) => createMultiple(parseInflow(data, model, 'base', 'base')))42 .then((data) => fs.readFileAsync(rootPath + 'inflow_five_increase.csv'))43 .then((data) => createMultiple(parseInflow(data, model, 'five', 'increase')))44 .then((data) => fs.readFileAsync(rootPath + 'inflow_ten_increase.csv'))45 .then((data) => createMultiple(parseInflow(data, model, 'ten', 'increase')))46 .then((data) => fs.readFileAsync(rootPath + 'inflow_five_decrease.csv'))47 .then((data) => createMultiple(parseInflow(data, model, 'five', 'decrease')))48 .then((data) => fs.readFileAsync(rootPath + 'inflow_ten_decrease.csv'))49 .then((data) => createMultiple(parseInflow(data, model, 'ten', 'decrease')))50 // start parsing and storing links51 .then((data) => fs.readFileAsync(rootPath + 'links_base.csv'))52 .then((data) => createMultiple(parseLinks(data, model, 'base', 'base')))53 .then((data) => fs.readFileAsync(rootPath + 'links_five_increase.csv'))54 .then((data) => createMultiple(parseLinks(data, model, 'five', 'increase')))55 .then((data) => fs.readFileAsync(rootPath + 'links_ten_increase.csv'))56 .then((data) => createMultiple(parseLinks(data, model, 'ten', 'increase')))57 .then((data) => fs.readFileAsync(rootPath + 'links_five_decrease.csv'))58 .then((data) => createMultiple(parseLinks(data, model, 'five', 'decrease')))59 .then((data) => fs.readFileAsync(rootPath + 'links_ten_decrease.csv'))60 .then((data) => createMultiple(parseLinks(data, model, 'ten', 'decrease')))61 // start parsing and storing reservoir info62 .then((data) => fs.readFileAsync(rootPath + 'reservoir_base.csv'))63 .then((data) => createMultiple(parseReservoir(data, model, 'base', 'base')))64 .then((data) => fs.readFileAsync(rootPath + 'reservoir_five_increase.csv'))65 .then((data) => createMultiple(parseReservoir(data, model, 'five', 'increase')))66 .then((data) => fs.readFileAsync(rootPath + 'reservoir_ten_increase.csv'))67 .then((data) => createMultiple(parseReservoir(data, model, 'ten', 'increase')))68 .then((data) => fs.readFileAsync(rootPath + 'reservoir_five_decrease.csv'))69 .then((data) => createMultiple(parseReservoir(data, model, 'five', 'decrease')))70 .then((data) => fs.readFileAsync(rootPath + 'reservoir_ten_decrease.csv'))71 .then((data) => createMultiple(parseReservoir(data, model, 'ten', 'decrease')))72 .then((data) => {73 console.log("all records ingested without any errors for model -", model);74 })75 .catch((error) => {76 console.log(error);77 })78function parseDemand(data, modelID, threshold, condition) {79 var dataStore = data.split("\n"),80 line,81 tempStore = [];82 for (lineIndex = 1; lineIndex < dataStore.length - 1; lineIndex++) {83 line = dataStore[lineIndex].split(",");84 tempStore.push({...

Full Screen

Full Screen

extract-stream.js

Source:extract-stream.js Github

copy

Full Screen

...23 t.plan(2)24 return mockTar(pkg, { stream: true }).then(tarStream => {25 return pipe(tarStream, extractStream('foo@1', './'))26 }).then(() => {27 return fs.readFileAsync('./package.json', 'utf8')28 }).then(data => {29 t.deepEqual(data, pkg['package.json'], 'extracted package.json')30 return fs.readFileAsync('./index.js', 'utf8')31 }).then(data => {32 t.equal(data, pkg['index.js'], 'extracted index.js')33 })34})35test('adds metadata fields if resolved/integrity are present', t => {36 const pkg = {37 'package.json': JSON.stringify({38 name: 'foo',39 version: '1.0.0'40 }),41 'index.js': 'console.log("hello world!")'42 }43 return mockTar(pkg, { stream: true }).then(tarStream => {44 return pipe(tarStream, extractStream('foo@1', './', {45 resolved: 'https://stuff.is.here',46 integrity: 'sha1-deadbeef'47 }))48 }).then(() => {49 return fs.readFileAsync('./package.json', 'utf8')50 }).then(data => {51 t.deepEqual(JSON.parse(data), {52 name: 'foo',53 version: '1.0.0',54 _resolved: 'https://stuff.is.here',55 _integrity: 'sha1-deadbeef',56 _from: 'foo@1'57 }, 'extracted package.json')58 })59})60test('automatically handles gzipped tarballs', t => {61 const pkg = {62 'package.json': JSON.stringify({63 name: 'foo',64 version: '1.0.0'65 }),66 'index.js': 'console.log("hello world!")'67 }68 return mockTar(pkg, { gzip: true, stream: true }).then(tarStream => {69 return pipe(tarStream, extractStream('foo@1', './', OPTS))70 }).then(() => {71 return BB.join(72 fs.readFileAsync('./package.json', 'utf8'),73 fs.readFileAsync('./index.js', 'utf8'),74 (json, indexjs) => {75 t.deepEqual(json, pkg['package.json'], 'got gunzipped package.json')76 t.equal(indexjs, pkg['index.js'], 'got gunzipped index.js')77 }78 )79 })80})81test('strips first item in path, even if not `package/`', t => {82 const pkg = {83 'package/package.json': JSON.stringify({84 name: 'foo',85 version: '1.0.0'86 }),87 'something-else/index.js': 'console.log("hello world!")'88 }89 return mockTar(pkg, { noPrefix: true, stream: true }).then(tarStream => {90 return pipe(tarStream, extractStream('foo@1', './', OPTS))91 }).then(() => {92 return BB.join(93 fs.readFileAsync('./package.json', 'utf8'),94 fs.readFileAsync('./index.js', 'utf8'),95 (json, indexjs) => {96 t.deepEqual(97 json, pkg['package/package.json'], 'flattened package.json')98 t.equal(99 indexjs, pkg['something-else/index.js'], 'flattened index.js')100 }101 )102 })103})104test('excludes symlinks', t => {105 const pkg = {106 'package.json': JSON.stringify({107 name: 'foo',108 version: '1.0.0'109 }),110 'index.js': 'console.log("hello world!")',111 'linky': { type: 'Link', linkname: '/usr/local/bin/linky' },112 'symmylinky': { type: 'SymbolicLink', linkname: '../nowhere' }113 }114 return mockTar(pkg, { stream: true }).then(tarStream => {115 return pipe(tarStream, extractStream('foo@1', './', OPTS))116 }).then(() => {117 return BB.join(118 fs.readFileAsync('./package.json', 'utf8').then(data => {119 t.deepEqual(data, pkg['package.json'], 'package.json still there')120 }),121 fs.statAsync('./linky').then(122 stat => { throw new Error('this was supposed to error' + JSON.stringify(stat)) },123 err => {124 t.equal(err.code, 'ENOENT', 'hard link excluded!')125 }126 ),127 fs.readFileAsync('./symmylinky').then(128 () => { throw new Error('this was supposed to error') },129 err => {130 t.equal(err.code, 'ENOENT', 'symlink excluded!')131 }132 )133 )134 })135})136// Yes, this logic is terrible and seriously confusing, but137// I'm pretty sure this is exactly what npm is doing.138// ...we should really deprecate this cluster.139test('renames .gitignore to .npmignore if not present', t => {140 return mkdirp('./no-npmignore').then(() => {141 return mockTar({142 'package.json': JSON.stringify({143 name: 'foo',144 version: '1.0.0'145 }),146 'index.js': 'console.log("hello world!")',147 '.gitignore': 'tada!'148 }, { stream: true }).then(tarStream => {149 return pipe(tarStream, extractStream('foo@1', './no-npmignore', OPTS))150 }).then(() => {151 return fs.readFileAsync(152 './no-npmignore/.npmignore', 'utf8'153 ).then(data => {154 t.deepEqual(data, 'tada!', '.gitignore renamed to .npmignore')155 })156 })157 }).then(() => {158 return mkdirp('./has-npmignore1')159 }).then(() => {160 return mockTar({161 'package.json': JSON.stringify({162 name: 'foo',163 version: '1.0.0'164 }),165 'index.js': 'console.log("hello world!")',166 '.gitignore': 'git!',167 '.npmignore': 'npm!'168 }, { stream: true }).then(tarStream => {169 return pipe(tarStream, extractStream('foo@1', './has-npmignore1', OPTS))170 }).then(() => {171 return BB.join(172 fs.readFileAsync(173 './has-npmignore1/.npmignore', 'utf8'174 ).then(data => {175 t.deepEqual(data, 'npm!', '.npmignore left intact if present')176 }),177 fs.readFileAsync(178 './has-npmignore1/.gitignore', 'utf8'179 ).then(180 () => { throw new Error('expected an error') },181 err => {182 t.ok(err, 'got expected error on reading .gitignore')183 t.equal(err.code, 'ENOENT', '.gitignore missing')184 }185 )186 )187 })188 }).then(() => {189 return mkdirp('./has-npmignore2')190 }).then(() => {191 return mockTar({192 'package.json': JSON.stringify({193 name: 'foo',194 version: '1.0.0'195 }),196 'index.js': 'console.log("hello world!")',197 '.npmignore': 'npm!',198 '.gitignore': 'git!'199 }, { stream: true }).then(tarStream => {200 return pipe(tarStream, extractStream('foo@1', './has-npmignore2', OPTS))201 }).then(() => {202 return BB.join(203 fs.readFileAsync(204 './has-npmignore2/.npmignore', 'utf8'205 ).then(data => {206 t.deepEqual(data, 'npm!', '.npmignore left intact if present')207 }),208 fs.readFileAsync(209 './has-npmignore2/.gitignore', 'utf8'210 ).then(data => {211 t.deepEqual(data, 'git!', '.gitignore intact if we previously had an .npmignore')212 })213 )214 })215 })216})217test('accepts dmode/fmode/umask opts', {218 skip: process.platform === 'win32'219}, t => {220 const pkg = {221 'package.json': {222 data: JSON.stringify({...

Full Screen

Full Screen

config.test.js

Source:config.test.js Github

copy

Full Screen

...39 .readFileAsync(path.resolve(os.homedir(), '.bashrc'), 'utf8')40 .then(bashRcContent =>41 expect(bashRcContent).to.include(' ~/.config/tabtab/__tabtab.bash')42 ),43 fs.readFileAsync(path.resolve(os.homedir(), '.config/tabtab/serverless.bash'), 'utf8'),44 fs.readFileAsync(path.resolve(os.homedir(), '.config/tabtab/sls.bash'), 'utf8'),45 fs.readFileAsync(path.resolve(os.homedir(), '.config/tabtab/slss.bash'), 'utf8'),46 ])47 ));48 it('should support "config tabcompletion uninstall" command', () =>49 runServerless({50 cwd: os.homedir(),51 env: { SHELL: 'bash' },52 cliArgs: ['config', 'tabcompletion', 'install'],53 }).then(() =>54 runServerless({55 cwd: os.homedir(),56 env: { SHELL: 'bash' },57 cliArgs: ['config', 'tabcompletion', 'uninstall'],58 }).then(() =>59 Promise.all([...

Full Screen

Full Screen

read.demo.2.js

Source:read.demo.2.js Github

copy

Full Screen

...3Promise.promisifyAll(fs); // Promisification of FS Module4let readDemo = () => {5 // fs.readFile();6 const filePath1 = "/Users/research/Desktop/temp.txt";7 // fs.readFileAsync(filePath1, { encoding: "utf-8" });8 fs.readFileAsync(filePath1, { encoding: "utf-8" })9 .then((data) => {10 // file 1 done11 console.log(data);12 const filePath2 = "/Users/research/Desktop/temp.txt";13 return fs.readFileAsync(filePath2, { encoding: "utf-8" });14 })15 .then((data) => {16 // file 2 done17 console.log(data);18 const filePath3 = "/Users/research/Desktop/temp.txt";19 return fs.readFileAsync(filePath3, { encoding: "utf-8" });20 })21 .then((data) => {22 // file 3 done23 console.log(data);24 });25};...

Full Screen

Full Screen

09.Generator.js

Source:09.Generator.js Github

copy

Full Screen

...4'use strict';5const Promise = require('bluebird');6const fs = Promise.promisifyAll(require('fs'));7const g = function*(){8 let EventEmitter = yield fs.readFileAsync('01.EventEmitter.js');9 let Callback = yield fs.readFileAsync('02.Callback.js');10};11fs.readFileAsync('01.EventEmitter.js')12 .then((data)=>{13 return fs.readFileAsync('02.Callback.js');14 })15 .then((data)=>{16 console.log(data);17 });18Promise.all([19 fs.readFileAsync('01.EventEmitter.js'),20 fs.readFileAsync('02.Callback.js'),21 fs.readFileAsync('03.Callback2.js'),22]).then((res)=>{23 console.log(Buffer.concat(res).toString());...

Full Screen

Full Screen

08.Promise.js

Source:08.Promise.js Github

copy

Full Screen

...3 */4'use strict';5const Promise = require('bluebird');6const fs = Promise.promisifyAll(require('fs'));7fs.readFileAsync('01.EventEmitter.js')8 .then((data)=>{9 return fs.readFileAsync('02.Callback.js');10 })11 .then((data)=>{12 console.log(data);13 });14Promise.all([15 fs.readFileAsync('01.EventEmitter.js'),16 fs.readFileAsync('02.Callback.js'),17 fs.readFileAsync('03.Callback2.js'),18]).then((res)=>{19 console.log(Buffer.concat(res).toString());...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('My First Test', function() {2 it('Visits the Kitchen Sink', function() {3 cy.contains('type').click()4 cy.url().should('include', '/commands/actions')5 cy.get('.action-email')6 .type('

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('My First Test', function() {2 it('Does not do much!', function() {3 cy.readFile('cypress/fixtures/employees.json').then((employees) => {4 cy.log(employees)5 })6 })7})8 {9 },10 {11 },12 {13 }14 {15 },16 {17 },18 {19 }20describe('My First Test', function() {21 it('Does not do much!', function() {22 cy.writeFile('cypress/fixtures/employees.json', {23 })24 })25})26{27}28describe('My First Test', function() {29 it('Does not do much!', function() {30 cy.readFile('cypress/fixtures/employees.json').then((employees) => {31 cy.log(employees)32 })33 })34})35 {36 },

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('test', () => {2 it('test', () => {3 cy.readFile('test.json').then((data) => {4 console.log(data);5 });6 });7});8{9 "env": {10 }11}12{13}14describe('test', () => {15 it('test', () => {16 cy.readFile(Cypress.env('test')).then((data) => {17 console.log(data);18 });19 });20});21{22 "env": {23 }24}25{26}27describe('test', () => {28 it('test', () => {29 cy.readFile(Cypress.env('test')).then((data) => {30 console.log(data);31 });32 });33});34{35 "env": {36 }37}38{39}40describe('test', () => {41 it('test', () => {42 cy.readFile(Cypress.env('test')).then((data) => {43 console.log(data);44 });45 });46});47{48 "env": {49 }50}51{52}53describe('test', () => {54 it('test', () => {55 cy.readFile(Cypress.env('test')).then((data) => {56 console.log(data);57 });58 });59});60{61 "env": {62 }63}64{65}66describe('test', () => {67 it('test', () => {68 cy.readFile(Cypress.env

Full Screen

Using AI Code Generation

copy

Full Screen

1cy.readFile('cypress/fixtures/test.json').then((json) => {2 expect(json).to.deep.equal({3 { "name": "Ford", "models": ["Fiesta", "Focus", "Mustang"] },4 { "name": "BMW", "models": ["320", "X3", "X5"] },5 { "name": "Fiat", "models": ["500", "Panda"] }6 });7});

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('Read a file', () => {2 it('Read the file', () => {3 cy.readFile('path/to/file').then((fileContent) => {4 })5 })6})7describe('Write to a file', () => {8 it('Write to the file', () => {9 cy.writeFile('path/to/file', 'some content').then((fileContent) => {10 })11 })12})13describe('Upload a file', () => {14 it('Upload the file', () => {15 cy.get('input[type="file"]').attachFile('path/to/file')16 })17})18describe('Upload a file', () => {19 it('Upload the file', () => {20 cy.get('input[type="file"]').attachFile({21 })22 })23})24describe('Download a file', () => {25 it('Download the file', () => {26 cy.get('a.download').click()27 cy.readFile('

Full Screen

Using AI Code Generation

copy

Full Screen

1it('should read a file', () => {2 cy.readFile('file.txt').then((text) => {3 expect(text).to.equal('Hello world!')4 })5})6it('should write to a file', () => {7 cy.writeFile('file.txt', 'Hello world!')8})9it('should run a task', () => {10 cy.task('readFile', 'file.txt').then((text) => {11 expect(text).to.equal('Hello world!')12 })13})14it('should make an HTTP request', () => {15 expect(response.body).to.have.property('name', 'John Doe')16 })17})18it('should execute a command', () => {19 cy.exec('echo Hello world!').then((result) => {20 expect(result.stdout).to.equal('Hello world!')21 })22})23it('should spawn a child process', () => {24 cy.spawn('node', ['--version']).then((result) => {25 expect(result.stdout).to.match(/^v\d+\.\d+\.\d+$/)26 })27})28- **cy.fixture()** - This

Full Screen

Using AI Code Generation

copy

Full Screen

1import {readFileAsync} from 'fs-extra'2it('Uploads a file', () => {3 cy.fixture('test.png', 'base64').then(fileContent => {4 cy.request({5 headers: {6 }7 })8 })9})

Full Screen

Cypress Tutorial

Cypress is a renowned Javascript-based open-source, easy-to-use end-to-end testing framework primarily used for testing web applications. Cypress is a relatively new player in the automation testing space and has been gaining much traction lately, as evidenced by the number of Forks (2.7K) and Stars (42.1K) for the project. LambdaTest’s Cypress Tutorial covers step-by-step guides that will help you learn from the basics till you run automation tests on LambdaTest.

Chapters:

  1. What is Cypress? -
  2. Why Cypress? - Learn why Cypress might be a good choice for testing your web applications.
  3. Features of Cypress Testing - Learn about features that make Cypress a powerful and flexible tool for testing web applications.
  4. Cypress Drawbacks - Although Cypress has many strengths, it has a few limitations that you should be aware of.
  5. Cypress Architecture - Learn more about Cypress architecture and how it is designed to be run directly in the browser, i.e., it does not have any additional servers.
  6. Browsers Supported by Cypress - Cypress is built on top of the Electron browser, supporting all modern web browsers. Learn browsers that support Cypress.
  7. Selenium vs Cypress: A Detailed Comparison - Compare and explore some key differences in terms of their design and features.
  8. Cypress Learning: Best Practices - Take a deep dive into some of the best practices you should use to avoid anti-patterns in your automation tests.
  9. How To Run Cypress Tests on LambdaTest? - Set up a LambdaTest account, and now you are all set to learn how to run Cypress tests.

Certification

You can elevate your expertise with end-to-end testing using the Cypress automation framework and stay one step ahead in your career by earning a Cypress certification. Check out our Cypress 101 Certification.

YouTube

Watch this 3 hours of complete tutorial to learn the basics of Cypress and various Cypress commands with the Cypress testing at LambdaTest.

Run Cypress automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful