How to use getGroups method in devicefarmer-stf

Best JavaScript code snippet using devicefarmer-stf

en-globbed.spec.js

Source:en-globbed.spec.js Github

copy

Full Screen

...66 * ------------------------- Test cases for * wildcard ------------------------------67 * ----------------------------------------------------------------------------------68 */69describe('When * wildcard matches multiple characters', function () {70 describe('capture()[x].getGroups()', function () {71 it('should return an array of {type: "wildcard", pattern: "*", match: <matched_str>}', function () {72 let result = capture(['homer.js'], '*.js');73 expect(result[0].getGroups()[0]).to.eql({type: 'wildcard', pattern: '*', match: 'homer'});74 expect(result[0].hasMatch()).to.be.true;75 result = capture(['homer.js'], 'homer*');76 expect(result[0].getGroups()[1]).to.eql({type: 'wildcard', pattern: '*', match: '.js'});77 expect(result[0].hasMatch()).to.be.true;78 result = capture(['homer.js'], 'h*s');79 expect(result[0].getGroups()[1]).to.eql({type: 'wildcard', pattern: '*', match: 'omer.j'});80 expect(result[0].hasMatch()).to.be.true;81 result = capture(['lisa', 'maggie.', 'x'], '*');82 expect(result[0].getGroups()[0]).to.eql({type: 'wildcard', pattern: '*', match: 'lisa'});83 expect(result[1].getGroups()[0]).to.eql({type: 'wildcard', pattern: '*', match: 'maggie.'});84 expect(result[2].getGroups()[0]).to.eql({type: 'wildcard', pattern: '*', match: 'x'});85 expect(result[0].hasMatch()).to.be.true;86 expect(result[1].hasMatch()).to.be.true;87 expect(result[2].hasMatch()).to.be.true;88 });89 });90});91describe('When * wildcard matches a single character', function () {92 describe('capture()[x].getGroups()', function () {93 it('should return an array of {type: "wildcard", pattern: "*", match: <matched_char>}', function () {94 let result = capture(['homer.js'], '*omer.js');95 expect(result[0].getGroups()[0]).to.eql({type: 'wildcard', pattern: '*', match: 'h'});96 expect(result[0].hasMatch()).to.be.true;97 result = capture(['homer.js'], 'homer*js');98 expect(result[0].getGroups()[1]).to.eql({type: 'wildcard', pattern: '*', match: '.'});99 expect(result[0].hasMatch()).to.be.true;100 result = capture(['homer.js'], 'homer.j*');101 expect(result[0].getGroups()[1]).to.eql({type: 'wildcard', pattern: '*', match: 's'});102 expect(result[0].hasMatch()).to.be.true;103 });104 });105});106describe('When * wildcard matches no character', function () {107 describe('capture()[x].getGroups()', function () {108 it('should return an array of {type: "wildcard", pattern: "*", match: ""} because * matches zero or more characters', function () {109 let result = capture(['homer.js'], '*homer.js');110 expect(result[0].getGroups()[0]).to.eql({type: 'wildcard', pattern: '*', match: ''});111 expect(result[0].hasMatch()).to.be.true;112 result = capture(['homer.js'], 'homer*.js');113 expect(result[0].getGroups()[1]).to.eql({type: 'wildcard', pattern: '*', match: ''});114 expect(result[0].hasMatch()).to.be.true;115 result = capture(['homer.js'], 'homer.js*');116 expect(result[0].getGroups()[1]).to.eql({type: 'wildcard', pattern: '*', match: ''});117 expect(result[0].hasMatch()).to.be.true;118 });119 });120});121describe('When ** is specified', function () {122 describe('capture()', function () {123 it('should treat ** like *, e.g. {type: "wildcard", pattern: "*", match: <matched_str>}', function () {124 let result = capture(['homer.js'], '**.js');125 expect(result[0].getGroups().length).to.equal(2);126 expect(result[0].getGroups()[0]).to.eql({type: 'wildcard', pattern: '*', match: 'homer'});127 expect(result[0].hasMatch()).to.be.true;128 result = capture(['homer.js'], 'homer**js');129 expect(result[0].getGroups().length).to.equal(3);130 expect(result[0].getGroups()[1]).to.eql({type: 'wildcard', pattern: '*', match: '.'});131 expect(result[0].hasMatch()).to.be.true;132 result = capture(['homer.js'], 'homer?js**');133 expect(result[0].getGroups().length).to.equal(4);134 expect(result[0].getGroups()[3]).to.eql({type: 'wildcard', pattern: '*', match: ''});135 expect(result[0].hasMatch()).to.be.true;136 result = capture(['abcdef', '123bf4'], '**b**f***');137 expect(result.length).to.equal(2);138 expect(result[0].hasMatch()).to.be.true;139 expect(result[0].getGroups().length).to.equal(5);140 expect(result[0].getGroups()[0]).to.eql({type: 'wildcard', pattern: '*', match: 'a'});141 expect(result[0].getGroups()[1]).to.eql({type: 'literal', pattern: 'b', match: 'b'});142 expect(result[0].getGroups()[2]).to.eql({type: 'wildcard', pattern: '*', match: 'cde'});143 expect(result[0].getGroups()[3]).to.eql({type: 'literal', pattern: 'f', match: 'f'});144 expect(result[0].getGroups()[4]).to.eql({type: 'wildcard', pattern: '*', match: ''});145 expect(result[1].hasMatch()).to.be.true;146 expect(result[1].getGroups().length).to.equal(5);147 expect(result[1].getGroups()[0]).to.eql({type: 'wildcard', pattern: '*', match: '123'});148 expect(result[1].getGroups()[1]).to.eql({type: 'literal', pattern: 'b', match: 'b'});149 expect(result[1].getGroups()[2]).to.eql({type: 'wildcard', pattern: '*', match: ''});150 expect(result[1].getGroups()[3]).to.eql({type: 'literal', pattern: 'f', match: 'f'});151 expect(result[1].getGroups()[4]).to.eql({type: 'wildcard', pattern: '*', match: '4'});152 });153 });154});155describe('When * wildcard is used in glob pattern', function () {156 describe('capture()[x].getAsterisk()', function () {157 it('should return { type, pattern, match } with pattern="*" for every instances of *', function () {158 let result = capture(['homersimpsons.txt'], '*hom??*m*.?**?');159 expect(result[0].getAsterisk()[0]).to.eql({ type: 'wildcard', pattern: '*', match: '' });160 expect(result[0].getAsterisk()[1]).to.eql({ type: 'wildcard', pattern: '*', match: 'si' });161 expect(result[0].getAsterisk()[2]).to.eql({ type: 'wildcard', pattern: '*', match: 'psons' });162 expect(result[0].getAsterisk()[3]).to.eql({ type: 'wildcard', pattern: '*', match: 'x' });163 expect(result[0].hasMatch()).to.be.true;164 result = capture([''], '***');165 expect(result[0].getAsterisk().length).to.eql(1);166 expect(result[0].getAsterisk()[0]).to.eql({ type: 'wildcard', pattern: '*', match: '' });167 expect(result[0].hasMatch()).to.be.true;168 });169 it('should return empty array if glob does not match', function () {170 let result = capture(['Bomersimpsons.txt'], '*hom??*m*.?**?');171 expect(result[0].getAsterisk()).to.be.empty;172 expect(result[0].hasMatch()).to.be.false;173 });174 it('should return empty array if no * wildcard used', function () {175 let result = capture(['homer.txt'], 'homer.???');176 expect(result[0].getAsterisk()).to.be.empty;177 expect(result[0].hasMatch()).to.be.true;178 });179 it('should return empty array when invalid names used for capture()', function () {180 let result = capture([11], '*');181 expect(result.length).to.eql(1);182 expect(result[0].getAsterisk()).to.be.empty;183 expect(result[0].hasMatch()).to.be.false;184 result = capture([{}, 'bob'], '**');185 expect(result.length).to.eql(2);186 expect(result[0].getAsterisk()).to.be.empty;187 expect(result[0].hasMatch()).to.be.false;188 expect(result[1].hasMatch()).to.be.true;189 expect(result[1].getAsterisk()).to.be.not.empty;190 });191 });192});193/*194 * ------------------------------------------------------------------------------195 * ------------------- Tests cases for ? wildcard -------------------------------196 * ------------------------------------------------------------------------------197 */198describe('When ? wildcard matches one character', function () {199 describe('capture()[x].getGroups', function () {200 it('should return an array of {type: "wildcard", pattern: "?", match: <matched_char>}', function () {201 let result = capture(['homer.js'], '?omer.js');202 expect(result[0].getGroups()[0]).to.eql({type: 'wildcard', pattern: '?', match: 'h'});203 expect(result[0].hasMatch()).to.be.true;204 result = capture(['homer.js'], 'homer?js');205 expect(result[0].getGroups()[1]).to.eql({type: 'wildcard', pattern: '?', match: '.'});206 expect(result[0].hasMatch()).to.be.true;207 result = capture(['homer.js'], 'homer.j?');208 expect(result[0].getGroups()[1]).to.eql({type: 'wildcard', pattern: '?', match: 's'});209 expect(result[0].hasMatch()).to.be.true;210 result = capture(['.', 'x'], '?');211 expect(result[0].getGroups()[0]).to.eql({type: 'wildcard', pattern: '?', match: '.'});212 expect(result[1].getGroups()[0]).to.eql({type: 'wildcard', pattern: '?', match: 'x'});213 expect(result[0].hasMatch()).to.be.true;214 expect(result[1].hasMatch()).to.be.true;215 });216 });217});218describe('When ? wildcard matches no character', function () {219 describe('capture()[x].getGroups()', function () {220 it('should return empty array (i.e. no match)', function () {221 let result = capture(['homer.js'], '?homer.js');222 expect(result[0].getGroups()).to.be.empty;223 expect(result[0].hasMatch()).to.be.false;224 result = capture(['homer.js'], 'homer.js?');225 expect(result[0].getGroups()).to.be.empty;226 expect(result[0].hasMatch()).to.be.false;227 result = capture(['homer.js'], 'homer?.js');228 expect(result[0].getGroups()).to.be.empty;229 expect(result[0].hasMatch()).to.be.false;230 result = capture(['bart'], '?????');231 expect(result[0].getGroups()).to.be.empty;232 expect(result[0].hasMatch()).to.be.false;233 });234 });235});236describe('When ? wildcards do not match enough characters', function () {237 describe('capture()[x].getGroups()', function () {238 it('should return empty array (i.e. no match)', function () {239 let result = capture(['barney.beer'], '?');240 expect(result[0].getGroups()).to.be.empty;241 expect(result[0].hasMatch()).to.be.false;242 result = capture(['homer'], '???');243 expect(result[0].getGroups()).to.be.empty;244 expect(result[0].hasMatch()).to.be.false;245 });246 });247});248describe('When multiple ? wildcards are used', function () {249 describe('capture()[x].getGroups()', function () {250 it('should return empty array (i.e. no match), if one or more ? have no match', function () {251 let result = capture(['homer.js'], '??omer.js');252 expect(result[0].getGroups()).to.be.empty;253 expect(result[0].hasMatch()).to.be.false;254 result = capture(['homer.js'], 'homer.j??');255 expect(result[0].getGroups()).to.be.empty;256 expect(result[0].hasMatch()).to.be.false;257 result = capture(['homer.js'], 'home??.js');258 expect(result[0].getGroups()).to.be.empty;259 expect(result[0].hasMatch()).to.be.false;260 result = capture(['homer.js'], '??????????');261 expect(result[0].getGroups()).to.be.empty;262 expect(result[0].hasMatch()).to.be.false;263 result = capture(['homer.js'], '??homer?js');264 expect(result[0].getGroups()).to.be.empty;265 expect(result[0].hasMatch()).to.be.false;266 result = capture(['homer.js'], '??mer.js??');267 expect(result[0].getGroups()).to.be.empty;268 expect(result[0].hasMatch()).to.be.false;269 });270 it('should return in an array of {type: "wildcard", pattern: "?", match: <matched_char>} for each ?, if all of them have a match', function () {271 let result = capture(['homer.js'], 'ho?er?js');272 expect(result[0].getGroups()[1]).to.eql({type: 'wildcard', pattern: '?', match: 'm'});273 expect(result[0].getGroups()[3]).to.eql({type: 'wildcard', pattern: '?', match: '.'});274 expect(result[0].hasMatch()).to.be.true;275 result = capture(['homer.js'], 'h??e???s');276 expect(result[0].getGroups()[1]).to.eql({type: 'wildcard', pattern: '?', match: 'o'});277 expect(result[0].getGroups()[2]).to.eql({type: 'wildcard', pattern: '?', match: 'm'});278 expect(result[0].getGroups()[4]).to.eql({type: 'wildcard', pattern: '?', match: 'r'});279 expect(result[0].getGroups()[5]).to.eql({type: 'wildcard', pattern: '?', match: '.'});280 expect(result[0].getGroups()[6]).to.eql({type: 'wildcard', pattern: '?', match: 'j'});281 expect(result[0].hasMatch()).to.be.true;282 result = capture(['homer.js'], '????????');283 expect(result[0].getGroups()[0]).to.eql({type: 'wildcard', pattern: '?', match: 'h'});284 expect(result[0].getGroups()[1]).to.eql({type: 'wildcard', pattern: '?', match: 'o'});285 expect(result[0].getGroups()[2]).to.eql({type: 'wildcard', pattern: '?', match: 'm'});286 expect(result[0].getGroups()[3]).to.eql({type: 'wildcard', pattern: '?', match: 'e'});287 expect(result[0].getGroups()[4]).to.eql({type: 'wildcard', pattern: '?', match: 'r'});288 expect(result[0].getGroups()[5]).to.eql({type: 'wildcard', pattern: '?', match: '.'});289 expect(result[0].getGroups()[6]).to.eql({type: 'wildcard', pattern: '?', match: 'j'});290 expect(result[0].getGroups()[7]).to.eql({type: 'wildcard', pattern: '?', match: 's'});291 expect(result[0].hasMatch()).to.be.true;292 });293 });294});295describe('When ? wildcard is used in glob pattern', function () {296 describe('capture()[x].getQuestionMark()', function () {297 it('should return { type, pattern, match } with pattern="?" for every instances of ?', function () {298 let result = capture(['homersimpsons.tx$'], '*hom??*m*.?**?');299 expect(result[0].getQuestionMark()[0]).to.eql({ type: 'wildcard', pattern: '?', match: 'e' });300 expect(result[0].getQuestionMark()[1]).to.eql({ type: 'wildcard', pattern: '?', match: 'r' });301 expect(result[0].getQuestionMark()[2]).to.eql({ type: 'wildcard', pattern: '?', match: 't' });302 expect(result[0].getQuestionMark()[3]).to.eql({ type: 'wildcard', pattern: '?', match: '$' });303 expect(result[0].hasMatch()).to.be.true;304 });305 it('should return empty array if glob does not match', function () {306 let result = capture(['Bomersimpsons.txt'], '*hom??*m*.?**?');307 expect(result[0].getQuestionMark()).to.be.empty;308 expect(result[0].hasMatch()).to.be.false;309 result = capture([''], '?');310 expect(result[0].getQuestionMark()).to.be.empty;311 expect(result[0].hasMatch()).to.be.false;312 result = capture(['^omer$'], '???????');313 expect(result[0].getQuestionMark()).to.be.empty;314 expect(result[0].hasMatch()).to.be.false;315 });316 it('should return empty array if no ? wildcard used', function () {317 let result = capture(['homer.txt'], 'homer.*');318 expect(result[0].getQuestionMark()).to.be.empty;319 expect(result[0].hasMatch()).to.be.true;320 });321 it('should return empty array when invalid names used for capture()', function () {322 let result = capture([11], '?');323 expect(result.length).to.eql(1);324 expect(result[0].getQuestionMark()).to.be.empty;325 expect(result[0].hasMatch()).to.be.false;326 result = capture([{}, 'bob'], '???');327 expect(result.length).to.eql(2);328 expect(result[0].getQuestionMark()).to.be.empty;329 expect(result[0].hasMatch()).to.be.false;330 expect(result[1].hasMatch()).to.be.true;331 expect(result[1].getQuestionMark()).to.be.not.empty;332 });333 });334});335/*336 * --------------------------------------------------------------------------------------337 * ------------------------------- Test cases for literals ------------------------------338 * --------------------------------------------------------------------------------------339 */340describe('When the literal part is matched', function () {341 describe('capture()[x].getGroups()', function () {342 it('should return in an array of {type: "literal", pattern: <literal_str>, match: <matched_str>}', function () {343 let result = capture(['homer.js'], 'homer.js');344 expect(result[0].getGroups()[0]).to.eql({type: 'literal', pattern: 'homer.js', match: 'homer.js'});345 expect(result[0].hasMatch()).to.be.true;346 result = capture(['homer..js'], 'homer..js');347 expect(result[0].getGroups()[0]).to.eql({type: 'literal', pattern: 'homer..js', match: 'homer..js'});348 expect(result[0].hasMatch()).to.be.true;349 result = capture(['homer.js'], '*.js');350 expect(result[0].getGroups()[1]).to.eql({type: 'literal', pattern: '.js', match: '.js'});351 expect(result[0].hasMatch()).to.be.true;352 result = capture(['homer.js'], 'h**');353 expect(result[0].getGroups()[0]).to.eql({type: 'literal', pattern: 'h', match: 'h'});354 expect(result[0].hasMatch()).to.be.true;355 result = capture(['homer.js'], '*o*');356 expect(result[0].getGroups()[1]).to.eql({type: 'literal', pattern: 'o', match: 'o'});357 expect(result[0].hasMatch()).to.be.true;358 result = capture(['homer.js'], '?omer.??');359 expect(result[0].getGroups()[1]).to.eql({type: 'literal', pattern: 'omer.', match: 'omer.'});360 expect(result[0].hasMatch()).to.be.true;361 result = capture(['a', 'a'], 'a');362 expect(result[0].getGroups()[0]).to.eql({type: 'literal', pattern: 'a', match: 'a'});363 expect(result[1].getGroups()[0]).to.eql({type: 'literal', pattern: 'a', match: 'a'});364 expect(result[0].hasMatch()).to.be.true;365 expect(result[1].hasMatch()).to.be.true;366 result = capture(['pop(tarts)TXT', ')Tpop(tarts'], 'pop(tarts)TXT');367 expect(result.length).to.eql(2);368 expect(result[0].hasMatch()).to.be.true;369 expect(result[0].getGroups().length).to.eql(1);370 expect(result[0].getGroups()[0]).to.eql({type: 'literal', pattern: 'pop(tarts)TXT', match: 'pop(tarts)TXT'});371 result = capture([')whe(re(is)my)sweet()(pop((tarts))TXT'], ')whe(re(is)my)sweet()(pop((tarts))TXT');372 expect(result.length).to.eql(1);373 expect(result[0].hasMatch()).to.be.true;374 expect(result[0].getGroups().length).to.eql(1);375 expect(result[0].getGroups()[0]).to.eql({type: 'literal', pattern: ')whe(re(is)my)sweet()(pop((tarts))TXT', match: ')whe(re(is)my)sweet()(pop((tarts))TXT'});376 // Glob: contains\\\\backward\\slashes\\ (equals code 'contains\\\\\\\\backward\\\\slashes\\\\') should match contains\\backward\slashes\377 result = capture(['contains\\\\backward\\slashes\\'], 'contains\\\\\\\\backward\\\\slashes\\\\');378 expect(result.length).to.eql(1);379 expect(result[0].hasMatch()).to.be.true;380 expect(result[0].getGroups().length).to.eql(1);381 expect(result[0].getGroups()[0]).to.eql({type: 'literal', pattern: 'contains\\\\\\\\backward\\\\slashes\\\\', match: 'contains\\\\backward\\slashes\\'});382 result = capture([')mix\\(of)\\\\parens(and\\\\)sla(she(\\s)\\)'], ')mix\\\\(of)\\\\\\\\parens(and\\\\\\\\)sla(she(\\\\s)\\\\)');383 expect(result.length).to.eql(1);384 expect(result[0].hasMatch()).to.be.true;385 expect(result[0].getGroups().length).to.eql(1);386 expect(result[0].getGroups()[0]).to.eql({type: 'literal', pattern: ')mix\\\\(of)\\\\\\\\parens(and\\\\\\\\)sla(she(\\\\s)\\\\)', match: ')mix\\(of)\\\\parens(and\\\\)sla(she(\\s)\\)'});387 });388 });389});390describe('When the literal part has no match', function () {391 describe('capture()[x].getGroups()', function () {392 it('should return an empty array', function () {393 let result = capture(['homer.js'], 'homar.js');394 expect(result[0].getGroups()).to.be.empty;395 expect(result[0].hasMatch()).to.be.false;396 result = capture(['homer.js'], '*.j');397 expect(result[0].getGroups()).to.be.empty;398 expect(result[0].hasMatch()).to.be.false;399 result = capture(['homer.js'], 'o*');400 expect(result[0].getGroups()).to.be.empty;401 expect(result[0].hasMatch()).to.be.false;402 result = capture(['homer.js'], '*a*');403 expect(result[0].getGroups()).to.be.empty;404 expect(result[0].hasMatch()).to.be.false;405 result = capture(['homer.js'], '*.');406 expect(result[0].getGroups()).to.be.empty;407 expect(result[0].hasMatch()).to.be.false;408 result = capture(['homer.js'], '?omar.??');409 expect(result[0].getGroups()).to.be.empty;410 expect(result[0].hasMatch()).to.be.false;411 result = capture(['homer.js'], '?i*');412 expect(result[0].getGroups()).to.be.empty;413 expect(result[0].hasMatch()).to.be.false;414 result = capture(['homer.js'], 'homer');415 expect(result[0].getGroups()).to.be.empty;416 expect(result[0].hasMatch()).to.be.false;417 result = capture(['pop(tarts)TXT', ')Tpop(tarts'], 'pop(tarts)TXT');418 expect(result.length).to.eql(2);419 expect(result[1].getGroups()).to.be.empty;420 expect(result[1].hasMatch()).to.be.false;421 });422 });423});424describe('When multiple literal parts matched', function () {425 describe('capture()[x].getGroups()', function () {426 it('should return in an array of {type: "literal", pattern: <literal_str>, match: <matched_str>} for each literal match', function () {427 let result = capture(['homer.js'], 'h*s');428 expect(result[0].getGroups()[0]).to.eql({type: 'literal', pattern: 'h', match: 'h'});429 expect(result[0].getGroups()[2]).to.eql({type: 'literal', pattern: 's', match: 's'});430 expect(result[0].hasMatch()).to.be.true;431 result = capture(['homer.js'], 'home**js');432 expect(result[0].getGroups()[0]).to.eql({type: 'literal', pattern: 'home', match: 'home'});433 expect(result[0].getGroups()[2]).to.eql({type: 'literal', pattern: 'js', match: 'js'});434 expect(result[0].hasMatch()).to.be.true;435 result = capture(['homer.js'], 'homer?js');436 expect(result[0].getGroups()[0]).to.eql({type: 'literal', pattern: 'homer', match: 'homer'});437 expect(result[0].getGroups()[2]).to.eql({type: 'literal', pattern: 'js', match: 'js'});438 expect(result[0].hasMatch()).to.be.true;439 result = capture(['homer.js'], 'ho?e??js');440 expect(result[0].getGroups()[0]).to.eql({type: 'literal', pattern: 'ho', match: 'ho'});441 expect(result[0].getGroups()[2]).to.eql({type: 'literal', pattern: 'e', match: 'e'});442 expect(result[0].getGroups()[5]).to.eql({type: 'literal', pattern: 'js', match: 'js'});443 expect(result[0].hasMatch()).to.be.true;444 result = capture(['homer.js'], '*ho?e*?s');445 expect(result[0].getGroups()[1]).to.eql({type: 'literal', pattern: 'ho', match: 'ho'});446 expect(result[0].getGroups()[3]).to.eql({type: 'literal', pattern: 'e', match: 'e'});447 expect(result[0].getGroups()[6]).to.eql({type: 'literal', pattern: 's', match: 's'});448 expect(result[0].hasMatch()).to.be.true;449 });450 });451});452describe('When literal parts contain "^" and "$" characters', function () {453 describe('capture()[x].getGroups()', function () {454 it('should return in an array of {type: "literal", pattern: <literal_str>, match: <matched_str>} for each literal match)', function () {455 let result = capture(['homer^.js'], 'homer^.js');456 expect(result[0].getGroups()[0]).to.eql({type: 'literal', pattern: 'homer^.js', match: 'homer^.js'});457 expect(result[0].hasMatch()).to.be.true;458 result = capture(['homer.$js'], 'homer.$js');459 expect(result[0].getGroups()[0]).to.eql({type: 'literal', pattern: 'homer.$js', match: 'homer.$js'});460 expect(result[0].hasMatch()).to.be.true;461 result = capture(['^homer.js'], '^homer.js');462 expect(result[0].getGroups()[0]).to.eql({type: 'literal', pattern: '^homer.js', match: '^homer.js'});463 expect(result[0].hasMatch()).to.be.true;464 result = capture(['homer.as$'], 'homer.as$');465 expect(result[0].getGroups()[0]).to.eql({type: 'literal', pattern: 'homer.as$', match: 'homer.as$'});466 expect(result[0].hasMatch()).to.be.true;467 result = capture(['^homer.as$'], '^homer.as$');468 expect(result[0].getGroups()[0]).to.eql({type: 'literal', pattern: '^homer.as$', match: '^homer.as$'});469 expect(result[0].hasMatch()).to.be.true;470 result = capture(['$homer.as^'], '$homer.as^');471 expect(result[0].getGroups()[0]).to.eql({type: 'literal', pattern: '$homer.as^', match: '$homer.as^'});472 expect(result[0].hasMatch()).to.be.true;473 });474 });475 describe('capture()[x].getGroups()', function () {476 it('should return an empty array if not matching', function () {477 let result = capture(['homer.txt'], '^homer.txt$');478 expect(result[0].getGroups()).to.be.empty;479 expect(result[0].hasMatch()).to.be.false;480 result = capture(['homer.txt'], '$homer.txt^');481 expect(result[0].getGroups()).to.be.empty;482 expect(result[0].hasMatch()).to.be.false;483 result = capture(['^^homer.txt$$'], '^homer.txt$');484 expect(result[0].getGroups()).to.be.empty;485 expect(result[0].hasMatch()).to.be.false;486 });487 });488});489/*490 * -------------------------------------------------------------------------------------------491 * ------------------------ Tests mixed wildcards and literals -------------------------------492 * -------------------------------------------------------------------------------------------493 */494describe('When a mix of wildcards and literal parts are used in glob pattern', function () {495 describe('capture()[x].getGroups()', function () {496 it('should return an array of {type, pattern, match} for each part of the pattern, if all parts match', function () {497 let result = capture(['homer.js'], '*.?s');498 expect(result[0].getGroups()[0]).to.eql({type: 'wildcard', pattern: '*', match: 'homer'});499 expect(result[0].getGroups()[1]).to.eql({type: 'literal', pattern: '.', match: '.'});500 expect(result[0].getGroups()[2]).to.eql({type: 'wildcard', pattern: '?', match: 'j'});501 expect(result[0].getGroups()[3]).to.eql({type: 'literal', pattern: 's', match: 's'});502 expect(result[0].hasMatch()).to.be.true;503 result = capture(['homer.js'], 'h*?');504 expect(result[0].getGroups()[0]).to.eql({type: 'literal', pattern: 'h', match: 'h'});505 expect(result[0].getGroups()[1]).to.eql({type: 'wildcard', pattern: '*', match: 'omer.j'});506 expect(result[0].getGroups()[2]).to.eql({type: 'wildcard', pattern: '?', match: 's'});507 expect(result[0].hasMatch()).to.be.true;508 result = capture(['homer.js'], '?**?');509 expect(result[0].getGroups()[0]).to.eql({type: 'wildcard', pattern: '?', match: 'h'});510 expect(result[0].getGroups()[1]).to.eql({type: 'wildcard', pattern: '*', match: 'omer.j'});511 expect(result[0].getGroups()[2]).to.eql({type: 'wildcard', pattern: '?', match: 's'});512 expect(result[0].hasMatch()).to.be.true;513 result = capture(['homer.js'], '???*??**???');514 expect(result[0].getGroups()[0]).to.eql({type: 'wildcard', pattern: '?', match: 'h'});515 expect(result[0].getGroups()[1]).to.eql({type: 'wildcard', pattern: '?', match: 'o'});516 expect(result[0].getGroups()[2]).to.eql({type: 'wildcard', pattern: '?', match: 'm'});517 expect(result[0].getGroups()[3]).to.eql({type: 'wildcard', pattern: '*', match: ''});518 expect(result[0].getGroups()[4]).to.eql({type: 'wildcard', pattern: '?', match: 'e'});519 expect(result[0].getGroups()[5]).to.eql({type: 'wildcard', pattern: '?', match: 'r'});520 expect(result[0].getGroups()[6]).to.eql({type: 'wildcard', pattern: '*', match: ''});521 expect(result[0].getGroups()[7]).to.eql({type: 'wildcard', pattern: '?', match: '.'});522 expect(result[0].getGroups()[8]).to.eql({type: 'wildcard', pattern: '?', match: 'j'});523 expect(result[0].getGroups()[9]).to.eql({type: 'wildcard', pattern: '?', match: 's'});524 expect(result[0].hasMatch()).to.be.true;525 result = capture(['homer.js'], '?o??r**.*');526 expect(result[0].getGroups()[0]).to.eql({type: 'wildcard', pattern: '?', match: 'h'});527 expect(result[0].getGroups()[1]).to.eql({type: 'literal', pattern: 'o', match: 'o'});528 expect(result[0].getGroups()[2]).to.eql({type: 'wildcard', pattern: '?', match: 'm'});529 expect(result[0].getGroups()[3]).to.eql({type: 'wildcard', pattern: '?', match: 'e'});530 expect(result[0].getGroups()[4]).to.eql({type: 'literal', pattern: 'r', match: 'r'});531 expect(result[0].getGroups()[5]).to.eql({type: 'wildcard', pattern: '*', match: ''});532 expect(result[0].getGroups()[6]).to.eql({type: 'literal', pattern: '.', match: '.'});533 expect(result[0].getGroups()[7]).to.eql({type: 'wildcard', pattern: '*', match: 'js'});534 expect(result[0].hasMatch()).to.be.true;535 result = capture(['bart.bar', 'lisa', 'maggie.', 'mr.burns'], '*.');536 expect(result[2].getGroups()[0]).to.eql({type: 'wildcard', pattern: '*', match: 'maggie'});537 expect(result[2].getGroups()[1]).to.eql({type: 'literal', pattern: '.', match: '.'});538 expect(result[2].hasMatch()).to.be.true;539 expect(result[0].hasMatch()).to.be.false;540 expect(result[1].hasMatch()).to.be.false;541 expect(result[3].hasMatch()).to.be.false;542 // * is greedy543 result = capture(['homer.js'], '*??*');544 expect(result[0].getGroups()[0]).to.eql({type: 'wildcard', pattern: '*', match: 'homer.'});545 expect(result[0].getGroups()[1]).to.eql({type: 'wildcard', pattern: '?', match: 'j'});546 expect(result[0].getGroups()[2]).to.eql({type: 'wildcard', pattern: '?', match: 's'});547 expect(result[0].getGroups()[3]).to.eql({type: 'wildcard', pattern: '*', match: ''});548 expect(result[0].hasMatch()).to.be.true;549 });550 it('should return an empty array if any part, except for wildcard *, of the glob does not match', function () {551 let result = capture(['homer.js'], '*.js?');552 expect(result[0].getGroups()).to.be.empty;553 expect(result[0].hasMatch()).to.be.false;554 result = capture(['homer.js'], '*.???');555 expect(result[0].getGroups()).to.be.empty;556 expect(result[0].hasMatch()).to.be.false;557 result = capture(['homer.js'], '*..??');558 expect(result[0].getGroups()).to.be.empty;559 expect(result[0].hasMatch()).to.be.false;560 });561 it('should return an empty array if glob does not completely match the name', function () {562 let result = capture(['homer.js'], '?js');563 expect(result[0].getGroups()).to.be.empty;564 expect(result[0].hasMatch()).to.be.false;565 result = capture(['homer.js'], '?');566 expect(result[0].getGroups()).to.be.empty;567 expect(result[0].hasMatch()).to.be.false;568 result = capture(['homer.js'], '*.?');569 expect(result[0].getGroups()).to.be.empty;570 expect(result[0].hasMatch()).to.be.false;571 result = capture(['homer.js'], 'ho*?j');572 expect(result[0].getGroups()).to.be.empty;573 expect(result[0].hasMatch()).to.be.false;574 result = capture(['bart.bar', 'lisa', 'maggie.', 'mr.burns'], '*.');575 expect(result[0].getGroups()).to.be.empty;576 expect(result[0].hasMatch()).to.be.false;577 expect(result[1].getGroups()).to.be.empty;578 expect(result[1].hasMatch()).to.be.false;579 expect(result[3].getGroups()).to.be.empty;580 expect(result[3].hasMatch()).to.be.false;581 expect(result[2].hasMatch()).to.be.true;582 });583 });584});585/*586 * Testing Error Cases for capture().getGroups()587 */588describe('When element in names array is not a string', function () {589 describe('capture()[x].getGroups()', function () {590 it('should return an array containing an Error object', function () {591 let result = capture([0], '*.txt');592 expect(result.length).to.eql(1);593 expect(result[0].getGroups()[0]).to.be.instanceof(Error)594 .and.have.property('message', 'Invalid type! Expects a string.');595 expect(result[0].hasMatch()).to.be.false;596 result = capture([undefined], 'bob');597 expect(result[0].getGroups().length).to.eql(1);598 expect(result[0].getGroups()[0]).to.be.instanceof(Error)599 .and.have.property('message', 'Invalid type! Expects a string.');600 expect(result[0].hasMatch()).to.be.false;601 result = capture([['name.txt']], 'bob');602 expect(result[0].getGroups().length).to.eql(1);603 expect(result[0].getGroups()[0]).to.be.instanceof(Error)604 .and.have.property('message', 'Invalid type! Expects a string.');605 expect(result[0].hasMatch()).to.be.false;606 result = capture(['homer', {}], '?');607 expect(result.length).to.eql(2);608 expect(result[0].getGroups()[0]).to.not.be.instanceof(Error);609 expect(result[1].getGroups()[0]).to.be.instanceof(Error)610 .and.have.property('message', 'Invalid type! Expects a string.');611 expect(result[0].hasMatch()).to.be.false;612 expect(result[1].hasMatch()).to.be.false;613 });614 });615});616/*617 * Testing Error Cases for capture().getAsterisk()618 */619describe('When invalid parameters are given to capture()', function () {620 describe('capture()[x].getAsterisk()', function () {621 it('should return an empty array', function () {622 let result = capture([0], '*.txt');623 expect(result.length).to.eql(1);...

Full Screen

Full Screen

getGroups.test.ts

Source:getGroups.test.ts Github

copy

Full Screen

...12 let provider: AuthProvider13 let cache: Cache14 function configureProvider(getGroups: (token: string) => string[]) {15 provider = createTestAuthProvider()16 provider.getGroups = jest.fn((token) => Promise.resolve(getGroups(token)))17 cache = new Cache(provider, cacheTTLms)18 }19 function configureErrorProvider() {20 provider = createTestAuthProvider()21 jest22 .spyOn(provider, "getGroups")23 .mockRejectedValue(new Error(testErrorMessage))24 cache = new Cache(provider, cacheTTLms)25 }26 it("fetches groups from the provider", async () => {27 configureProvider(() => ["bread"])28 const groups = await cache.getGroups(testOAuthToken)29 expect(provider.getGroups).toHaveBeenCalledWith(testOAuthToken)30 expect(groups).toEqual(["bread"])31 })32 it("caches groups", async () => {33 configureProvider(() => [])34 await cache.getGroups(testOAuthToken)35 await cache.getGroups(testOAuthToken)36 expect(provider.getGroups).toHaveBeenCalledTimes(1)37 })38 it("invalidates cached groups after its ttl passed", async () => {39 configureProvider(() => [])40 await cache.getGroups(testOAuthToken)41 await delay(cacheTTLms * 2) // ensure it's not flaky42 await cache.getGroups(testOAuthToken)43 expect(provider.getGroups).toHaveBeenCalledTimes(2)44 })45 it("automatically extends the cache ttl on access", async () => {46 configureProvider(() => [])47 await cache.getGroups(testOAuthToken)48 for (let i = 0; i < 3; i++) {49 await delay(cacheTTLms / 2)50 await cache.getGroups(testOAuthToken)51 }52 expect(provider.getGroups).toHaveBeenCalledTimes(1)53 })54 it("returns empty groups when an error occurs", async () => {55 configureErrorProvider()56 const groups = await cache.getGroups(testOAuthToken)57 expect(provider.getGroups).toHaveBeenCalledTimes(1)58 expect(groups).toEqual([])59 })60 it("distinguishes between different tokens", async () => {61 configureProvider((token) => [token])62 const aGroups = await cache.getGroups("goat")63 const bGroups = await cache.getGroups("cheese")64 expect(provider.getGroups).toHaveBeenCalledTimes(2)65 expect(aGroups).toEqual(["goat"])66 expect(bGroups).toEqual(["cheese"])67 })68 })...

Full Screen

Full Screen

auth.service.ts

Source:auth.service.ts Github

copy

Full Screen

...56 return (JSON.parse(atob(user.split('.')[1])).email);57 }58 return ''59 }60 getGroups(): string[]{61 const t = jwt_decode(this.getUser())62 return t['cognito:groups'];63 }64 isMLO(){65 if (this.getGroups() && this.getGroups().filter(g => g == 'mlo') && this.getGroups().filter(g => g == 'mlo').length>0) {66 return true;67 }else{68 return false;69 }70 }71 isLockDeskLimited(){72 if (this.getGroups() && this.getGroups().filter(g => g == 'lockdesk_limited') && this.getGroups().filter(g => g == 'lockdesk_limited').length>0) {73 return true;74 }else{75 return false;76 }77 }78 isAdmin(){79 if (this.getGroups() && this.getGroups().filter(g => g == 'admin') && this.getGroups().filter(g => g == 'admin').length>0) {80 return true;81 }else{82 return false;83 }84 }85 isLockDesk(){86 if (this.getGroups() && this.getGroups().filter(g => g == 'lockdesk') && this.getGroups().filter(g => g == 'lockdesk').length>0) {87 return true;88 }else{89 return false;90 }91 }92 isLockDeskOrMLO(){93 if(this.isLockDesk() || this.isMLO()){94 return true;95 }96 return false;97 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var stf = require('devicefarmer-stf-client');2var client = stf.connect({ host: 'localhost', port: 7100 });3client.getGroups(function (err, groups) {4 console.log(groups);5});6var stf = require('devicefarmer-stf-client');7var client = stf.connect({ host: 'localhost', port: 7100 });8client.getDevices(function (err, devices) {9 console.log(devices);10});11var stf = require('devicefarmer-stf-client');12var client = stf.connect({ host: 'localhost', port: 7100 });13client.getDevices(function (err, devices) {14 console.log(devices);15});16var stf = require('devicefarmer-stf-client');17var client = stf.connect({ host: 'localhost', port: 7100 });18client.getDevices(function (err, devices) {19 console.log(devices);20});21var stf = require('devicefarmer-stf-client');22var client = stf.connect({ host: 'localhost', port: 7100 });23client.getDevices(function (err, devices) {24 console.log(devices);25});26var stf = require('devicefarmer-stf-client');27var client = stf.connect({ host: 'localhost', port: 7100 });28client.getDevices(function (err, devices) {29 console.log(devices);30});31var stf = require('devicefarmer-stf-client');32var client = stf.connect({ host: 'localhost', port: 7100 });33client.getDevices(function (err, devices) {34 console.log(devices);35});36var stf = require('devicefar

Full Screen

Using AI Code Generation

copy

Full Screen

1var stf = require('devicefarmer-stf-client');2var device = new stf.Device(client);3device.getGroups().then(function(groups) {4 console.log(groups);5});6var stf = require('devicefarmer-stf-client');7var device = new stf.Device(client);8device.getDevices().then(function(devices) {9 console.log(devices);10});11var stf = require('devicefarmer-stf-client');12var device = new stf.Device(client);13device.getDevicesByGroup('group1').then(function(devices) {14 console.log(devices);15});16var stf = require('devicefarmer-stf-client');17var device = new stf.Device(client);18device.getDevicesByGroup('group1').then(function(devices) {19 console.log(devices);20});21var stf = require('devicefarmer-stf-client');22var device = new stf.Device(client);23device.getDevicesByOwner('owner1').then(function(devices) {24 console.log(devices);25});26var stf = require('devicefarmer-stf-client');27var device = new stf.Device(client);28device.getDevicesBySerial('serial1').then(function(devices) {29 console.log(devices);30});31var stf = require('devicefarmer-stf-client');

Full Screen

Using AI Code Generation

copy

Full Screen

1var STF = require('devicefarmer-stf-client');2var stf = new STF();3stf.getGroups().then(function (groups) {4 console.log(groups);5});6var STF = require('devicefarmer-stf-client');7var stf = new STF();8stf.getDevices().then(function (devices) {9 console.log(devices);10});11var STF = require('devicefarmer-stf-client');12var stf = new STF();13stf.getDevices().then(function (devices) {14 console.log(devices);15});16var STF = require('devicefarmer-stf-client');17var stf = new STF();18stf.getDevices().then(function (devices) {19 console.log(devices);20});21var STF = require('devicefarmer-stf-client');22var stf = new STF();23stf.getDevices().then(function (devices) {24 console.log(devices);25});26var STF = require('devicefarmer-stf-client');27var stf = new STF();28stf.getDevices().then(function (devices) {29 console.log(devices);30});31var STF = require('devicefarmer-stf-client');32var stf = new STF();33stf.getDevices().then(function (devices) {34 console.log(devices);35});36var STF = require('devicefarmer-stf-client');37var stf = new STF();38stf.getDevices().then(function (devices) {39 console.log(devices);40});41var STF = require('devicefarmer-stf-client');42var stf = new STF();43stf.getDevices().then(function (devices) {44 console.log(devices);45});46var STF = require('devicefarmer-stf-client

Full Screen

Using AI Code Generation

copy

Full Screen

1var client = require('devicefarmer-stf-client');2var stf = new client();3stf.getGroups(function(err, data){4 if(err){5 console.log(err);6 }else{7 console.log(data);8 }9});10var client = require('devicefarmer-stf-client');11var stf = new client();12stf.getDevices(function(err, data){13 if(err){14 console.log(err);15 }else{16 console.log(data);17 }18});19var client = require('devicefarmer-stf-client');20var stf = new client();21stf.getDevicesByGroup("group1", function(err, data){22 if(err){23 console.log(err);24 }else{25 console.log(data);26 }27});28var client = require('devicefarmer-stf-client');29var stf = new client();30stf.getDevicesByOwner("owner1", function(err, data){31 if(err){32 console.log(err);33 }else{34 console.log(data);35 }36});37var client = require('devicefarmer-stf-client');38var stf = new client();39stf.getDevicesByUser("user1", function(err, data){40 if(err){41 console.log(err);42 }else{43 console.log(data);44 }45});46var client = require('devicefarmer-stf-client');47var stf = new client();48stf.getDevicesBySerial("serial1", function(err, data){49 if(err){50 console.log(err);51 }else{52 console.log(data);53 }54});55var client = require('devicefarmer-stf-client');56var stf = new client();57stf.getDevicesByProvider("provider1", function(err, data){58 if(err){59 console.log(err);

Full Screen

Using AI Code Generation

copy

Full Screen

1var stf = require('devicefarmer-stf');2client.getGroups().then(function(groups) {3 console.log('Groups: ', groups);4});5Groups: [ { id: 1, name: 'default', description: 'Default group' } ]6var stf = require('devicefarmer-stf');7client.getDevices().then(function(devices) {8 console.log('Devices: ', devices);9});10Devices: [ { serial: '0123456789ABCDEF',

Full Screen

Using AI Code Generation

copy

Full Screen

1var client = require('devicefarmer-stf-client');2stf.getGroups(function(err, groups) {3 console.log(groups);4});5[ { id: 1, name: 'default', owner: 'admin' } ]6[ { id: 1, name: 'default', owner: 'admin' },7 { id: 2, name: 'group1', owner: 'admin' } ]8[ { id: 1, name: 'default', owner: 'admin' },9 { id: 2, name: 'group1', owner: 'admin' },10 { id: 3, name: 'group2', owner: 'admin' } ]11[ { id: 1, name: 'default', owner: 'admin' },12 { id: 2, name: 'group1', owner: 'admin' },13 { id: 3, name: 'group2', owner: 'admin' },14 { id: 4, name: 'group3', owner: 'admin' } ]15[ { id: 1, name: 'default', owner: 'admin' },16 { id: 2, name: 'group1', owner: 'admin' },17 { id: 3, name: 'group2', owner: 'admin' },18 { id: 4, name: 'group3', owner: 'admin' },19 { id: 5, name: 'group4', owner: 'admin' } ]20[ { id: 1, name: 'default', owner: 'admin' },21 { id: 2, name: 'group1', owner: 'admin' },22 { id: 3, name: 'group2', owner: 'admin' },23 { id: 4, name: 'group3', owner: 'admin' },24 { id: 5, name: 'group4', owner: 'admin' },25 { id: 6, name: 'group5', owner: 'admin' } ]26[ { id: 1, name: 'default', owner: 'admin' },27 {

Full Screen

Using AI Code Generation

copy

Full Screen

1var stf = require('devicefarmer-stf-client');2client.getGroups(function(err, groups) {3});4var stf = require('devicefarmer-stf-client');5client.getDevices(function(err, devices) {6});7var stf = require('devicefarmer-stf-client');8client.getDevices(function(err, devices) {9});10var stf = require('devicefarmer-stf-client');11client.getDevices(function(err, devices) {12});13var stf = require('devicefarmer-stf-client');14client.getDevices(function(err, devices) {15});16var stf = require('devicefarmer-stf-client');17client.getDevices(function(err, devices) {

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run devicefarmer-stf 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