Best JavaScript code snippet using storybook-root
test-utils.spec.js
Source:test-utils.spec.js
1/* global describe, beforeEach, it */2const fse = require('fs-extra');3const chai = require('chai');4const dirtyChai = require('dirty-chai');5const path = require('path');6const os = require('os');7const jsyaml = require('js-yaml');8const memFs = require('mem-fs');9const editor = require('mem-fs-editor');10const BaseGenerator = require('../generators/app/index').prototype;11const utilYaml = require('../generators/app/utilYaml');12BaseGenerator.log = (msg) => {13 console.log(msg);// eslint-disable-line no-console14};15chai.use(dirtyChai);16const expect = chai.expect;17const store = memFs.create();18const fs = editor.create(store);19BaseGenerator.fs = fs;20process.on('unhandledRejection', (error) => {21 // Will print "unhandledRejection err is not defined"22 console.log('unhandledRejection', error.stack);// eslint-disable-line no-console23});24function copyYamlTemp(filesrc, nameFileDest) {25 // const filesrc = path.join(__dirname, filesrc);26 const tmpdir = fse.mkdtempSync(path.join(os.tmpdir(), 'jhipster-'));27 const file = path.join(tmpdir, nameFileDest);28 // BaseGenerator.fs.createReadStream(path.join(__dirname, filesrc)).pipe(BaseGenerator.fs.createWriteStream(file));29 fse.copySync(path.join(__dirname, filesrc), file);30 // fse.readFileSync(file);31 return file;32}33function deleteDirTemp(file) {34 fse.unlinkSync(file);35 fse.rmdirSync(path.dirname(file));36}37describe('JHipster generator spring-cloud-stream', () => {38 describe('Test array property', () => {39 describe('Get array property', () => {40 it('get property on array null', () => {41 const result = utilYaml.getPropertyInArray(null, 'test', BaseGenerator);42 expect(result).to.be.undefined();43 });44 it('get property on array empty', () => {45 const result = utilYaml.getPropertyInArray({ }, 'test', BaseGenerator);46 expect(result).to.be.undefined();47 });48 it('get a simple property that does not exist in a non-empty array', () => {49 const array = ['spring', 'application'];50 const result = utilYaml.getPropertyInArray(array, 'test', BaseGenerator);51 expect(result).to.be.undefined();52 });53 it('get a property that does not exist in a non-empty array', () => {54 const yaml = { spring: { cloud: 'stream' }, application: null };55 const result = utilYaml.getPropertyInArray(yaml, 'spring.cloud.toto', BaseGenerator);56 expect(result).to.be.undefined();57 });58 it('get a simple property that exist in a non-empty array', () => {59 const yaml = { spring: { cloud: 'stream' }, application: null };60 const result = utilYaml.getPropertyInArray(yaml, 'spring', BaseGenerator);61 expect(result).eql({ cloud: 'stream' });62 });63 it('get a property that exist in a non-empty array', () => {64 const yaml = { spring: { cloud: 'stream' }, application: null };65 const result = utilYaml.getPropertyInArray(yaml, 'spring.cloud', BaseGenerator);66 expect(result).eql('stream');67 });68 it('get a property that exist in a non-empty array', () => {69 const yaml = { spring: { cloud: 'stream' }, application: null };70 const result = utilYaml.getPropertyInArray(yaml, 'spring.cloud', BaseGenerator);71 expect(result).eql('stream');72 });73 });74 describe('add/Update array property', () => {75 it('update property on array null', () => {76 const result = utilYaml.updatePropertyInArray(null, 'spring.cloud', BaseGenerator, 'value');77 expect(result).to.be.undefined();78 });79 it('update property on array empty', () => {80 const result = utilYaml.updatePropertyInArray({ }, 'spring.cloud', BaseGenerator, 'value');81 expect(result).to.be.undefined();82 });83 it('add a simple property that does not exist in a non-empty array', () => {84 const array = ['spring', 'application'];85 utilYaml.updatePropertyInArray(array, 'toto', BaseGenerator, 'value');86 const result = utilYaml.getPropertyInArray(array, 'toto', BaseGenerator);87 expect(result).eql('value');88 });89 it('update a simple property that exist in a non-empty array', () => {90 const yaml = { spring: { cloud: 'stream' }, application: null };91 utilYaml.updatePropertyInArray(yaml, 'spring', BaseGenerator, 'value');92 const result = utilYaml.getPropertyInArray(yaml, 'spring', BaseGenerator);93 expect(result).eql('value');94 });95 it('update a property that exist in a non-empty array', () => {96 const yaml = { spring: { cloud: 'stream' }, application: null };97 utilYaml.updatePropertyInArray(yaml, 'spring.cloud', BaseGenerator, 'value');98 const result = utilYaml.getPropertyInArray(yaml, 'spring.cloud', BaseGenerator);99 expect(result).eql('value');100 });101 });102 describe('Delete array property', () => {103 it('Delete property on array null', () => {104 const result = utilYaml.deletePropertyInArray(null, 'spring.cloud', BaseGenerator, 'value');105 expect(result).to.be.undefined();106 });107 it('Delete property on array empty', () => {108 const result = utilYaml.deletePropertyInArray({ }, 'spring.cloud', BaseGenerator, 'value');109 expect(result).to.be.undefined();110 });111 it('Delete a simple property that does not exist in a non-empty array', () => {112 const yaml = { spring: { cloud: 'stream' }, application: null };113 utilYaml.deletePropertyInArray(yaml, 'toto', BaseGenerator);114 const length = Object.keys(yaml).length;115 expect(length).eql(2);116 });117 it('Delete a simple property that exist in a non-empty array', () => {118 const yaml = {119 spring: {120 cloud: 'stream',121 profiles: 'dev'122 },123 application: null124 };125 utilYaml.deletePropertyInArray(yaml, 'application', BaseGenerator);126 expect(Object.keys(yaml).length).eql(1);127 expect(Object.keys(yaml.spring).length).eql(2);128 });129 it('Delete a property that exist in a non-empty array', () => {130 const yaml = {131 spring: {132 cloud: 'stream',133 profiles: 'dev'134 },135 application: null136 };137 utilYaml.deletePropertyInArray(yaml, 'spring.cloud', BaseGenerator);138 const length = Object.keys(yaml.spring).length;139 expect(length).eql(1);140 });141 });142 });143 describe('Test yaml property', () => {144 describe('Get YAML property', () => {145 it('get property that doesnt exist', () => {146 const file = path.join(__dirname, '../test/templates/utils/application-dev.yml');147 const result = utilYaml.getYamlProperty(file, 'toto', BaseGenerator);148 expect(result).to.be.undefined();149 });150 it('get property on file empty', () => {151 const file = path.join(__dirname, '../test/templates/utils/yaml-empty.yml');152 const result = utilYaml.getYamlProperty(file, 'toto', BaseGenerator);153 expect(result).to.be.undefined();154 });155 it('get property on file that doesn\'t exist', () => {156 const file = path.join(__dirname, '../test/templates/utils/application-totos.yml');157 expect(() => utilYaml.getYamlProperty(file, 'spring', BaseGenerator)).to.throw(/doesn't exist/);158 });159 it('get simple property that exist', () => {160 const file = path.join(__dirname, '../test/templates/utils/application-dev.yml');161 const result = utilYaml.getYamlProperty(file, 'liquibase', BaseGenerator);162 expect(result).eql({ contexts: 'dev' });163 });164 it('get property that exist', () => {165 const file = path.join(__dirname, '../test/templates/utils/application-dev.yml');166 const result = utilYaml.getYamlProperty(file, 'liquibase.contexts', BaseGenerator);167 expect(result).eql('dev');168 });169 });170 describe('Add YAML properties', () => {171 it('add properties at beginin of file', () => {172 const file = copyYamlTemp('../test/templates/utils/application-dev.yml', 'application-dev.yml');173 const yaml = { toto: { cloud: 'stream' } };174 utilYaml.addYamlPropertiesAtBeginin(file, yaml, BaseGenerator);175 const result = utilYaml.getYamlProperty(file, 'toto.cloud', BaseGenerator);176 expect(result).eql('stream');177 const body = BaseGenerator.fs.read(file);178 const lines = body.split('\n');179 expect(lines[0].indexOf('toto:')).eql(0);180 deleteDirTemp(file);181 });182 it('add v at end of file', () => {183 const file = copyYamlTemp('../test/templates/utils/application-dev.yml', 'application-dev.yml');184 const yaml = { toto: { cloud: 'stream' } };185 utilYaml.addYamlPropertiesAtEnd(file, yaml, BaseGenerator);186 const result = utilYaml.getYamlProperty(file, 'toto.cloud', BaseGenerator);187 expect(result).eql('stream');188 const lines = BaseGenerator.fs.read(file).split('\n');189 expect(lines[lines.length - 3].indexOf('toto:')).eql(0);190 expect(lines[lines.length - 2].indexOf('cloud:')).not.eql(-1);191 expect(lines[lines.length - 2].indexOf('stream')).not.eql(-1);192 deleteDirTemp(file);193 });194 it('add yaml properties before another property and his comment', () => {195 const file = copyYamlTemp('../test/templates/utils/application-dev.yml', 'application-dev.yml');196 const yaml = { toto: { cloud: 'stream' } };197 utilYaml.addYamlPropertiesBeforeAnotherProperty(file, yaml, BaseGenerator, 'jhipster', true);198 const result = utilYaml.getYamlProperty(file, 'toto.cloud', BaseGenerator);199 expect(result).eql('stream');200 const lines = BaseGenerator.fs.read(file).split('\n');201 expect(lines[77].indexOf('toto:')).eql(0);202 expect(lines[78].indexOf('cloud:')).not.eql(-1);203 expect(lines[78].indexOf('stream')).not.eql(-1);204 deleteDirTemp(file);205 });206 it('add yaml properties before another property without his comment', () => {207 const file = copyYamlTemp('../test/templates/utils/application-dev.yml', 'application-dev.yml');208 const yaml = { toto: { cloud: 'stream' } };209 utilYaml.addYamlPropertiesBeforeAnotherProperty(file, yaml, BaseGenerator, 'jhipster', false);210 const result = utilYaml.getYamlProperty(file, 'toto.cloud', BaseGenerator);211 expect(result).eql('stream');212 const lines = BaseGenerator.fs.read(file).split('\n');213 expect(lines[83].indexOf('toto:')).eql(0);214 expect(lines[84].indexOf('cloud:')).not.eql(-1);215 expect(lines[84].indexOf('stream')).not.eql(-1);216 deleteDirTemp(file);217 });218 it('add yaml properties before another property that don\'t exist', () => {219 const file = copyYamlTemp('../test/templates/utils/application-dev.yml', 'application-dev.yml');220 const yaml = { toto: { cloud: 'stream' } };221 expect(() => utilYaml.addYamlPropertiesBeforeAnotherProperty(file, yaml, BaseGenerator, 'titi')).to.throw(/not found/);222 deleteDirTemp(file);223 });224 it('add yaml properties after another simple property', () => {225 const file = copyYamlTemp('../test/templates/utils/application-dev.yml', 'application-dev.yml');226 const yaml = { toto: { cloud: 'stream' } };227 utilYaml.addYamlPropertiesAfterAnotherProperty(file, yaml, BaseGenerator, 'jhipster');228 const result = utilYaml.getYamlProperty(file, 'toto.cloud', BaseGenerator);229 expect(result).eql('stream');230 const lines = BaseGenerator.fs.read(file).split('\n');231 expect(lines[127].indexOf('toto:')).eql(0);232 expect(lines[128].indexOf('cloud:')).not.eql(-1);233 expect(lines[128].indexOf('stream')).not.eql(-1);234 deleteDirTemp(file);235 });236 it('add yaml properties after another property', () => {237 const file = copyYamlTemp('../test/templates/utils/application-dev.yml', 'application-dev.yml');238 const yaml = { toto: { cloud: 'stream' } };239 utilYaml.addYamlPropertiesAfterAnotherProperty(file, yaml, BaseGenerator, 'jhipster.logging.logstash');240 const result = utilYaml.getYamlProperty(file, 'toto.cloud', BaseGenerator);241 expect(result).eql('stream');242 const lines = BaseGenerator.fs.read(file).split('\n');243 expect(lines[127].indexOf('toto:')).eql(0);244 expect(lines[128].indexOf('cloud:')).not.eql(-1);245 expect(lines[128].indexOf('stream')).not.eql(-1);246 deleteDirTemp(file);247 });248 it('add yaml properties after another property that don\'t exist', () => {249 const file = copyYamlTemp('../test/templates/utils/application-dev.yml', 'application-dev.yml');250 const yaml = { toto: { cloud: 'stream' } };251 expect(() => utilYaml.addYamlPropertiesAfterAnotherProperty(file, yaml, BaseGenerator, 'titi')).to.throw(/not found/);252 deleteDirTemp(file);253 });254 it('add yaml properties at specific index line with no space', () => {255 const file = copyYamlTemp('../test/templates/utils/application-dev.yml', 'application-dev.yml');256 const yaml = { toto: { cloud: 'stream' } };257 utilYaml.addYamlPropertiesAtLineIndex(file, yaml, BaseGenerator, 10, 0);258 const result = utilYaml.getYamlProperty(file, 'toto.cloud', BaseGenerator);259 expect(result).eql('stream');260 const lines = BaseGenerator.fs.read(file).split('\n');261 expect(lines[10].indexOf('toto:')).eql(0);262 expect(lines[11].indexOf('cloud:')).not.eql(-1);263 expect(lines[11].indexOf('stream')).not.eql(-1);264 deleteDirTemp(file);265 });266 it('add yaml properties at specific index line with space', () => {267 const file = copyYamlTemp('../test/templates/utils/application-dev.yml', 'application-dev.yml');268 const yaml = { cloud: 'stream' };269 utilYaml.addYamlPropertiesAtLineIndex(file, yaml, BaseGenerator, 16, 4);270 const result = utilYaml.getYamlProperty(file, 'spring.cloud', BaseGenerator);271 expect(result).eql('stream');272 const lines = BaseGenerator.fs.read(file).split('\n');273 expect(lines[16].indexOf('cloud:')).eql(4);274 expect(lines[16].indexOf('stream')).not.eql(-1);275 deleteDirTemp(file);276 });277 });278 describe('Add YAML property', () => {279 it('add property at beginin of file', () => {280 const file = copyYamlTemp('../test/templates/utils/application-dev.yml', 'application-dev.yml');281 const property = 'toto.cloud';282 utilYaml.addYamlPropertyAtBeginin(file, property, 'stream', BaseGenerator);283 const result = utilYaml.getYamlProperty(file, 'toto.cloud', BaseGenerator);284 expect(result).eql('stream');285 const body = BaseGenerator.fs.read(file);286 const lines = body.split('\n');287 expect(lines[0].indexOf('toto:')).eql(0);288 deleteDirTemp(file);289 });290 it('add property at end of file', () => {291 const file = copyYamlTemp('../test/templates/utils/application-dev.yml', 'application-dev.yml');292 const property = 'toto.cloud';293 utilYaml.addYamlPropertyAtEnd(file, property, 'stream', BaseGenerator);294 const result = utilYaml.getYamlProperty(file, 'toto.cloud', BaseGenerator);295 expect(result).eql('stream');296 const lines = BaseGenerator.fs.read(file).split('\n');297 expect(lines[lines.length - 3].indexOf('toto:')).eql(0);298 expect(lines[lines.length - 2].indexOf('cloud:')).not.eql(-1);299 expect(lines[lines.length - 2].indexOf('stream')).not.eql(-1);300 deleteDirTemp(file);301 });302 it('add yaml property before another property and his comment', () => {303 const file = copyYamlTemp('../test/templates/utils/application-dev.yml', 'application-dev.yml');304 const property = 'toto.cloud';305 utilYaml.addYamlPropertyBeforeAnotherProperty(file, property, 'stream', BaseGenerator, 'jhipster', true);306 const result = utilYaml.getYamlProperty(file, 'toto.cloud', BaseGenerator);307 expect(result).eql('stream');308 const lines = BaseGenerator.fs.read(file).split('\n');309 expect(lines[77].indexOf('toto:')).eql(0);310 expect(lines[78].indexOf('cloud:')).not.eql(-1);311 expect(lines[78].indexOf('stream')).not.eql(-1);312 deleteDirTemp(file);313 });314 it('add yaml property before another property without his comment', () => {315 const file = copyYamlTemp('../test/templates/utils/application-dev.yml', 'application-dev.yml');316 const property = 'toto.cloud';317 utilYaml.addYamlPropertyBeforeAnotherProperty(file, property, 'stream', BaseGenerator, 'jhipster', false);318 const result = utilYaml.getYamlProperty(file, 'toto.cloud', BaseGenerator);319 expect(result).eql('stream');320 const lines = BaseGenerator.fs.read(file).split('\n');321 expect(lines[83].indexOf('toto:')).eql(0);322 expect(lines[84].indexOf('cloud:')).not.eql(-1);323 expect(lines[84].indexOf('stream')).not.eql(-1);324 deleteDirTemp(file);325 });326 it('add yaml property before another property that don\'t exist', () => {327 const file = copyYamlTemp('../test/templates/utils/application-dev.yml', 'application-dev.yml');328 const property = 'toto.cloud';329 expect(() => utilYaml.addYamlPropertyBeforeAnotherProperty(file, property, 'stream', BaseGenerator, 'titi')).to.throw(/not found/);330 deleteDirTemp(file);331 });332 it('add yaml property after another simple property', () => {333 const file = copyYamlTemp('../test/templates/utils/application-dev.yml', 'application-dev.yml');334 const property = 'toto.cloud';335 utilYaml.addYamlPropertyAfterAnotherProperty(file, property, 'stream', BaseGenerator, 'jhipster');336 const result = utilYaml.getYamlProperty(file, 'toto.cloud', BaseGenerator);337 expect(result).eql('stream');338 const lines = BaseGenerator.fs.read(file).split('\n');339 expect(lines[127].indexOf('toto:')).eql(0);340 expect(lines[128].indexOf('cloud:')).not.eql(-1);341 expect(lines[128].indexOf('stream')).not.eql(-1);342 deleteDirTemp(file);343 });344 it('add yaml property after another property', () => {345 const file = copyYamlTemp('../test/templates/utils/application-dev.yml', 'application-dev.yml');346 const property = 'toto.cloud';347 utilYaml.addYamlPropertyAfterAnotherProperty(file, property, 'stream', BaseGenerator, 'jhipster.logging.logstash');348 const result = utilYaml.getYamlProperty(file, 'toto.cloud', BaseGenerator);349 expect(result).eql('stream');350 const lines = BaseGenerator.fs.read(file).split('\n');351 expect(lines[127].indexOf('toto:')).eql(0);352 expect(lines[128].indexOf('cloud:')).not.eql(-1);353 expect(lines[128].indexOf('stream')).not.eql(-1);354 deleteDirTemp(file);355 });356 it('add yaml property after another property that don\'t exist', () => {357 const file = copyYamlTemp('../test/templates/utils/application-dev.yml', 'application-dev.yml');358 const property = 'toto.cloud';359 expect(() => utilYaml.addYamlPropertyAfterAnotherProperty(file, property, 'stream', BaseGenerator, 'titi')).to.throw(/not found/);360 deleteDirTemp(file);361 });362 it('add yaml property at specific index line with no space', () => {363 const file = copyYamlTemp('../test/templates/utils/application-dev.yml', 'application-dev.yml');364 const property = 'toto.cloud';365 utilYaml.addYamlPropertyAtLineIndex(file, property, 'stream', BaseGenerator, 10, 0);366 const result = utilYaml.getYamlProperty(file, 'toto.cloud', BaseGenerator);367 expect(result).eql('stream');368 const lines = BaseGenerator.fs.read(file).split('\n');369 expect(lines[10].indexOf('toto:')).eql(0);370 expect(lines[11].indexOf('cloud:')).not.eql(-1);371 expect(lines[11].indexOf('stream')).not.eql(-1);372 deleteDirTemp(file);373 });374 it('add yaml property at specific index line with space', () => {375 const file = copyYamlTemp('../test/templates/utils/application-dev.yml', 'application-dev.yml');376 const property = 'cloud';377 utilYaml.addYamlPropertyAtLineIndex(file, property, 'stream', BaseGenerator, 16, 4);378 const result = utilYaml.getYamlProperty(file, 'spring.cloud', BaseGenerator);379 expect(result).eql('stream');380 const lines = BaseGenerator.fs.read(file).split('\n');381 expect(lines[16].indexOf('cloud:')).eql(4);382 expect(lines[16].indexOf('stream')).not.eql(-1);383 deleteDirTemp(file);384 });385 });386 describe('Add YAML property, updateYamlProperty (Intelligent method of adding a property in yaml)', () => {387 it('add a property that don\'t exist in the file', () => {388 const file = copyYamlTemp('../test/templates/utils/application-dev.yml', 'application-dev.yml');389 const property = 'toto.cloud';390 utilYaml.updateYamlProperty(file, property, 'stream', BaseGenerator);391 const result = utilYaml.getYamlProperty(file, 'toto.cloud', BaseGenerator);392 expect(result).eql('stream');393 const lines = BaseGenerator.fs.read(file).split('\n');394 expect(lines[140].indexOf('toto:')).eql(0);395 expect(lines[141].indexOf('stream')).not.eql(-1);396 deleteDirTemp(file);397 });398 it('add a property that exist partially in the file. one levels', () => {399 const file = copyYamlTemp('../test/templates/utils/application-dev.yml', 'application-dev.yml');400 const property = 'spring.cloud';401 utilYaml.updateYamlProperty(file, property, 'stream', BaseGenerator);402 const result = utilYaml.getYamlProperty(file, 'spring.cloud', BaseGenerator);403 expect(result).eql('stream');404 const lines = BaseGenerator.fs.read(file).split('\n');405 expect(lines[15].indexOf('spring:')).eql(0);406 expect(lines[53].indexOf('cloud:')).not.eql(-1);407 expect(lines[53].indexOf('stream')).not.eql(-1);408 deleteDirTemp(file);409 });410 it('add a property that exist partially in the file two levels', () => {411 const file = copyYamlTemp('../test/templates/utils/application-dev.yml', 'application-dev.yml');412 const property = 'spring.profiles.test';413 utilYaml.updateYamlProperty(file, property, 'stream', BaseGenerator);414 const result = utilYaml.getYamlProperty(file, 'spring.profiles.test', BaseGenerator);415 expect(result).eql('stream');416 const lines = BaseGenerator.fs.read(file).split('\n');417 expect(lines[15].indexOf('spring:'), 'spring').eql(0);418 expect(lines[16].indexOf('profiles:'), 'profiles').not.eql(-1);419 expect(lines[19].indexOf('test:'), 'test').not.eql(-1);420 expect(lines[19].indexOf('stream'), 'stream').not.eql(-1);421 deleteDirTemp(file);422 });423 it('add a property that exist partially in the file tree levels', () => {424 const file = copyYamlTemp('../test/templates/utils/application-dev.yml', 'application-dev.yml');425 const property = 'jhipster.security.authentication.test';426 utilYaml.updateYamlProperty(file, property, 'stream', BaseGenerator);427 const result = utilYaml.getYamlProperty(file, 'jhipster.security.authentication.test', BaseGenerator);428 expect(result).eql('stream');429 const lines = BaseGenerator.fs.read(file).split('\n');430 expect(lines[83].indexOf('jhipster:'), 'jhipster').eql(0);431 expect(lines[98].indexOf('security:'), 'security').not.eql(-1);432 expect(lines[99].indexOf('authentication:'), 'authentication').not.eql(-1);433 expect(lines[105].indexOf('test:'), 'test').not.eql(-1);434 expect(lines[105].indexOf('stream'), 'stream').not.eql(-1);435 deleteDirTemp(file);436 });437 it('add yaml property before complex property that is on one line or more (ex hibernate.id.new_generator_mappings)', () => {438 const file = copyYamlTemp('../test/templates/utils/application-dev.yml', 'application-dev.yml');439 utilYaml.updateYamlProperty(file, 'spring.jpa.properties.hibernate.id.toto', 'stream', BaseGenerator);440 const result = utilYaml.getYamlProperty(file, 'spring.jpa.properties.hibernate.id.toto', BaseGenerator);441 expect(result).eql('stream');442 const lines = BaseGenerator.fs.read(file).split('\n');443 expect(lines[44].indexOf('hibernate:')).eql(12);444 expect(lines[45].indexOf('id:')).eql(16);445 expect(lines[46].indexOf('toto:')).eql(20);446 expect(lines[46].indexOf('stream')).not.eql(-1);447 deleteDirTemp(file);448 });449 });450 describe('Add YAML properties, updateYamlProperties (Intelligent method of adding properties in yaml)', () => {451 it('add properties that don\'t exist in the file', () => {452 const file = copyYamlTemp('../test/templates/utils/application-dev.yml', 'application-dev.yml');453 const yaml = { toto: { cloud: 'stream' } };454 utilYaml.updateYamlProperties(file, yaml, BaseGenerator);455 const result = utilYaml.getYamlProperty(file, 'toto.cloud', BaseGenerator);456 expect(result).eql('stream');457 const lines = BaseGenerator.fs.read(file).split('\n');458 expect(lines[140].indexOf('toto:')).eql(0);459 expect(lines[141].indexOf('stream')).not.eql(-1);460 deleteDirTemp(file);461 });462 it('add properties that exist partially in the file. one levels', () => {463 const file = copyYamlTemp('../test/templates/utils/application-dev.yml', 'application-dev.yml');464 const yaml = { spring: { cloud: 'stream' } };465 utilYaml.updateYamlProperties(file, yaml, BaseGenerator);466 const result = utilYaml.getYamlProperty(file, 'spring.cloud', BaseGenerator);467 expect(result).eql('stream');468 const lines = BaseGenerator.fs.read(file).split('\n');469 expect(lines[15].indexOf('spring:')).eql(0);470 expect(lines[53].indexOf('cloud:')).not.eql(-1);471 expect(lines[53].indexOf('stream')).not.eql(-1);472 deleteDirTemp(file);473 });474 it('add properties that exist partially in the file two levels', () => {475 const file = copyYamlTemp('../test/templates/utils/application-dev.yml', 'application-dev.yml');476 const yaml = { spring: { profiles: { test: 'stream' } } };477 utilYaml.updateYamlProperties(file, yaml, BaseGenerator);478 const result = utilYaml.getYamlProperty(file, 'spring.profiles.test', BaseGenerator);479 expect(result).eql('stream');480 const lines = BaseGenerator.fs.read(file).split('\n');481 expect(lines[15].indexOf('spring:'), 'spring').eql(0);482 expect(lines[16].indexOf('profiles:'), 'profiles').not.eql(-1);483 expect(lines[19].indexOf('test:'), 'test').not.eql(-1);484 expect(lines[19].indexOf('stream'), 'stream').not.eql(-1);485 deleteDirTemp(file);486 });487 it('add properties that exist partially in the file tree levels', () => {488 const file = copyYamlTemp('../test/templates/utils/application-dev.yml', 'application-dev.yml');489 const yaml = { jhipster: { security: { authentication: { test: 'stream' } } } };490 utilYaml.updateYamlProperties(file, yaml, BaseGenerator);491 const result = utilYaml.getYamlProperty(file, 'jhipster.security.authentication.test', BaseGenerator);492 expect(result).eql('stream');493 const lines = BaseGenerator.fs.read(file).split('\n');494 expect(lines[83].indexOf('jhipster:'), 'jhipster').eql(0);495 expect(lines[98].indexOf('security:'), 'security').not.eql(-1);496 expect(lines[99].indexOf('authentication:'), 'authentication').not.eql(-1);497 expect(lines[105].indexOf('test:'), 'test').not.eql(-1);498 expect(lines[105].indexOf('stream'), 'stream').not.eql(-1);499 deleteDirTemp(file);500 });501 it('add properties that exist partially in the file x levels', () => {502 const file = copyYamlTemp('../test/templates/utils/application-dev.yml', 'application-dev.yml');503 const yamlAppDevProperties = { };504 utilYaml.updatePropertyInArray(yamlAppDevProperties, 'spring.cloud.stream.default.contentType', BaseGenerator, 'application/json');505 utilYaml.updatePropertyInArray(yamlAppDevProperties, 'spring.cloud.stream.bindings.input.destination', BaseGenerator, 'topic-jhipster');506 utilYaml.updatePropertyInArray(yamlAppDevProperties, 'spring.cloud.stream.bindings.output.destination', BaseGenerator, 'topic-jhipster');507 utilYaml.updatePropertyInArray(yamlAppDevProperties, 'spring.cloud.stream.bindings.rabbit.bindings.output.producer.routingKeyExpression', BaseGenerator, 'headers.title');508 utilYaml.updateYamlProperties(file, yamlAppDevProperties, BaseGenerator);509 const result = utilYaml.getYamlProperty(file, 'spring.cloud.stream.bindings.output.destination', BaseGenerator);510 expect(result).eql('topic-jhipster');511 deleteDirTemp(file);512 });513 it('add properties that exist, don\'t duplicate key update the file', () => {514 const file = copyYamlTemp('../test/templates/utils/application-dev.yml', 'application-dev.yml');515 const yamlAppDevProperties = { };516 utilYaml.updatePropertyInArray(yamlAppDevProperties, 'spring.jpa.database-platform', BaseGenerator, 'Test');517 utilYaml.updateYamlProperties(file, yamlAppDevProperties, BaseGenerator);518 expect(() => utilYaml.getYamlProperty(file, 'spring.jpa.database-platform', BaseGenerator)).not.to.throw(/no such file or directory/);519 deleteDirTemp(file);520 });521 it('add properties before complex property that is on one line or more (ex hibernate.id.new_generator_mappings)', () => {522 const file = copyYamlTemp('../test/templates/utils/application-dev.yml', 'application-dev.yml');523 const yamlAppDevProperties = { };524 utilYaml.updatePropertyInArray(yamlAppDevProperties, 'spring.jpa.properties.hibernate.id.toto', BaseGenerator, 'stream');525 utilYaml.updateYamlProperties(file, yamlAppDevProperties, BaseGenerator);526 const result = utilYaml.getYamlProperty(file, 'spring.jpa.properties.hibernate.id.toto', BaseGenerator);527 expect(result).eql('stream');528 const lines = BaseGenerator.fs.read(file).split('\n');529 expect(lines[44].indexOf('hibernate:')).eql(12);530 expect(lines[45].indexOf('id:')).eql(16);531 expect(lines[46].indexOf('toto:')).eql(20);532 expect(lines[46].indexOf('stream')).not.eql(-1);533 deleteDirTemp(file);534 });535 });536 describe.skip('update YAML properties', () => {537 it('update YAML properties ', () => {538 });539 });540 describe.skip('Delete YAML properties', () => {541 it('delete YAML properties ', () => {542 });543 });544 describe('functions', () => {545 it('getPathAndValueOfAllProperty ', () => {546 const file = copyYamlTemp('../test/templates/utils/application-dev.yml', 'application-dev.yml');547 const object = jsyaml.safeLoad(BaseGenerator.fs.read(file));548 const arrayRetur = [];549 utilYaml.getPathAndValueOfAllProperty(object, '', arrayRetur, BaseGenerator);550 // BaseGenerator.log(arrayRetur);551 expect(arrayRetur.length).eql(54);552 deleteDirTemp(file);553 });554 it('getLastPropertyCommonHierarchy ', () => {555 const file = copyYamlTemp('../test/templates/utils/application-dev.yml', 'application-dev.yml');556 const property = 'spring';557 const propExist = utilYaml.getLastPropertyCommonHierarchy(file, property, BaseGenerator);558 expect(propExist).eql('spring');559 deleteDirTemp(file);560 });561 it('getLastPropertyCommonHierarchy ', () => {562 const file = copyYamlTemp('../test/templates/utils/application-dev.yml', 'application-dev.yml');563 const property = 'spring.profiles';564 const propExist = utilYaml.getLastPropertyCommonHierarchy(file, property, BaseGenerator);565 expect(propExist).eql('spring.profiles');566 deleteDirTemp(file);567 });568 it('getLastPropertyCommonHierarchy ', () => {569 const file = copyYamlTemp('../test/templates/utils/application-dev.yml', 'application-dev.yml');570 const property = 'spring.profiles.test';571 const propExist = utilYaml.getLastPropertyCommonHierarchy(file, property, BaseGenerator);572 expect(propExist).eql('spring.profiles');573 deleteDirTemp(file);574 });575 it('getLastPropertyCommonHierarchy ', () => {576 const file = copyYamlTemp('../test/templates/utils/application-dev.yml', 'application-dev.yml');577 const property = 'spring.profiles.active';578 const propExist = utilYaml.getLastPropertyCommonHierarchy(file, property, BaseGenerator);579 expect(propExist).eql('spring.profiles.active');580 deleteDirTemp(file);581 });582 it('getLastPropertyCommonHierarchy ', () => {583 const file = copyYamlTemp('../test/templates/utils/application-dev.yml', 'application-dev.yml');584 const property = 'toto';585 const propExist = utilYaml.getLastPropertyCommonHierarchy(file, property, BaseGenerator);586 expect(propExist).to.be.undefined();587 deleteDirTemp(file);588 });589 });590 });...
generator-base.spec.js
Source:generator-base.spec.js
1const expect = require('chai').expect;2const jhiCore = require('jhipster-core');3const expectedFiles = require('./utils/expected-files');4const BaseGenerator = require('../generators/generator-base').prototype;5BaseGenerator.log = msg => {6 // eslint-disable-next-line no-console7 console.log(msg);8};9describe('Generator Base', () => {10 describe('getAllSupportedLanguages', () => {11 describe('when called', () => {12 it('returns an array', () => {13 expect(BaseGenerator.getAllSupportedLanguages()).to.not.have.length(0);14 });15 });16 });17 describe('isSupportedLanguage', () => {18 describe('when called with valid language', () => {19 it('returns true', () => {20 expect(BaseGenerator.isSupportedLanguage('en')).to.equal(true);21 });22 });23 describe('when called with invalid language', () => {24 it('returns false', () => {25 expect(BaseGenerator.isSupportedLanguage('ab')).to.equal(false);26 });27 });28 });29 describe('getAllSupportedLanguageOptions', () => {30 describe('when called', () => {31 it('returns an array', () => {32 expect(BaseGenerator.getAllSupportedLanguages()).to.not.have.length(0);33 });34 });35 });36 describe('getExistingEntities', () => {37 describe('when entities change on-disk', () => {38 before(() => {39 const entities = {40 Region: {41 fluentMethods: true,42 relationships: [],43 fields: [44 {45 fieldName: 'regionName',46 fieldType: 'String'47 }48 ],49 changelogDate: '20170623093902',50 entityTableName: 'region',51 dto: 'mapstruct',52 pagination: 'no',53 service: 'serviceImpl',54 angularJSSuffix: 'mySuffix'55 }56 };57 jhiCore.exportEntities({58 entities,59 forceNoFiltering: true,60 application: {}61 });62 BaseGenerator.getExistingEntities();63 entities.Region.fields.push({ fieldName: 'regionDesc', fieldType: 'String' });64 jhiCore.exportEntities({65 entities,66 forceNoFiltering: true,67 application: {}68 });69 });70 it('returns an up-to-date state', () => {71 expect(BaseGenerator.getExistingEntities().find(it => it.name === 'Region').definition.fields[1]).to.eql({72 fieldName: 'regionDesc',73 fieldType: 'String'74 });75 });76 });77 });78 describe('getTableName', () => {79 describe('when called with a value', () => {80 it('returns a table name', () => {81 expect(BaseGenerator.getTableName('tableName')).to.equal('table_name');82 });83 });84 });85 describe('getColumnName', () => {86 describe('when called with a value', () => {87 it('returns a column name', () => {88 expect(BaseGenerator.getColumnName('colName')).to.equal('col_name');89 expect(BaseGenerator.getColumnName('colNName')).to.equal('colnname');90 });91 });92 });93 describe('getPluralColumnName', () => {94 describe('when called with a value', () => {95 it('returns a plural column name', () => {96 expect(BaseGenerator.getPluralColumnName('colName')).to.equal('col_names');97 });98 });99 });100 describe('getJoinTableName', () => {101 describe('when called with a value', () => {102 it('returns a join table name', () => {103 expect(BaseGenerator.getJoinTableName('entityName', 'relationshipName', 'mysql')).to.equal('entity_name_relationship_name');104 });105 });106 describe('when called with a long name', () => {107 it('returns a proper join table name', () => {108 expect(BaseGenerator.getJoinTableName('entityNameLonger', 'relationshipName', 'oracle')).to.have.length(30);109 expect(BaseGenerator.getJoinTableName('entityNameLonger', 'relationshipName', 'oracle')).to.equal(110 'entity_name_lon_relationship_n'111 );112 });113 });114 });115 describe('getFKConstraintName', () => {116 describe('when called with a value', () => {117 it('returns a constraint name', () => {118 expect(BaseGenerator.getFKConstraintName('entityName', 'relationshipName', 'mysql')).to.equal(119 'fk_entity_name_relationship_name_id'120 );121 });122 });123 describe('when called with a long name and oracle', () => {124 it('returns a proper constraint name', () => {125 expect(BaseGenerator.getFKConstraintName('entityNameLongerName', 'relationshipLongerName', 'oracle')).to.have.length(30);126 expect(BaseGenerator.getFKConstraintName('entityNameLongerName', 'relationshipLongerName', 'oracle')).to.equal(127 'entity_name_lo_relationship_id'128 );129 });130 });131 describe('when called with a long name and mysql', () => {132 it('returns a proper constraint name', () => {133 expect(134 BaseGenerator.getFKConstraintName(135 'entityLongerNameWithPaginationAndDTO',136 'relationshipLongerNameWithPaginationAndDTO',137 'mysql'138 )139 ).to.have.length(64);140 expect(141 BaseGenerator.getFKConstraintName(142 'entityLongerNameWithPaginationAndDTO',143 'relationshipLongerNameWithPaginationAndDTO',144 'mysql'145 )146 ).to.equal('entity_longer_name_with_paginat_relationship_longer_name_with_id');147 });148 });149 describe('when called with a long name that is near limit and mysql', () => {150 it('returns a proper constraint name', () => {151 expect(152 BaseGenerator.getFKConstraintName('testCustomTableName', 'userManyToManyUserManyToMany', 'mysql').length153 ).to.be.lessThan(64);154 expect(BaseGenerator.getFKConstraintName('testCustomTableName', 'userManyToManyUserManyToMany', 'mysql')).to.equal(155 'test_custom_table_name_user_many_to_many_user_many_to_many_id'156 );157 expect(158 BaseGenerator.getFKConstraintName('testCustomTableName', 'userManyToManyUserManyToManies', 'mysql').length159 ).to.be.lessThan(64);160 expect(BaseGenerator.getFKConstraintName('testCustomTableName', 'userManyToManyUserManyToManies', 'mysql')).to.equal(161 'test_custom_table_name_user_many_to_many_user_many_to_manies_id'162 );163 });164 });165 describe('when called with a long name that is equal to limit and mysql', () => {166 it('returns a proper constraint name', () => {167 expect(BaseGenerator.getFKConstraintName('testCustomTableNames', 'userManyToManyUserManyToManies', 'mysql')).to.have.length(168 64169 );170 expect(BaseGenerator.getFKConstraintName('testCustomTableNames', 'userManyToManyUserManyToManies', 'mysql')).to.equal(171 'test_custom_table_names_user_many_to_many_user_many_to_manies_id'172 );173 });174 });175 describe('when called with a long name and no snake case', () => {176 it('returns a proper constraint name', () => {177 expect(BaseGenerator.getFKConstraintName('entityNameLongerName', 'relationshipLongerName', 'oracle', true)).to.have.length(178 30179 );180 expect(BaseGenerator.getFKConstraintName('entityNameLongerName', 'relationshipLongerName', 'oracle', true)).to.equal(181 'entityNameLong_relationship_id'182 );183 });184 });185 });186 describe('getUXConstraintName', () => {187 describe('when called with a value', () => {188 it('returns a constraint name', () => {189 expect(BaseGenerator.getUXConstraintName('entityName', 'columnName', 'mysql')).to.equal('ux_entity_name_column_name');190 });191 });192 describe('when called with a value and no snake case', () => {193 it('returns a constraint name', () => {194 expect(BaseGenerator.getUXConstraintName('entityName', 'columnName', 'mysql', true)).to.equal('ux_entityName_columnName');195 });196 });197 describe('when called with a long name and oracle', () => {198 it('returns a proper constraint name', () => {199 expect(BaseGenerator.getUXConstraintName('entityNameLongerName', 'columnLongerName', 'oracle')).to.have.length(30);200 expect(BaseGenerator.getUXConstraintName('entityNameLongerName', 'columnLongerName', 'oracle')).to.equal(201 'ux_entity_name_lo_column_longe'202 );203 });204 });205 describe('when called with a long name and mysql', () => {206 it('returns a proper constraint name', () => {207 expect(208 BaseGenerator.getUXConstraintName(209 'entityLongerNameWithPaginationAndDTO',210 'columnLongerNameWithPaginationAndDTO',211 'mysql'212 )213 ).to.have.length(64);214 expect(215 BaseGenerator.getUXConstraintName(216 'entityLongerNameWithPaginationAndDTO',217 'columnLongerNameWithPaginationAndDTO',218 'mysql'219 )220 ).to.equal('ux_entity_longer_name_with_paginat_column_longer_name_with_pagin');221 });222 });223 describe('when called with a long name that is near limit and mysql', () => {224 it('returns a proper constraint name', () => {225 expect(226 BaseGenerator.getUXConstraintName('testCustomTableName', 'userManyToManyUserManyToManies', 'mysql').length227 ).to.be.lessThan(64);228 expect(BaseGenerator.getUXConstraintName('testCustomTableName', 'userManyToManyUserManyToManies', 'mysql')).to.equal(229 'ux_test_custom_table_name_user_many_to_many_user_many_to_manies'230 );231 });232 });233 describe('when called with a long name that is equal to limit and mysql', () => {234 it('returns a proper constraint name', () => {235 expect(BaseGenerator.getUXConstraintName('testCustomTableNames', 'userManyToManyUserManyToManies', 'mysql')).to.have.length(236 64237 );238 expect(BaseGenerator.getUXConstraintName('testCustomTableNames', 'userManyToManyUserManyToManies', 'mysql')).to.equal(239 'ux_test_custom_table_names_user_many_to_many_user_many_to_manies'240 );241 });242 });243 describe('when called with a long name and mysql and no snake case', () => {244 it('returns a proper constraint name', () => {245 expect(246 BaseGenerator.getUXConstraintName(247 'entityLongerNameWithPaginationAndDTO',248 'columnLongerNameWithPaginationAndDTO',249 'mysql',250 true251 )252 ).to.have.length(64);253 expect(254 BaseGenerator.getUXConstraintName(255 'entityLongerNameWithPaginationAndDTO',256 'columnLongerNameWithPaginationAndDTO',257 'mysql',258 true259 )260 ).to.equal('ux_entityLongerNameWithPaginationA_columnLongerNameWithPaginatio');261 });262 });263 });264 describe('printJHipsterLogo', () => {265 describe('when called', () => {266 it('prints the logo', () => {267 expect(BaseGenerator.printJHipsterLogo()).to.equal(undefined);268 });269 });270 });271 describe('checkForNewVersion', () => {272 describe('when called', () => {273 it('prints the new version info', () => {274 expect(BaseGenerator.checkForNewVersion()).to.equal(undefined);275 });276 });277 });278 describe('getAngularAppName', () => {279 describe('when called with name', () => {280 it('return the angular app name', () => {281 BaseGenerator.baseName = 'myTest';282 expect(BaseGenerator.getAngularAppName()).to.equal('myTestApp');283 });284 });285 describe('when called with name having App', () => {286 it('return the angular app name', () => {287 BaseGenerator.baseName = 'myApp';288 expect(BaseGenerator.getAngularAppName()).to.equal('myApp');289 });290 });291 });292 describe('getMainClassName', () => {293 describe('when called with name', () => {294 it('return the app name', () => {295 BaseGenerator.baseName = 'myTest';296 expect(BaseGenerator.getMainClassName()).to.equal('MyTestApp');297 });298 });299 describe('when called with name having App', () => {300 it('return the app name', () => {301 BaseGenerator.baseName = 'myApp';302 expect(BaseGenerator.getMainClassName()).to.equal('MyApp');303 });304 });305 describe('when called with name having invalid java chars', () => {306 it('return the default app name', () => {307 BaseGenerator.baseName = '9myApp';308 expect(BaseGenerator.getMainClassName()).to.equal('Application');309 });310 });311 });312 describe('writeFilesToDisk', () => {313 describe('when called with default angular client options', () => {314 it('should produce correct files', () => {315 const files = require('../generators/client/files-angular').files; // eslint-disable-line global-require316 const generator = {317 useSass: false,318 enableTranslation: true,319 serviceDiscoveryType: false,320 authenticationType: 'jwt',321 testFrameworks: []322 };323 let filesToAssert = expectedFiles.client;324 filesToAssert = filesToAssert.concat(expectedFiles.jwtClient);325 filesToAssert = filesToAssert.concat(expectedFiles.userManagement).sort();326 const out = BaseGenerator.writeFilesToDisk(files, generator, true).sort();327 expect(out).to.eql(filesToAssert);328 });329 });330 describe('when called with default angular client options skipping user-management', () => {331 it('should produce correct files', () => {332 const files = require('../generators/client/files-angular').files; // eslint-disable-line global-require333 const generator = {334 useSass: false,335 enableTranslation: true,336 serviceDiscoveryType: false,337 authenticationType: 'jwt',338 skipUserManagement: true,339 testFrameworks: []340 };341 let filesToAssert = expectedFiles.client;342 filesToAssert = filesToAssert.concat(expectedFiles.jwtClient);343 filesToAssert = filesToAssert.sort();344 const out = BaseGenerator.writeFilesToDisk(files, generator, true).sort();345 expect(out).to.eql(filesToAssert);346 });347 });348 });...
generator-base-private.spec.js
Source:generator-base-private.spec.js
1const expect = require('chai').expect;2// using base generator which extends the private base3const BaseGenerator = require('../generators/generator-base').prototype;4BaseGenerator.log = msg => {5 // eslint-disable-next-line no-console6 console.log(msg);7};8describe('Generator Base Private', () => {9 describe('stripMargin', () => {10 it('should produce correct output without margin', () => {11 const entityFolderName = 'entityFolderName';12 const entityFileName = 'entityFileName';13 const content = `|export * from './${entityFolderName}/${entityFileName}-update.component';14 |export * from './${entityFolderName}/${entityFileName}-delete-dialog.component';15 |export * from './${entityFolderName}/${entityFileName}-detail.component';16 |export * from './${entityFolderName}/${entityFileName}.component';17 |export * from './${entityFolderName}/${entityFileName}.state';`;18 const out = `export * from './entityFolderName/entityFileName-update.component';19export * from './entityFolderName/entityFileName-delete-dialog.component';20export * from './entityFolderName/entityFileName-detail.component';21export * from './entityFolderName/entityFileName.component';22export * from './entityFolderName/entityFileName.state';`;23 expect(BaseGenerator.stripMargin(content)).to.equal(out);24 });25 it('should produce correct indented output without margin', () => {26 const routerName = 'routerName';27 const enableTranslation = true;28 const glyphiconName = 'glyphiconName';29 const content = `|<li ui-sref-active="active">30 | <a ui-sref="${routerName}" ng-click="vm.collapseNavbar()">31 | <span class="glyphicon glyphicon-${glyphiconName}"></span> 32 | <span ${enableTranslation ? `data-translate="global.menu.${routerName}"` : ''}>${routerName}</span>33 | </a>34 |</li>`;35 const out = `<li ui-sref-active="active">36 <a ui-sref="routerName" ng-click="vm.collapseNavbar()">37 <span class="glyphicon glyphicon-glyphiconName"></span> 38 <span data-translate="global.menu.routerName">routerName</span>39 </a>40</li>`;41 expect(BaseGenerator.stripMargin(content)).to.equal(out);42 });43 });44 describe('getDBTypeFromDBValue', () => {45 describe('when called with sql DB name', () => {46 it('return SQL', () => {47 expect(BaseGenerator.getDBTypeFromDBValue('mysql')).to.equal('sql');48 });49 });50 describe('when called with mongo DB', () => {51 it('return mongodb', () => {52 expect(BaseGenerator.getDBTypeFromDBValue('mongodb')).to.equal('mongodb');53 });54 });55 describe('when called with cassandra', () => {56 it('return cassandra', () => {57 expect(BaseGenerator.getDBTypeFromDBValue('cassandra')).to.equal('cassandra');58 });59 });60 });61 describe('generateEntityClientImports', () => {62 describe('with relationships from or to the User', () => {63 const relationships = [64 {65 otherEntityAngularName: 'User'66 },67 {68 otherEntityAngularName: 'AnEntity'69 }70 ];71 describe('when called with dto option', () => {72 it('return an empty Map', () => {73 const imports = BaseGenerator.generateEntityClientImports(relationships, 'yes');74 expect(imports.size).to.eql(0);75 });76 });77 describe('when called with 2 distinct relationships without dto option', () => {78 it('return a Map with 2 imports', () => {79 const imports = BaseGenerator.generateEntityClientImports(relationships, 'no');80 expect(imports).to.have.all.keys('IUser', 'IAnEntity');81 expect(imports.size).to.eql(relationships.length);82 });83 });84 describe('when called with 2 identical relationships without dto option', () => {85 const relationships = [86 {87 otherEntityAngularName: 'User'88 },89 {90 otherEntityAngularName: 'User'91 }92 ];93 it('return a Map with 1 import', () => {94 const imports = BaseGenerator.generateEntityClientImports(relationships, 'no');95 expect(imports).to.have.key('IUser');96 expect(imports.size).to.eql(1);97 });98 });99 });100 describe('with no relationship from or to the User', () => {101 describe('when called to have models to be imported in the templates', () => {102 let importsForAngular = null;103 let importsForReact = null;104 const relationships = [105 {106 otherEntityAngularName: 'AnEntity',107 otherEntityFileName: 'AnEntity',108 otherEntityClientRootFolder: 'anEntity'109 },110 {111 otherEntityAngularName: 'AnotherEntity',112 otherEntityFileName: 'AnotherEntity',113 otherEntityClientRootFolder: 'anotherEntity'114 }115 ];116 before(() => {117 importsForAngular = BaseGenerator.generateEntityClientImports(relationships, 'no', 'angularX');118 importsForReact = BaseGenerator.generateEntityClientImports(relationships, 'no', 'react');119 });120 it('adds the same imports regardless of the client framework', () => {121 expect(importsForAngular).to.eql(importsForReact);122 });123 });124 });125 });126 describe('generateLanguageOptions', () => {127 describe('when called with empty array', () => {128 it('return empty', () => {129 expect(BaseGenerator.generateLanguageOptions([])).to.eql([]);130 });131 });132 describe('when called with languages array', () => {133 it('return languages pipe syntax', () => {134 expect(BaseGenerator.generateLanguageOptions(['en', 'fr'])).to.eql([135 `'en': { name: 'English' }`, // eslint-disable-line136 `'fr': { name: 'Français' }` // eslint-disable-line137 ]);138 });139 });140 });141 describe('skipLanguageForLocale', () => {142 describe('when called with english', () => {143 it('return false', () => {144 expect(BaseGenerator.skipLanguageForLocale('en')).to.equal(false);145 });146 });147 describe('when called with languages ar-ly', () => {148 it('return true', () => {149 expect(BaseGenerator.skipLanguageForLocale('ar-ly')).to.equal(true);150 });151 });152 });153 describe('generateTestEntityId', () => {154 describe('when called with int', () => {155 it('return 123', () => {156 expect(BaseGenerator.generateTestEntityId('int')).to.equal(123);157 });158 });159 describe('when called with String', () => {160 it("return '123'", () => {161 expect(BaseGenerator.generateTestEntityId('String')).to.equal("'123'");162 });163 });164 describe('when called with String and cassandra', () => {165 it("return '9fec3727-3421-4967-b213-ba36557ca194'", () => {166 expect(BaseGenerator.generateTestEntityId('String', 'cassandra')).to.equal("'9fec3727-3421-4967-b213-ba36557ca194'");167 });168 });169 });170 describe('formatAsApiDescription', () => {171 describe('when formatting a nil text', () => {172 it('returns it', () => {173 expect(BaseGenerator.formatAsApiDescription()).to.equal(undefined);174 });175 });176 describe('when formatting an empty text', () => {177 it('returns it', () => {178 expect(BaseGenerator.formatAsApiDescription('')).to.equal('');179 });180 });181 describe('when formatting normal texts', () => {182 describe('when having empty lines', () => {183 it('discards them', () => {184 expect(BaseGenerator.formatAsApiDescription('First line\n \nSecond line\n\nThird line')).to.equal(185 'First line Second line Third line'186 );187 });188 });189 describe('when having HTML tags', () => {190 it('keeps them', () => {191 expect(BaseGenerator.formatAsApiDescription('Not boldy\n<b>boldy</b>')).to.equal('Not boldy<b>boldy</b>');192 });193 });194 describe('when having a plain text', () => {195 it('puts a space before each line', () => {196 expect(BaseGenerator.formatAsApiDescription('JHipster is\na great generator')).to.equal(197 'JHipster is a great generator'198 );199 });200 });201 describe('when having quotes', () => {202 it('formats the text to make the string valid', () => {203 // eslint-disable-next-line quotes204 expect(BaseGenerator.formatAsApiDescription('JHipster is "the" best')).to.equal('JHipster is \\"the\\" best');205 });206 });207 });208 });209 describe('formatAsLiquibaseRemarks', () => {210 describe('when formatting a nil text', () => {211 it('returns it', () => {212 expect(BaseGenerator.formatAsLiquibaseRemarks()).to.equal(undefined);213 });214 });215 describe('when formatting an empty text', () => {216 it('returns it', () => {217 expect(BaseGenerator.formatAsLiquibaseRemarks('')).to.equal('');218 });219 });220 describe('when formatting normal texts', () => {221 describe('when having empty lines', () => {222 it('discards them', () => {223 expect(BaseGenerator.formatAsLiquibaseRemarks('First line\n \nSecond line\n\nThird line')).to.equal(224 'First line Second line Third line'225 );226 });227 });228 describe('when having a plain text', () => {229 it('puts a space before each line', () => {230 expect(BaseGenerator.formatAsLiquibaseRemarks('JHipster is\na great generator')).to.equal(231 'JHipster is a great generator'232 );233 });234 });235 describe('when having ampersand', () => {236 it('formats the text to escape it', () => {237 expect(BaseGenerator.formatAsLiquibaseRemarks('JHipster uses Spring & Hibernate')).to.equal(238 'JHipster uses Spring & Hibernate'239 );240 });241 });242 describe('when having quotes', () => {243 it('formats the text to escape it', () => {244 // eslint-disable-next-line quotes245 expect(BaseGenerator.formatAsLiquibaseRemarks('JHipster is "the" best')).to.equal('JHipster is "the" best');246 });247 });248 describe('when having apostrophe', () => {249 it('formats the text to escape it', () => {250 // eslint-disable-next-line quotes251 expect(BaseGenerator.formatAsLiquibaseRemarks("JHipster is 'the' best")).to.equal('JHipster is 'the' best');252 });253 });254 describe('when having HTML tags < and >', () => {255 it('formats the text to escape it', () => {256 expect(BaseGenerator.formatAsLiquibaseRemarks('Not boldy\n<b>boldy</b>')).to.equal('Not boldy<b>boldy</b>');257 });258 });259 });260 });...
Using AI Code Generation
1I am trying to use the baseGenerator method of storybook-root in my test.js file. I am getting the error “TypeError: Cannot read property ‘baseGenerator’ of undefined”. I have tried using the following code to import the baseGenerator method:2const { baseGenerator } = require(‘storybook-root’);3I have also tried using the following code to import the baseGenerator method:4const baseGenerator = require(‘storybook-root’);5I have tried using the following code to import the baseGenerator method:6import { baseGenerator } from ‘storybook-root’;7I have also tried using the following code to import the baseGenerator method:8import baseGenerator from ‘storybook-root’;9I have also tried using the following code to import the baseGenerator method:10import { baseGenerator } from ‘storybook-root/lib/baseGenerator’;11I have also tried using the following code to import the baseGenerator method:12import baseGenerator from ‘storybook-root/lib/baseGenerator’;13I have also tried using the following code to import the baseGenerator method:14const baseGenerator = require(‘storybook-root/lib/baseGenerator’);15I have also tried using the following code to import the baseGenerator method:16const { baseGenerator } = require(‘storybook-root/lib/baseGenerator’);17I have also tried using the following code to import the baseGenerator method:18const baseGenerator = require(‘storybook-root/lib/baseGenerator’).default;19I have also tried using the following code to import the baseGenerator method:20const { baseGenerator } = require(‘storybook-root/lib/baseGenerator’).default;21I have also tried using the following code to import the baseGenerator method:22const baseGenerator = require(‘storybook-root/lib/baseGenerator’).baseGenerator;23I have also tried using the following code to import the baseGenerator method:24const { baseGenerator } = require(‘storybook-root/lib/baseGenerator’).baseGenerator;25I have also tried using the following code to import the baseGenerator method:26import baseGenerator from ‘storybook-root/lib/baseGenerator’;27I have also tried using the following code to import the baseGenerator method:28import { baseGenerator } from ‘storybook-root/lib/baseGenerator’;29I have also tried using the following code to import
Using AI Code Generation
1import { baseGenerator } from 'storybook-root';2import { baseGenerator } from 'storybook-root';3import { baseGenerator } from 'storybook-root';4import { baseGenerator } from 'storybook-root';5import { baseGenerator } from 'storybook-root';6import { baseGenerator } from 'storybook-root';7import { baseGenerator } from 'storybook-root';8import { baseGenerator } from 'storybook-root';9import { baseGenerator } from 'storybook-root';10import { baseGenerator } from 'storybook-root';11import { baseGenerator } from 'storybook-root';12import { baseGenerator } from 'storybook-root';13import { baseGenerator } from 'storybook-root';14import { baseGenerator } from 'storybook-root';15import { baseGenerator } from 'storybook-root';16import { baseGenerator } from 'storybook-root';17import { baseGenerator } from 'storybook-root';18import { baseGenerator } from 'storybook-root';19import { baseGenerator } from 'storybook-root';20import { baseGenerator } from 'storybook-root';
Using AI Code Generation
1import { baseGenerator } from 'storybook-root';2import { storiesOf } from '@storybook/react';3import { withKnobs } from '@storybook/addon-knobs';4import { withInfo } from '@storybook/addon-info';5import { withA11y } from '@storybook/addon-a11y';6import { withTests } from '@storybook/addon-jest';7import results from '../.jest-test-results.json';8import { withActions } from '@storybook/addon-actions';9import { withState } from '@dump247/storybook-state';10import { withBackgrounds } from '@storybook/addon-backgrounds';11import { withViewport } from '@storybook/addon-viewport';12import { withConsole } from '@storybook/addon-console';13const storybook = storiesOf('storybook-root', module);14storybook.addDecorator(withKnobs);15storybook.addDecorator(withInfo);16storybook.addDecorator(withA11y);17storybook.addDecorator(withTests({ results }));18storybook.addDecorator(withActions);19storybook.addDecorator(withState);20storybook.addDecorator(withBackgrounds);21storybook.addDecorator(withViewport);22storybook.addDecorator((storyFn, context) => withConsole()(storyFn)(context));23storybook.add('storybook-root', baseGenerator('storybook-root'));24import { baseGenerator } from 'storybook-root';25import { storiesOf } from '@storybook/react';26import { withKnobs } from '@storybook/addon-knobs';27import { withInfo } from '@storybook/addon-info';28import { withA11y } from '@storybook/addon-a11y';29import { withTests } from '@storybook/addon-jest';30import results from '../.jest-test-results.json';31import { withActions } from '@storybook/addon-actions';32import { withState } from '@dump247/storybook-state';33import { withBackgrounds } from '@storybook/addon-backgrounds';34import { withViewport } from '@storybook/addon-viewport';35import { withConsole } from '@storybook/addon-console';36const storybook = storiesOf('storybook-root', module);37storybook.addDecorator(withKnobs);38storybook.addDecorator(withInfo);39storybook.addDecorator(withA11y);40storybook.addDecorator(withTests({ results }));41storybook.addDecorator(withActions);42storybook.addDecorator(withState);43storybook.addDecorator(withBackgrounds);44storybook.addDecorator(withViewport);45storybook.addDecorator((storyFn, context) => withConsole()(storyFn)(context));
Using AI Code Generation
1const { baseGenerator } = require('../storybook-root');2const componentGenerator = require('./component');3const storyGenerator = require('./story');4module.exports = (plop) => {5 plop.setGenerator('component', componentGenerator);6 plop.setGenerator('story', storyGenerator);7 baseGenerator(plop);8};9const componentGenerator = {10 {11 },12 {13 path: '../src/components/{{pascalCase name}}/index.js',14 },15 {16 path: '../src/components/{{pascalCase name}}/{{pascalCase name}}.js',17 },18 {19 path: '../src/components/{{pascalCase name}}/{{pascalCase name}}.test.js',20 },21 {22 path: '../src/components/{{pascalCase name}}/{{pascalCase name}}.module.scss',23 },24};25module.exports = componentGenerator;26const storyGenerator = {27 {28 },29 {30 path: '../src/components/{{pascalCase name}}/{{pascalCase name}}.stories.js',31 },32};33module.exports = storyGenerator;34const fs = require('fs');35const path = require('path');36const baseGenerator = (plop) => {37 plop.setGenerator('
Using AI Code Generation
1import { baseGenerator } from 'storybook-root';2const generator = baseGenerator({3 {4 },5});6export default generator;7const test = 'test';8export default test;9import { baseGenerator } from 'storybook-root';10const generator = baseGenerator({11 {12 },13});14export default generator;15const test = 'test';16export default test;17import { baseGenerator } from 'storybook-root';18const generator = baseGenerator({19 {20 },21});22export default generator;23const test = 'test';24export default test;25import { baseGenerator } from 'storybook-root';26const generator = baseGenerator({27 {28 },29});30export default generator;31const test = 'test';32export default test;33import { baseGenerator } from 'storybook-root';34const generator = baseGenerator({35 {36 },37});38export default generator;39const test = 'test';40export default test;41import { baseGenerator } from 'storybook-root';42const generator = baseGenerator({43 {44 },45});46export default generator;47const test = 'test';48export default test;
Using AI Code Generation
1import { baseGenerator } from 'storybook-root';2export default baseGenerator({3});4module.exports = {5};6import { addDecorator } from '@storybook/react';7import { withKnobs } from '@storybook/addon-knobs';8import { withA11y } from '@storybook/addon-a11y';9addDecorator(withKnobs);10addDecorator(withA11y);11const path = require('path');12module.exports = ({ config }) => {13 config.module.rules.push({14 include: path.resolve(__dirname, '../'),15 });16 return config;17};18{19 "compilerOptions": {20 "paths": {21 },22 },23}24{25 "compilerOptions": {26 "paths": {27 }28 },
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!