Best JavaScript code snippet using ng-mocks
resolve.js
Source:resolve.js
...73 const cache = {};74 this.getProviderCacheStub.returns( cache );75 const resolveProvider = this.subject();76 assert.strictEqual(77 await resolveProvider( stream, "", {} ),78 cache,79 "Returns cache if it is available"80 );81 assert.propEqual( this.isAbortedSpy.args, [[ stream ]], "Calls isAborted once" );82 assert.ok( this.getProviderCacheStub.calledOnce, "Gets provider cache once" );83 assert.notOk( this.whichFallbackStub.called, "Doesn't look up provider files" );84 assert.notOk( this.validateProviderStub.called, "Doesn't validate provider" );85 assert.notOk( this.setProviderCacheStub.called, "Doesn't set provider cache" );86});87/**88 * Check for existing provider configs89 */90test( "Invalid streaming provider", async function( assert ) {91 this.config = { [ this.provider ]: {} };92 const resolveProvider = this.subject();93 await assert.rejects(94 resolveProvider( stream, this.provider, {} ),95 new Error( "Invalid streaming provider: streamlink-provider" ),96 "Throws error on missing provider user data"97 );98 assert.propEqual( this.isAbortedSpy.args, [[ stream ]], "Calls isAborted once" );99 assert.ok( this.getProviderCacheStub.calledOnce, "Gets provider cache once" );100 assert.notOk( this.setProviderCacheStub.called, "Doesn't set provider cache" );101 this.isAbortedSpy.resetHistory();102 this.getProviderCacheStub.resetHistory();103 await assert.rejects(104 resolveProvider( stream, "livestreamer", { livestreamer: {} } ),105 new Error( "Invalid streaming provider: livestreamer" ),106 "Throws error on invalid provider data"107 );108 assert.propEqual( this.isAbortedSpy.args, [[ stream ]], "Calls isAborted once" );109 assert.ok( this.getProviderCacheStub.calledOnce, "Gets provider cache once" );110 assert.notOk( this.setProviderCacheStub.called, "Doesn't set provider cache" );111});112/**113 * Check for existing provider exec configs for current platform114 */115test( "Missing executable name for streaming provider", async function( assert ) {116 let resolveProvider;117 const providerUserData = {};118 this.config = {119 [ this.provider ]: {120 exec: {121 [ this.platform ]: null122 }123 }124 };125 resolveProvider = this.subject();126 await assert.rejects(127 resolveProvider( stream, this.provider, { [ this.provider ]: providerUserData } ),128 new Error( "Missing executable name for streaming provider" ),129 "Throws error on missing provider (user) conf exec data"130 );131 assert.propEqual( this.isAbortedSpy.args, [[ stream ]], "Calls isAborted once" );132 assert.ok( this.getProviderCacheStub.calledOnce, "Gets provider cache once" );133 assert.notOk( this.setProviderCacheStub.called, "Doesn't set provider cache" );134 assert.propEqual(135 this.logDebugSpy.args,136 [[ "Resolving streaming provider", { provider: this.provider, providerUserData } ]],137 "Logs provider name and user data"138 );139 this.isAbortedSpy.resetHistory();140 this.getProviderCacheStub.resetHistory();141 this.logDebugSpy.resetHistory();142 this.config = {143 [ this.provider ]: {144 exec: {145 linux: "streamlink-exec"146 }147 }148 };149 this.platform = "win32";150 resolveProvider = this.subject();151 await assert.rejects(152 resolveProvider( stream, this.provider, { [ this.provider ]: providerUserData } ),153 new Error( "Missing executable name for streaming provider" ),154 "Throws error on missing exec for current platform"155 );156 assert.propEqual( this.isAbortedSpy.args, [[ stream ]], "Calls isAborted once" );157 assert.ok( this.getProviderCacheStub.calledOnce, "Gets provider cache once" );158 assert.notOk( this.setProviderCacheStub.called, "Doesn't set provider cache" );159 assert.propEqual(160 this.logDebugSpy.args,161 [[ "Resolving streaming provider", { provider: this.provider, providerUserData } ]],162 "Logs provider name and user data"163 );164});165/**166 * Check for existing provider python script configs for current platform167 */168test( "Missing python script for streaming provider", async function( assert ) {169 let resolveProvider;170 const providerUserData = {};171 this.config = {172 [ this.provider ]: {173 python: true,174 exec: {175 [ this.platform ]: "python"176 },177 pythonscript: {178 [ this.platform ]: null179 }180 }181 };182 resolveProvider = this.subject();183 await assert.rejects(184 resolveProvider( stream, this.provider, { [ this.provider ]: providerUserData } ),185 new Error( "Missing python script for streaming provider" ),186 "Throws error on missing pythonscript"187 );188 assert.propEqual( this.isAbortedSpy.args, [[ stream ]], "Calls isAborted once" );189 assert.ok( this.getProviderCacheStub.calledOnce, "Gets provider cache once" );190 assert.notOk( this.setProviderCacheStub.called, "Doesn't set provider cache" );191 assert.propEqual(192 this.logDebugSpy.args,193 [[ "Resolving streaming provider", { provider: this.provider, providerUserData } ]],194 "Logs provider name and user data"195 );196 this.isAbortedSpy.resetHistory();197 this.getProviderCacheStub.resetHistory();198 this.logDebugSpy.resetHistory();199 this.config = {200 [ this.provider ]: {201 python: true,202 exec: {203 win32: "python"204 },205 pythonscript: {206 linux: "streamlink-script"207 }208 }209 };210 this.platform = "win32";211 resolveProvider = this.subject();212 await assert.rejects(213 resolveProvider( stream, this.provider, { [ this.provider ]: providerUserData } ),214 new Error( "Missing python script for streaming provider" ),215 "Throws error on missing pythonscript for current platform"216 );217 assert.propEqual( this.isAbortedSpy.args, [[ stream ]], "Calls isAborted once" );218 assert.ok( this.getProviderCacheStub.calledOnce, "Gets provider cache once" );219 assert.notOk( this.setProviderCacheStub.called, "Doesn't set provider cache" );220 assert.propEqual(221 this.logDebugSpy.args,222 [[ "Resolving streaming provider", { provider: this.provider, providerUserData } ]],223 "Logs provider name and user data"224 );225});226/**227 * Reject and resolve default standalone provider exec228 */229test( "Standalone - Default exec", async function( assert ) {230 const error = new Error( "Executables were not found" );231 const providerUserData = {};232 this.provider = "streamlinkw";233 this.platform = "win32";234 this.config = {235 [ this.provider ]: {236 exec: {237 [ this.platform ]: "streamlinkw.exe"238 },239 fallback: {240 [ this.platform ]: [241 "C:\\streamlink"242 ]243 }244 }245 };246 const resolveProvider = this.subject();247 // reject248 this.whichFallbackStub.throws( error );249 await assert.rejects(250 resolveProvider( stream, this.provider, { [ this.provider ]: providerUserData } ),251 new ProviderError( "Couldn't find executable", error ),252 "Throws a ProviderError on unresolvable file"253 );254 assert.propEqual( this.isAbortedSpy.args, [[ stream ]], "Calls isAborted once" );255 assert.ok( this.getProviderCacheStub.calledOnce, "Tries to get provider cache once" );256 assert.propEqual(257 this.whichFallbackStub.args,258 [[259 this.config[ this.provider ].exec[ this.platform ],260 this.config[ this.provider ].fallback261 ]],262 "Calls whichFallback with correct exec and fallbacks"263 );264 assert.notOk( this.validateProviderStub.called, "Doesn't validate provider" );265 assert.notOk( this.setProviderCacheStub.called, "Doesn't set provider cache" );266 assert.propEqual(267 this.logDebugSpy.args,268 [[ "Resolving streaming provider", { provider: this.provider, providerUserData } ]],269 "Logs provider name and user data"270 );271 this.isAbortedSpy.resetHistory();272 this.getProviderCacheStub.resetHistory();273 this.logDebugSpy.resetHistory();274 this.whichFallbackStub.reset();275 // resolve276 this.whichFallbackStub.returns( "C:\\streamlink\\streamlinkw.exe" );277 const expected = {278 exec: "C:\\streamlink\\streamlinkw.exe",279 params: null,280 env: null281 };282 assert.propEqual(283 await resolveProvider( stream, this.provider, { [ this.provider ]: providerUserData } ),284 expected,285 "Returns the correct execObj"286 );287 assert.propEqual( this.isAbortedSpy.args, [ [ stream] , [ stream ] ], "Calls isAborted twice" );288 assert.ok( this.getProviderCacheStub.calledOnce, "Tries to get provider cache once" );289 assert.propEqual(290 this.whichFallbackStub.args,291 [[292 this.config[ this.provider ].exec[ this.platform ],293 this.config[ this.provider ].fallback294 ]],295 "Calls whichFallback with correct exec and fallbacks"296 );297 assert.propEqual(298 this.validateProviderStub.args,299 [[ expected, this.config[ this.provider ] ]],300 "Validates the resolved provider"301 );302 assert.propEqual(303 this.setProviderCacheStub.args,304 [[ expected ]],305 "Sets up cache with correct execObj"306 );307 assert.propEqual(308 this.logDebugSpy.args,309 [310 [ "Resolving streaming provider", { provider: this.provider, providerUserData } ],311 [ "Found streaming provider", expected ],312 [ "Validated streaming provider", expected ]313 ],314 "Logs provider name and user data, and logs resolved and validated data"315 );316});317/**318 * Reject and resolve custom standalone provider exec319 */320test( "Standalone - Custom exec", async function( assert ) {321 const error = new Error( "Executables were not found" );322 let providerUserData;323 this.provider = "streamlinkw";324 this.platform = "win32";325 this.config = {326 [ this.provider ]: {327 exec: {328 [ this.platform ]: "streamlinkw.exe"329 },330 fallback: {331 [ this.platform ]: [332 "C:\\streamlink"333 ]334 }335 }336 };337 const resolveProvider = this.subject();338 // reject339 providerUserData = { exec: "C:\\non-existing\\streamlinkw.exe" };340 this.whichFallbackStub.throws( error );341 await assert.rejects(342 resolveProvider( stream, this.provider, { [ this.provider ]: providerUserData } ),343 new ProviderError( "Couldn't find executable", error ),344 "Throws a ProviderError on unresolvable file"345 );346 assert.propEqual( this.isAbortedSpy.args, [[ stream ]], "Calls isAborted once" );347 assert.ok( this.getProviderCacheStub.calledOnce, "Tries to get provider cache once" );348 assert.propEqual(349 this.whichFallbackStub.args,350 [[ providerUserData.exec ]],351 "Calls whichFallback with correct exec and no fallbacks"352 );353 assert.notOk( this.validateProviderStub.called, "Doesn't validate provider" );354 assert.notOk( this.setProviderCacheStub.called, "Doesn't set provider cache" );355 assert.propEqual(356 this.logDebugSpy.args,357 [[ "Resolving streaming provider", { provider: this.provider, providerUserData } ]],358 "Logs provider name and user data"359 );360 this.isAbortedSpy.resetHistory();361 this.getProviderCacheStub.resetHistory();362 this.logDebugSpy.resetHistory();363 this.whichFallbackStub.reset();364 // resolve365 providerUserData = { exec: "C:\\custom\\standalone.exe" };366 this.whichFallbackStub.returns( providerUserData.exec );367 const expected = {368 exec: "C:\\custom\\standalone.exe",369 params: null,370 env: null371 };372 assert.propEqual(373 await resolveProvider( stream, this.provider, { [ this.provider ]: providerUserData } ),374 expected,375 "Returns the correct execObj"376 );377 assert.propEqual( this.isAbortedSpy.args, [ [ stream] , [ stream ] ], "Calls isAborted twice" );378 assert.ok( this.getProviderCacheStub.calledOnce, "Tries to get provider cache once" );379 assert.propEqual(380 this.whichFallbackStub.args,381 [[ providerUserData.exec ]],382 "Calls whichFallback with correct exec and no fallbacks"383 );384 assert.propEqual(385 this.validateProviderStub.args,386 [[ expected, this.config[ this.provider ] ]],387 "Validates the resolved provider"388 );389 assert.propEqual(390 this.setProviderCacheStub.args,391 [[ expected ]],392 "Sets up cache with correct execObj"393 );394 assert.propEqual(395 this.logDebugSpy.args,396 [397 [ "Resolving streaming provider", { provider: this.provider, providerUserData } ],398 [ "Found streaming provider", expected ],399 [ "Validated streaming provider", expected ]400 ],401 "Logs provider name and user data, and logs resolved and validated data"402 );403});404/**405 * Check for existing python script and validate it406 */407test( "Python - Invalid python script", async function( assert ) {408 const errorWhich = new Error( "Executables were not found" );409 const errorInterpret = new Error( "Invalid python script" );410 const providerUserData = {};411 const resolveProvider = this.subject();412 // reject (unkown python script)413 this.whichFallbackStub.throws( errorWhich );414 await assert.rejects(415 resolveProvider( stream, this.provider, { [ this.provider ]: providerUserData } ),416 new ProviderError( "Couldn't find python script", errorWhich ),417 "Throws a ProviderError on unresolvable file"418 );419 assert.propEqual( this.isAbortedSpy.args, [[ stream ]], "Calls isAborted once" );420 assert.ok( this.getProviderCacheStub.calledOnce, "Tries to get provider cache once" );421 assert.propEqual(422 this.whichFallbackStub.args,423 [[424 this.config[ this.provider ].pythonscript[ this.platform ],425 this.config[ this.provider ].pythonscriptfallback,426 isFile427 ]],428 "Calls whichFallback with correct pythonscript, fallbacks and file check method"429 );430 assert.notOk(431 this.findPythonscriptInterpreterStub.called,432 "Doesn't call findPythonscriptInterpreter"433 );434 assert.notOk( this.validateProviderStub.called, "Doesn't validate provider" );435 assert.notOk( this.setProviderCacheStub.called, "Doesn't set provider cache" );436 assert.propEqual(437 this.logDebugSpy.args,438 [[ "Resolving streaming provider", { provider: this.provider, providerUserData } ]],439 "Logs provider name and user data"440 );441 this.isAbortedSpy.resetHistory();442 this.getProviderCacheStub.resetHistory();443 this.logDebugSpy.resetHistory();444 this.whichFallbackStub.reset();445 // reject (invalid python script)446 this.whichFallbackStub.returns( "/usr/bin/streamlink" );447 this.findPythonscriptInterpreterStub.throws( errorInterpret );448 await assert.rejects(449 resolveProvider( stream, this.provider, { [ this.provider ]: providerUserData } ),450 new ProviderError( "Couldn't validate python script", errorInterpret ),451 "Throws a ProviderError on unresolvable pythonscript"452 );453 assert.propEqual( this.isAbortedSpy.args, [[ stream ]], "Calls isAborted once" );454 assert.ok( this.getProviderCacheStub.calledOnce, "Tries to get provider cache once" );455 assert.propEqual(456 this.whichFallbackStub.args,457 [[458 this.config[ this.provider ].pythonscript[ this.platform ],459 this.config[ this.provider ].pythonscriptfallback,460 isFile461 ]],462 "Calls whichFallback with correct pythonscript, fallbacks and file check method"463 );464 assert.propEqual(465 this.findPythonscriptInterpreterStub.args,466 [[467 "/usr/bin/streamlink",468 this.config[ this.provider ],469 undefined470 ]],471 "Calls findPythonscriptInterpreter"472 );473 assert.notOk( this.validateProviderStub.called, "Doesn't validate provider" );474 assert.notOk( this.setProviderCacheStub.called, "Doesn't set provider cache" );475 assert.propEqual(476 this.logDebugSpy.args,477 [[ "Resolving streaming provider", { provider: this.provider, providerUserData } ]],478 "Logs provider name and user data"479 );480});481/**482 * Resolve default python script and its returned executable483 */484test( "Python - Default python exec/script", async function( assert ) {485 const providerUserData = {};486 const resolveProvider = this.subject();487 this.whichFallbackStub.returns( "/usr/bin/streamlink" );488 this.findPythonscriptInterpreterStub.returns( new ExecObj( "/usr/bin/python" ) );489 const expected = new ExecObj( "/usr/bin/python", [ "/usr/bin/streamlink" ], null );490 assert.propEqual(491 await resolveProvider( stream, this.provider, { [ this.provider ]: providerUserData } ),492 expected,493 "Resolves python script and its executable"494 );495 assert.propEqual( this.isAbortedSpy.args, [ [ stream] , [ stream ] ], "Calls isAborted twice" );496 assert.ok( this.getProviderCacheStub.calledOnce, "Tries to get provider cache once" );497 assert.propEqual(498 this.whichFallbackStub.args,499 [[500 this.config[ this.provider ].pythonscript[ this.platform ],501 this.config[ this.provider ].pythonscriptfallback,502 isFile503 ]],504 "Only calls whichFallback once with correct pythonscript, fallbacks and file check method"505 );506 assert.propEqual(507 this.findPythonscriptInterpreterStub.args,508 [[509 "/usr/bin/streamlink",510 this.config[ this.provider ],511 undefined512 ]],513 "Calls findPythonscriptInterpreter"514 );515 assert.propEqual(516 this.validateProviderStub.args,517 [[ expected, this.config[ this.provider ] ]],518 "Validates the resolved provider"519 );520 assert.propEqual(521 this.setProviderCacheStub.args,522 [[ expected ]],523 "Sets up cache with correct execObj"524 );525 assert.propEqual(526 this.logDebugSpy.args,527 [528 [ "Resolving streaming provider", { provider: this.provider, providerUserData } ],529 [ "Found streaming provider", expected ],530 [ "Validated streaming provider", expected ]531 ],532 "Logs provider name and user data, and logs resolved and validated data"533 );534});535/**536 * Resolve and reject custom python script and custom python executable537 */538test( "Python - Custom python exec/script", async function( assert ) {539 const error = new Error( "Executables were not found" );540 const providerUserData = {541 exec: "/usr/local/bin/python",542 pythonscript: "/usr/local/bin/streamlink"543 };544 this.whichFallbackStub.onCall( 0 ).returns( providerUserData.pythonscript );545 this.whichFallbackStub.onCall( 1 ).returns( providerUserData.exec );546 this.findPythonscriptInterpreterStub.returns( new ExecObj( "/usr/bin/python" ) );547 const resolveProvider = this.subject();548 // resolve549 const expected = new ExecObj( "/usr/local/bin/python", [ "/usr/local/bin/streamlink" ], null );550 assert.propEqual(551 await resolveProvider( stream, this.provider, { [ this.provider ]: providerUserData } ),552 expected,553 "Resolves python script and its executable"554 );555 assert.propEqual( this.isAbortedSpy.args, [ [ stream] , [ stream ] ], "Calls isAborted twice" );556 assert.ok( this.getProviderCacheStub.calledOnce, "Tries to get provider cache once" );557 assert.propEqual(558 this.whichFallbackStub.args,559 [560 [561 providerUserData.pythonscript,562 this.config[ this.provider ].pythonscriptfallback,563 isFile564 ],565 [566 providerUserData.exec567 ]568 ],569 "Calls whichFallback with custom pythonscript and fb, then with custom exec and no fb"570 );571 assert.propEqual(572 this.findPythonscriptInterpreterStub.args,573 [[574 "/usr/local/bin/streamlink",575 this.config[ this.provider ],576 "/usr/local/bin/python"577 ]],578 "Calls findPythonscriptInterpreter"579 );580 assert.propEqual(581 this.validateProviderStub.args,582 [[ expected, this.config[ this.provider ] ]],583 "Validates the resolved provider"584 );585 assert.propEqual(586 this.setProviderCacheStub.args,587 [[ expected ]],588 "Sets up cache with correct execObj"589 );590 assert.propEqual(591 this.logDebugSpy.args,592 [593 [ "Resolving streaming provider", { provider: this.provider, providerUserData } ],594 [ "Found streaming provider", expected ],595 [ "Validated streaming provider", expected ]596 ],597 "Logs provider name and user data, and logs resolved and validated data"598 );599 this.isAbortedSpy.resetHistory();600 this.getProviderCacheStub.resetHistory();601 this.logDebugSpy.resetHistory();602 this.whichFallbackStub.resetHistory();603 this.findPythonscriptInterpreterStub.resetHistory();604 this.validateProviderStub.resetHistory();605 this.setProviderCacheStub.resetHistory();606 // reject607 this.whichFallbackStub.onCall( 1 ).throws( error );608 await assert.rejects(609 resolveProvider( stream, this.provider, { [ this.provider ]: providerUserData } ),610 new ProviderError( "Couldn't find python executable", error ),611 "Throws a ProviderError on invalid custom exec"612 );613 assert.propEqual( this.isAbortedSpy.args, [[ stream ]], "Calls isAborted once" );614 assert.ok( this.getProviderCacheStub.calledOnce, "Tries to get provider cache once" );615 assert.propEqual(616 this.whichFallbackStub.args,617 [618 [619 providerUserData.pythonscript,620 this.config[ this.provider ].pythonscriptfallback,621 isFile622 ],623 [624 providerUserData.exec625 ]626 ],627 "Calls whichFallback with custom pythonscript and fb, then with custom exec and no fb"628 );629 assert.propEqual(630 this.findPythonscriptInterpreterStub.args,631 [[632 "/usr/local/bin/streamlink",633 this.config[ this.provider ],634 "/usr/local/bin/python"635 ]],636 "Calls findPythonscriptInterpreter"637 );638 assert.notOk( this.validateProviderStub.called, "Doesn't validate provider" );639 assert.notOk( this.setProviderCacheStub.called, "Doesn't set provider cache" );640 assert.propEqual(641 this.logDebugSpy.args,642 [[ "Resolving streaming provider", { provider: this.provider, providerUserData } ]],643 "Logs provider name and user data"644 );645});646/**647 * Resolve python script and executable from bash wrapper script data648 */649test( "Python - Bash wrapper script", async function( assert ) {650 const providerUserData = {};651 const expected = new ExecObj(652 "/usr/bin/different-python",653 [ "/usr/bin/different-streamlink-script" ],654 { foo: "bar" }655 );656 this.whichFallbackStub.returns( "/usr/bin/streamlink-script" );657 this.findPythonscriptInterpreterStub.returns( expected );658 const resolveProvider = this.subject();659 assert.propEqual(660 await resolveProvider( stream, this.provider, { [ this.provider ]: providerUserData } ),661 expected,662 "Resolves python script and its executable"663 );664 assert.propEqual( this.isAbortedSpy.args, [ [ stream] , [ stream ] ], "Calls isAborted twice" );665 assert.ok( this.getProviderCacheStub.calledOnce, "Tries to get provider cache once" );666 assert.propEqual(667 this.whichFallbackStub.args,668 [[669 this.config[ this.provider ].pythonscript[ this.platform ],670 this.config[ this.provider ].pythonscriptfallback,671 isFile672 ]],673 "Only calls whichFallback once with correct pythonscript, fallbacks and file check method"674 );675 assert.propEqual(676 this.findPythonscriptInterpreterStub.args,677 [[678 "/usr/bin/streamlink-script",679 this.config[ this.provider ],680 undefined681 ]],682 "Calls findPythonscriptInterpreter"683 );684 assert.propEqual(685 this.validateProviderStub.args,686 [[ expected, this.config[ this.provider ] ]],687 "Validates the resolved provider"688 );689 assert.propEqual(690 this.setProviderCacheStub.args,691 [[ expected ]],692 "Sets up cache with correct execObj"693 );694 assert.propEqual(695 this.logDebugSpy.args,696 [697 [ "Resolving streaming provider", { provider: this.provider, providerUserData } ],698 [ "Found streaming provider", expected ],699 [ "Validated streaming provider", expected ]700 ],701 "Logs provider name and user data, and logs resolved and validated data"702 );703});704/**705 * Reject on provider validation fail706 */707test( "Provider validation", async function( assert ) {708 const error = new Error( "Validation error" );709 const providerUserData = {};710 const resolveProvider = this.subject();711 this.whichFallbackStub.returns( "/usr/bin/streamlink" );712 this.findPythonscriptInterpreterStub.returns( new ExecObj( "/usr/bin/python" ) );713 this.validateProviderStub.throws( error );714 const expected = new ExecObj( "/usr/bin/python", [ "/usr/bin/streamlink" ], null );715 await assert.rejects(716 resolveProvider( stream, this.provider, { [ this.provider ]: providerUserData } ),717 error,718 "Throws validation error"719 );720 assert.propEqual( this.isAbortedSpy.args, [ [ stream] , [ stream ] ], "Calls isAborted twice" );721 assert.ok( this.getProviderCacheStub.calledOnce, "Tries to get provider cache once" );722 assert.propEqual(723 this.whichFallbackStub.args,724 [[725 this.config[ this.provider ].pythonscript[ this.platform ],726 this.config[ this.provider ].pythonscriptfallback,727 isFile728 ]],729 "Only calls whichFallback once with correct pythonscript, fallbacks and file check method"730 );...
resolve-provider.test.ts
Source:resolve-provider.test.ts
...63 );64 describe('when super.json is defined', () => {65 it('should return Provider instance when provider is string', async () => {66 expect(67 resolveProvider({68 superJson: mockSuperJson(),69 provider: 'bar',70 })71 ).toEqual(new Provider(new ProviderConfiguration('bar', [])));72 });73 it('should return Provider instance with exisitng values', async () => {74 expect(75 resolveProvider({76 superJson: mockSuperJson(),77 provider: new Provider(78 new ProviderConfiguration('bar', mockSecurityValues, mockParameters)79 ),80 profileId: 'foo',81 })82 ).toEqual(83 new Provider(84 new ProviderConfiguration('bar', mockSecurityValues, mockParameters)85 )86 );87 });88 it('should return Provider instance with super.json values', async () => {89 expect(90 resolveProvider({91 superJson: mockSuperJson(true),92 provider: 'bar',93 })94 ).toEqual(95 new Provider(96 new ProviderConfiguration('bar', mockSecurityValues, mockParameters)97 )98 );99 });100 it('should return Provider instance with custom values', async () => {101 expect(102 resolveProvider({103 superJson: mockSuperJson(),104 security: mockSecurityValues,105 parameters: mockParameters,106 provider: 'bar',107 })108 ).toEqual(109 new Provider(110 new ProviderConfiguration('bar', mockSecurityValues, mockParameters)111 )112 );113 });114 it('should return Provider instance with overriden values', async () => {115 expect(116 resolveProvider({117 superJson: mockSuperJson(),118 provider: new Provider(new ProviderConfiguration('bar', [], {})),119 profileId: 'foo',120 security: mockSecurityValues,121 parameters: mockParameters,122 })123 ).toEqual(124 new Provider(125 new ProviderConfiguration('bar', mockSecurityValues, mockParameters)126 )127 );128 });129 it('should return Provider instance and get provider for profile', async () => {130 expect(131 resolveProvider({132 superJson: mockSuperJson(),133 profileId: 'foo',134 })135 ).toEqual(new Provider(new ProviderConfiguration('bar', [])));136 });137 it('should return Provider instance and get provider for profile with values from super.json', async () => {138 expect(139 resolveProvider({140 superJson: mockSuperJson(true),141 profileId: 'foo',142 })143 ).toEqual(144 new Provider(145 new ProviderConfiguration('bar', mockSecurityValues, mockParameters)146 )147 );148 });149 it('should return Provider instance and get provider for profile with custom values', async () => {150 expect(151 resolveProvider({152 superJson: mockSuperJson(),153 profileId: 'foo',154 security: mockSecurityValues,155 parameters: mockParameters,156 })157 ).toEqual(158 new Provider(159 new ProviderConfiguration('bar', mockSecurityValues, mockParameters)160 )161 );162 });163 it('should throw error when profile is not configured in super.json', async () => {164 expect(() =>165 resolveProvider({166 profileId: 'boo',167 superJson: normalizeSuperJsonDocument(168 {169 profiles: {170 boo: {171 version: '1.2.3',172 },173 },174 providers: {},175 },176 new MockEnvironment()177 ),178 })179 ).toThrow(noConfiguredProviderError('boo'));180 });181 it('should throw error when profile is not found in super.json', async () => {182 expect(() =>183 resolveProvider({ profileId: 'test', superJson: mockSuperJson() })184 ).toThrow(profileNotFoundError('test'));185 });186 });187 describe('when super.json is undefined', () => {188 it('should return Provider instance', async () => {189 expect(190 resolveProvider({191 provider: 'bar',192 })193 ).toEqual(new Provider(new ProviderConfiguration('bar', [])));194 });195 it('should return Provider instance with custom values', async () => {196 expect(197 resolveProvider({198 security: mockSecurityValues,199 parameters: mockParameters,200 provider: 'bar',201 })202 ).toEqual(203 new Provider(204 new ProviderConfiguration('bar', mockSecurityValues, mockParameters)205 )206 );207 });208 it('should return Provider instance with overriden values', async () => {209 expect(210 resolveProvider({211 security: mockSecurityValues,212 parameters: mockParameters,213 provider: new Provider(new ProviderConfiguration('bar', [])),214 })215 ).toEqual(216 new Provider(217 new ProviderConfiguration('bar', mockSecurityValues, mockParameters)218 )219 );220 });221 it('should throw error when provider and super.json is undefined', async () => {222 expect(() => resolveProvider({ profileId: 'foo' })).toThrow(223 noConfiguredProviderError('foo')224 );225 });226 it('should throw error when provider, profile id and super.json is undefined', async () => {227 expect(() => resolveProvider({})).toThrow(unableToResolveProviderError());228 });229 });...
service.js
Source:service.js
...25 const results = keys.map( key => PROVIDER[key] )26 return results27}28exports.getAccounts = async (providerId) => {29 const provider = resolveProvider(providerId)30 const accounts = await provider.getAccounts()31 return accounts32}33exports.getBalance = async (providerId, walletAddress, tokenBalanceAddress) => {34 const provider = resolveProvider(providerId)35 return provider.getBalance(provider, walletAddress, tokenBalanceAddress)36}37exports.signMessage = async (providerId, walletAddress, msg) => {38 const provider = resolveProvider(providerId)39 return provider.signMessage(walletAddress, msg)40}41exports.generateSubmission = async (providerId, walletAddress, tokenBalanceAddress, msg) => {42 const provider = resolveProvider(providerId)43 const tokenBalance = await provider.getBalance(provider, walletAddress, tokenBalanceAddress)44 const submission = await provider.signMessage(walletAddress, msg)45 const response = {46 tokenBalanceAddress,47 walletAddress,48 tokenBalance,49 message: msg,50 verification: submission51 }52 return response53}54exports.verifyMessage = async (providerId, payload, signature, walletAddress) => {55 const provider = resolveProvider(providerId)56 const { isProd } = provider57 return provider.verifyMessage(isProd, payload, signature, walletAddress)...
Using AI Code Generation
1import { resolveProvider } from 'ng-mocks';2import { createComponent } from 'ng-mocks';3describe('AppComponent', () => {4 beforeEach(async(() => {5 TestBed.configureTestingModule({6 }).compileComponents();7 }));8 it('should create the app', () => {9 const fixture = TestBed.createComponent(AppComponent);10 const app = fixture.debugElement.componentInstance;11 expect(app).toBeTruthy();12 });13 it(`should have as title 'app'`, () => {14 const fixture = TestBed.createComponent(AppComponent);15 const app = fixture.debugElement.componentInstance;16 expect(app.title).toEqual('app');17 });18 it('should render title in a h1 tag', () => {19 const fixture = TestBed.createComponent(AppComponent);20 fixture.detectChanges();21 const compiled = fixture.debugElement.nativeElement;22 expect(compiled.querySelector('h1').textContent).toContain('Welcome to app!');23 });24});25import { resolveProvider } from 'ng-mocks';26import { createComponent } from 'ng-mocks';27describe('AppComponent', () => {28 beforeEach(async(() => {29 TestBed.configureTestingModule({30 }).compileComponents();31 }));32 it('should create the app', () => {33 const fixture = TestBed.createComponent(AppComponent);34 const app = fixture.debugElement.componentInstance;35 expect(app).toBeTruthy();36 });37 it(`should have as title 'app'`, () => {38 const fixture = TestBed.createComponent(AppComponent);39 const app = fixture.debugElement.componentInstance;40 expect(app.title).toEqual('app');41 });42 it('should render title in a h1 tag', () => {43 const fixture = TestBed.createComponent(AppComponent);44 fixture.detectChanges();45 const compiled = fixture.debugElement.nativeElement;46 expect(compiled.querySelector('h1').textContent).toContain('Welcome to app!');47 });48});49import { resolveProvider } from 'ng-mocks';50import { createComponent } from 'ng-mocks';51describe('AppComponent', () => {52 beforeEach(async(() => {53 TestBed.configureTestingModule({
Using AI Code Generation
1import { resolveProvider } from 'ng-mocks';2const provider = resolveProvider(ProviderClass);3const provider = resolveProvider({4});5const provider = resolveProvider({6 useFactory: () => 'value',7});8const provider = resolveProvider({9});10const provider = resolveProvider({11 useFactory: () => 'value',12});13const provider = resolveProvider({14 useFactory: () => 'value',15});16const provider = resolveProvider({17 useFactory: () => 'value',18});19const provider = resolveProvider({20 useFactory: () => 'value',21});22const provider = resolveProvider({23 useFactory: () => 'value',24});25const provider = resolveProvider({26 useFactory: () => 'value',27});28const provider = resolveProvider({29 useFactory: () => 'value',30});31const provider = resolveProvider({
Using AI Code Generation
1import {resolveProvider} from 'ng-mocks';2import {SomeService} from './some.service';3import {SomeComponent} from './some.component';4import {SomeModule} from './some.module';5const mockSomeService = {6 getSomeData: () => {7 return 'test data';8 }9};10const mockSomeComponent = {11};12const mockSomeModule = {13};14const mockSomeModule2 = {15};16const mockSomeModule3 = {17};18describe('SomeComponent', () => {19 let component: SomeComponent;20 let fixture: ComponentFixture<SomeComponent>;21 let someService: SomeService;22 beforeEach(async(() => {23 TestBed.configureTestingModule({24 imports: [SomeModule],25 resolveProvider(SomeService, mockSomeService),26 resolveProvider(SomeModule, mockSomeModule),27 resolveProvider(SomeModule, mockSomeModule2),28 resolveProvider(SomeModule, mockSomeModule3),29 })30 .compileComponents();31 }));32 beforeEach(() => {33 fixture = TestBed.createComponent(SomeComponent);34 component = fixture.componentInstance;35 fixture.detectChanges();36 someService = TestBed.get(SomeService);37 });38 it('should create', () => {39 expect(component).toBeTruthy();40 });41 it('should return test data', () => {42 expect(someService.getSomeData()).toBe('test data');43 });44});45import {async, ComponentFixture, TestBed} from '@angular/core/testing';46import {SomeComponent} from './some.component';47import {SomeService} from './some.service';48import {SomeModule} from './some.module';49describe('SomeComponent', () => {50 let component: SomeComponent;51 let fixture: ComponentFixture<SomeComponent>;52 let someService: SomeService;53 beforeEach(async(() => {54 TestBed.configureTestingModule({
Using AI Code Generation
1import { resolveProvider } from 'ng-mocks';2import { MyService } from './my-service';3import { resolveProvider } from 'ng-mocks';4import { MyService } from './my-service';5import { resolveProvider } from 'ng-mocks';6import { MyService } from './my-service';7import { resolveProvider } from 'ng-mocks';8import { MyService } from './my-service';9import { resolveProvider } from 'ng-mocks';10import { MyService } from './my-service';11import { resolveProvider } from 'ng-mocks';12import { MyService } from './my-service';13import { resolveProvider } from 'ng-mocks';14import { MyService } from './my-service';15import { resolveProvider } from 'ng-mocks';16import { MyService } from './my-service';17import { resolveProvider } from 'ng-mocks';18import { MyService } from './my-service';19import { resolveProvider } from 'ng-mocks';20import { MyService } from './my-service';21import { resolveProvider } from 'ng-mocks';22import { MyService } from './my-service';23import { resolveProvider } from 'ng-mocks';24import { MyService } from './my-service';25import { resolveProvider } from 'ng-mocks';26import { MyService } from './my-service';27import { resolveProvider } from 'ng-mocks';28import { MyService } from './my-service';29import { resolveProvider } from 'ng-mocks';30import { MyService } from './my-service';31import { resolveProvider } from 'ng-mocks';32import { MyService } from './my-service';
Using AI Code Generation
1import { resolveProvider } from 'ng-mocks';2import { MockService } from './mock-service';3describe('test', () => {4 it('should test', () => {5 const mockService = resolveProvider(MockService);6 });7});8import { Injectable } from '@angular/core';9import { MockBuilder, MockRender } from 'ng-mocks';10@Injectable()11export class MockService {12 constructor() {13 }14}
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!!