How to use secondRunOutput method in fast-check-monorepo

Best JavaScript code snippet using fast-check-monorepo

index.test.js

Source:index.test.js Github

copy

Full Screen

1'use strict';2const chai = require('chai');3const sinon = require('sinon');4const path = require('path');5const EventEmitter = require('events');6const fse = require('fs-extra');7const log = require('log').get('serverless:test');8const proxyquire = require('proxyquire');9const overrideEnv = require('process-utils/override-env');10const AwsProvider = require('../../../../../../lib/plugins/aws/provider');11const Serverless = require('../../../../../../lib/serverless');12const CLI = require('../../../../../../lib/classes/cli');13const { getTmpDirPath } = require('../../../../../utils/fs');14const skipWithNotice = require('@serverless/test/skip-with-notice');15const runServerless = require('../../../../../utils/run-serverless');16const spawnExt = require('child-process-ext/spawn');17const tmpServicePath = __dirname;18chai.use(require('chai-as-promised'));19chai.should();20const expect = chai.expect;21describe('AwsInvokeLocal', () => {22 let AwsInvokeLocal;23 let awsInvokeLocal;24 let options;25 let serverless;26 let provider;27 let stdinStub;28 let spawnExtStub;29 let spawnStub;30 let writeChildStub;31 let endChildStub;32 beforeEach(() => {33 options = {34 stage: 'dev',35 region: 'us-east-1',36 function: 'first',37 };38 spawnStub = sinon.stub();39 endChildStub = sinon.stub();40 writeChildStub = sinon.stub();41 spawnExtStub = sinon.stub().resolves({42 stdoutBuffer: Buffer.from('Mocked output'),43 });44 spawnStub = sinon.stub().returns({45 stderr: new EventEmitter().on('data', () => {}),46 stdout: new EventEmitter().on('data', () => {}),47 stdin: {48 write: writeChildStub,49 end: endChildStub,50 },51 on: (key, callback) => {52 if (key === 'close') process.nextTick(callback);53 },54 });55 stdinStub = sinon.stub().resolves('');56 AwsInvokeLocal = proxyquire('../../../../../../lib/plugins/aws/invoke-local/index', {57 'get-stdin': stdinStub,58 'child-process-ext/spawn': spawnExtStub,59 });60 serverless = new Serverless({ commands: [], options: {} });61 serverless.serviceDir = 'servicePath';62 serverless.cli = new CLI(serverless);63 serverless.processedInput = { commands: ['invoke'] };64 provider = new AwsProvider(serverless, options);65 provider.cachedCredentials = {66 credentials: { accessKeyId: 'foo', secretAccessKey: 'bar' },67 };68 serverless.setProvider('aws', provider);69 awsInvokeLocal = new AwsInvokeLocal(serverless, options);70 awsInvokeLocal.provider = provider;71 });72 describe('#extendedValidate()', () => {73 let backupIsTTY;74 beforeEach(() => {75 serverless.serviceDir = true;76 serverless.service.environment = {77 vars: {},78 stages: {79 dev: {80 vars: {},81 regions: {82 'us-east-1': {83 vars: {},84 },85 },86 },87 },88 };89 serverless.service.functions = {90 first: {91 handler: true,92 },93 };94 awsInvokeLocal.options.data = null;95 awsInvokeLocal.options.path = false;96 // Ensure there's no attempt to read path from stdin97 backupIsTTY = process.stdin.isTTY;98 process.stdin.isTTY = true;99 });100 afterEach(() => {101 if (backupIsTTY) process.stdin.isTTY = backupIsTTY;102 else delete process.stdin.isTTY;103 });104 it('should not throw error when there are no input data', async () => {105 awsInvokeLocal.options.data = undefined;106 await expect(awsInvokeLocal.extendedValidate()).to.be.fulfilled;107 expect(awsInvokeLocal.options.data).to.equal('');108 });109 it('it should throw error if function is not provided', () => {110 serverless.service.functions = null;111 return expect(awsInvokeLocal.extendedValidate()).to.be.rejected;112 });113 it('should keep data if it is a simple string', async () => {114 awsInvokeLocal.options.data = 'simple-string';115 await expect(awsInvokeLocal.extendedValidate()).to.be.fulfilled;116 expect(awsInvokeLocal.options.data).to.equal('simple-string');117 });118 it('should parse data if it is a json string', async () => {119 awsInvokeLocal.options.data = '{"key": "value"}';120 await expect(awsInvokeLocal.extendedValidate()).to.be.fulfilled;121 expect(awsInvokeLocal.options.data).to.deep.equal({ key: 'value' });122 });123 it('should skip parsing data if "raw" requested', async () => {124 awsInvokeLocal.options.data = '{"key": "value"}';125 awsInvokeLocal.options.raw = true;126 await expect(awsInvokeLocal.extendedValidate()).to.be.fulfilled;127 expect(awsInvokeLocal.options.data).to.deep.equal('{"key": "value"}');128 });129 it('should parse context if it is a json string', async () => {130 awsInvokeLocal.options.context = '{"key": "value"}';131 await expect(awsInvokeLocal.extendedValidate()).to.be.fulfilled;132 expect(awsInvokeLocal.options.context).to.deep.equal({ key: 'value' });133 });134 it('should skip parsing context if "raw" requested', async () => {135 awsInvokeLocal.options.context = '{"key": "value"}';136 awsInvokeLocal.options.raw = true;137 await expect(awsInvokeLocal.extendedValidate()).to.be.fulfilled;138 expect(awsInvokeLocal.options.context).to.deep.equal('{"key": "value"}');139 });140 it('it should parse file if relative file path is provided', async () => {141 serverless.serviceDir = getTmpDirPath();142 const data = {143 testProp: 'testValue',144 };145 serverless.utils.writeFileSync(146 path.join(serverless.serviceDir, 'data.json'),147 JSON.stringify(data)148 );149 awsInvokeLocal.options.contextPath = 'data.json';150 await expect(awsInvokeLocal.extendedValidate()).to.be.fulfilled;151 expect(awsInvokeLocal.options.context).to.deep.equal(data);152 });153 it('it should parse file if absolute file path is provided', async () => {154 serverless.serviceDir = getTmpDirPath();155 const data = {156 event: {157 testProp: 'testValue',158 },159 };160 const dataFile = path.join(serverless.serviceDir, 'data.json');161 serverless.utils.writeFileSync(dataFile, JSON.stringify(data));162 awsInvokeLocal.options.path = dataFile;163 awsInvokeLocal.options.contextPath = false;164 await expect(awsInvokeLocal.extendedValidate()).to.be.fulfilled;165 expect(awsInvokeLocal.options.data).to.deep.equal(data);166 });167 it('it should parse a yaml file if file path is provided', async () => {168 serverless.serviceDir = getTmpDirPath();169 const yamlContent = 'event: data';170 serverless.utils.writeFileSync(path.join(serverless.serviceDir, 'data.yml'), yamlContent);171 awsInvokeLocal.options.path = 'data.yml';172 await expect(awsInvokeLocal.extendedValidate()).to.be.fulfilled;173 expect(awsInvokeLocal.options.data).to.deep.equal({ event: 'data' });174 });175 it('it should require a js file if file path is provided', async () => {176 serverless.serviceDir = getTmpDirPath();177 const jsContent = [178 'module.exports = {',179 ' headers: { "Content-Type" : "application/json" },',180 ' body: JSON.stringify([100, 200]),',181 '}',182 ].join('\n');183 serverless.utils.writeFileSync(path.join(serverless.serviceDir, 'data.js'), jsContent);184 awsInvokeLocal.options.path = 'data.js';185 await expect(awsInvokeLocal.extendedValidate()).to.be.fulfilled;186 expect(awsInvokeLocal.options.data).to.deep.equal({187 headers: { 'Content-Type': 'application/json' },188 body: '[100,200]',189 });190 });191 it('it should reject error if file path does not exist', () => {192 serverless.serviceDir = getTmpDirPath();193 awsInvokeLocal.options.path = 'some/path';194 return expect(awsInvokeLocal.extendedValidate()).to.be.rejected;195 });196 });197 describe('#getCredentialEnvVars()', () => {198 it('returns empty object when credentials is not set', () => {199 provider.cachedCredentials = null;200 const credentialEnvVars = awsInvokeLocal.getCredentialEnvVars();201 expect(credentialEnvVars).to.be.eql({});202 });203 it('returns credential env vars from cached credentials', () => {204 provider.cachedCredentials = {205 credentials: {206 accessKeyId: 'ID',207 secretAccessKey: 'SECRET',208 sessionToken: 'TOKEN',209 },210 };211 const credentialEnvVars = awsInvokeLocal.getCredentialEnvVars();212 expect(credentialEnvVars).to.be.eql({213 AWS_ACCESS_KEY_ID: 'ID',214 AWS_SECRET_ACCESS_KEY: 'SECRET',215 AWS_SESSION_TOKEN: 'TOKEN',216 });217 });218 });219 describe('#loadEnvVars()', () => {220 let restoreEnv;221 beforeEach(() => {222 ({ restoreEnv } = overrideEnv());223 serverless.serviceDir = true;224 serverless.service.provider = {225 environment: {226 providerVar: 'providerValue',227 },228 };229 awsInvokeLocal.provider.options.region = 'us-east-1';230 awsInvokeLocal.options = {231 functionObj: {232 name: 'serviceName-dev-hello',233 environment: {234 functionVar: 'functionValue',235 },236 },237 };238 });239 afterEach(() => restoreEnv());240 it('it should load provider env vars', async () => {241 await awsInvokeLocal.loadEnvVars();242 expect(process.env.providerVar).to.be.equal('providerValue');243 });244 it('it should load provider profile env', async () => {245 serverless.service.provider.profile = 'jdoe';246 await awsInvokeLocal.loadEnvVars();247 expect(process.env.AWS_PROFILE).to.be.equal('jdoe');248 });249 it('it should load function env vars', async () => {250 await awsInvokeLocal.loadEnvVars();251 expect(process.env.functionVar).to.be.equal('functionValue');252 });253 it('it should load default lambda env vars', async () => {254 await awsInvokeLocal.loadEnvVars();255 expect(process.env.LANG).to.equal('en_US.UTF-8');256 expect(process.env.LD_LIBRARY_PATH).to.equal(257 '/usr/local/lib64/node-v4.3.x/lib:/lib64:/usr/lib64:/var/runtime:/var/runtime/lib:/var/task:/var/task/lib'258 );259 expect(process.env.LAMBDA_TASK_ROOT).to.equal('/var/task');260 expect(process.env.LAMBDA_RUNTIME_DIR).to.equal('/var/runtime');261 expect(process.env.AWS_REGION).to.equal('us-east-1');262 expect(process.env.AWS_DEFAULT_REGION).to.equal('us-east-1');263 expect(process.env.AWS_LAMBDA_LOG_GROUP_NAME).to.equal('/aws/lambda/serviceName-dev-hello');264 expect(process.env.AWS_LAMBDA_LOG_STREAM_NAME).to.equal(265 '2016/12/02/[$LATEST]f77ff5e4026c45bda9a9ebcec6bc9cad'266 );267 expect(process.env.AWS_LAMBDA_FUNCTION_NAME).to.equal('serviceName-dev-hello');268 expect(process.env.AWS_LAMBDA_FUNCTION_MEMORY_SIZE).to.equal('1024');269 expect(process.env.AWS_LAMBDA_FUNCTION_VERSION).to.equal('$LATEST');270 expect(process.env.NODE_PATH).to.equal('/var/runtime:/var/task:/var/runtime/node_modules');271 });272 it('it should set credential env vars #1', async () => {273 provider.cachedCredentials = {274 credentials: {275 accessKeyId: 'ID',276 secretAccessKey: 'SECRET',277 },278 };279 await awsInvokeLocal.loadEnvVars();280 expect(process.env.AWS_ACCESS_KEY_ID).to.equal('ID');281 expect(process.env.AWS_SECRET_ACCESS_KEY).to.equal('SECRET');282 expect('AWS_SESSION_TOKEN' in process.env).to.equal(false);283 });284 it('it should set credential env vars #2', async () => {285 provider.cachedCredentials = {286 credentials: {287 sessionToken: 'TOKEN',288 },289 };290 await awsInvokeLocal.loadEnvVars();291 expect(process.env.AWS_SESSION_TOKEN).to.equal('TOKEN');292 expect('AWS_ACCESS_KEY_ID' in process.env).to.equal(false);293 expect('AWS_SECRET_ACCESS_KEY' in process.env).to.equal(false);294 });295 it('it should work without cached credentials set', async () => {296 provider.cachedCredentials = null;297 await awsInvokeLocal.loadEnvVars();298 expect('AWS_SESSION_TOKEN' in process.env).to.equal(false);299 expect('AWS_ACCESS_KEY_ID' in process.env).to.equal(false);300 expect('AWS_SECRET_ACCESS_KEY' in process.env).to.equal(false);301 });302 it('should fallback to service provider configuration when options are not available', async () => {303 awsInvokeLocal.provider.options.region = null;304 awsInvokeLocal.serverless.service.provider.region = 'us-west-1';305 await awsInvokeLocal.loadEnvVars();306 expect(process.env.AWS_REGION).to.equal('us-west-1');307 expect(process.env.AWS_DEFAULT_REGION).to.equal('us-west-1');308 });309 it('it should overwrite provider env vars', async () => {310 awsInvokeLocal.options.functionObj.environment.providerVar = 'providerValueOverwritten';311 await awsInvokeLocal.loadEnvVars();312 expect(process.env.providerVar).to.be.equal('providerValueOverwritten');313 });314 });315 describe('#invokeLocal()', () => {316 let invokeLocalNodeJsStub;317 let invokeLocalPythonStub;318 let invokeLocalJavaStub;319 let invokeLocalRubyStub;320 let invokeLocalDockerStub;321 beforeEach(() => {322 invokeLocalNodeJsStub = sinon.stub(awsInvokeLocal, 'invokeLocalNodeJs').resolves();323 invokeLocalPythonStub = sinon.stub(awsInvokeLocal, 'invokeLocalPython').resolves();324 invokeLocalJavaStub = sinon.stub(awsInvokeLocal, 'invokeLocalJava').resolves();325 invokeLocalRubyStub = sinon.stub(awsInvokeLocal, 'invokeLocalRuby').resolves();326 invokeLocalDockerStub = sinon.stub(awsInvokeLocal, 'invokeLocalDocker').resolves();327 awsInvokeLocal.serverless.service.service = 'new-service';328 awsInvokeLocal.provider.options.stage = 'dev';329 awsInvokeLocal.options = {330 function: 'first',331 functionObj: {332 handler: 'handler.hello',333 name: 'hello',334 },335 data: {},336 };337 });338 afterEach(() => {339 awsInvokeLocal.invokeLocalNodeJs.restore();340 awsInvokeLocal.invokeLocalPython.restore();341 awsInvokeLocal.invokeLocalJava.restore();342 awsInvokeLocal.invokeLocalRuby.restore();343 });344 it('should call invokeLocalNodeJs when no runtime is set', async () => {345 await awsInvokeLocal.invokeLocal();346 expect(invokeLocalNodeJsStub.calledOnce).to.be.equal(true);347 expect(348 invokeLocalNodeJsStub.calledWithExactly('handler', 'hello', {}, undefined)349 ).to.be.equal(true);350 });351 describe('for different handler paths', () => {352 [353 { path: 'handler.hello', expected: 'handler' },354 { path: '.build/handler.hello', expected: '.build/handler' },355 ].forEach((item) => {356 it(`should call invokeLocalNodeJs for any node.js runtime version for ${item.path}`, async () => {357 awsInvokeLocal.options.functionObj.handler = item.path;358 awsInvokeLocal.options.functionObj.runtime = 'nodejs12.x';359 await awsInvokeLocal.invokeLocal();360 expect(invokeLocalNodeJsStub.calledOnce).to.be.equal(true);361 expect(362 invokeLocalNodeJsStub.calledWithExactly(item.expected, 'hello', {}, undefined)363 ).to.be.equal(true);364 });365 });366 });367 it('should call invokeLocalNodeJs with custom context if provided', async () => {368 awsInvokeLocal.options.context = 'custom context';369 await awsInvokeLocal.invokeLocal();370 expect(invokeLocalNodeJsStub.calledOnce).to.be.equal(true);371 expect(372 invokeLocalNodeJsStub.calledWithExactly('handler', 'hello', {}, 'custom context')373 ).to.be.equal(true);374 });375 it('should call invokeLocalPython when python2.7 runtime is set', async () => {376 awsInvokeLocal.options.functionObj.runtime = 'python2.7';377 await awsInvokeLocal.invokeLocal();378 // NOTE: this is important so that tests on Windows won't fail379 const runtime = process.platform === 'win32' ? 'python.exe' : 'python2.7';380 expect(invokeLocalPythonStub.calledOnce).to.be.equal(true);381 expect(382 invokeLocalPythonStub.calledWithExactly(runtime, 'handler', 'hello', {}, undefined)383 ).to.be.equal(true);384 });385 it('should call invokeLocalJava when java8 runtime is set', async () => {386 awsInvokeLocal.options.functionObj.runtime = 'java8';387 await awsInvokeLocal.invokeLocal();388 expect(invokeLocalJavaStub.calledOnce).to.be.equal(true);389 expect(390 invokeLocalJavaStub.calledWithExactly(391 'java',392 'handler.hello',393 'handleRequest',394 undefined,395 {},396 undefined397 )398 ).to.be.equal(true);399 });400 it('should call invokeLocalRuby when ruby2.5 runtime is set', async () => {401 awsInvokeLocal.options.functionObj.runtime = 'ruby2.5';402 await awsInvokeLocal.invokeLocal();403 // NOTE: this is important so that tests on Windows won't fail404 const runtime = process.platform === 'win32' ? 'ruby.exe' : 'ruby';405 expect(invokeLocalRubyStub.calledOnce).to.be.equal(true);406 expect(407 invokeLocalRubyStub.calledWithExactly(runtime, 'handler', 'hello', {}, undefined)408 ).to.be.equal(true);409 });410 it('should call invokeLocalDocker if using runtime provided', async () => {411 awsInvokeLocal.options.functionObj.runtime = 'provided';412 awsInvokeLocal.options.functionObj.handler = 'handler.foobar';413 await awsInvokeLocal.invokeLocal();414 expect(invokeLocalDockerStub.calledOnce).to.be.equal(true);415 expect(invokeLocalDockerStub.calledWithExactly()).to.be.equal(true);416 });417 it('should call invokeLocalDocker if using --docker option with nodejs12.x', async () => {418 awsInvokeLocal.options.functionObj.runtime = 'nodejs12.x';419 awsInvokeLocal.options.functionObj.handler = 'handler.foobar';420 awsInvokeLocal.options.docker = true;421 await awsInvokeLocal.invokeLocal();422 expect(invokeLocalDockerStub.calledOnce).to.be.equal(true);423 expect(invokeLocalDockerStub.calledWithExactly()).to.be.equal(true);424 });425 });426 describe('#callJavaBridge()', () => {427 let invokeLocalSpawnStubbed;428 beforeEach(() => {429 AwsInvokeLocal = proxyquire('../../../../../../lib/plugins/aws/invoke-local/index', {430 'get-stdin': stdinStub,431 'child-process-ext/spawn': spawnExtStub,432 'child_process': {433 spawn: spawnStub,434 },435 });436 invokeLocalSpawnStubbed = new AwsInvokeLocal(serverless, {437 stage: 'dev',438 function: 'first',439 functionObj: {440 handler: 'handler.hello',441 name: 'hello',442 timeout: 4,443 },444 data: {},445 });446 });447 it('spawns java process with correct arguments', async () => {448 await invokeLocalSpawnStubbed.callJavaBridge(449 tmpServicePath,450 'com.serverless.Handler',451 'handleRequest',452 '{}'453 );454 expect(writeChildStub.calledOnce).to.be.equal(true);455 expect(endChildStub.calledOnce).to.be.equal(true);456 expect(writeChildStub.calledWithExactly('{}')).to.be.equal(true);457 });458 });459 describe('#invokeLocalJava()', () => {460 let callJavaBridgeStub;461 let bridgePath;462 beforeEach(async () => {463 const wrapperPath = await awsInvokeLocal.resolveRuntimeWrapperPath('java/target');464 bridgePath = wrapperPath;465 fse.mkdirsSync(bridgePath);466 callJavaBridgeStub = sinon.stub(awsInvokeLocal, 'callJavaBridge').resolves();467 awsInvokeLocal.provider.options.stage = 'dev';468 awsInvokeLocal.options = {469 function: 'first',470 functionObj: {471 handler: 'handler.hello',472 name: 'hello',473 timeout: 4,474 },475 data: {},476 };477 });478 afterEach(() => {479 awsInvokeLocal.callJavaBridge.restore();480 fse.removeSync(bridgePath);481 });482 it('should invoke callJavaBridge when bridge is built', async () => {483 await awsInvokeLocal.invokeLocalJava(484 'java',485 'com.serverless.Handler',486 'handleRequest',487 tmpServicePath,488 {}489 );490 expect(callJavaBridgeStub.calledOnce).to.be.equal(true);491 expect(492 callJavaBridgeStub.calledWithExactly(493 tmpServicePath,494 'com.serverless.Handler',495 'handleRequest',496 JSON.stringify({497 event: {},498 context: {499 name: 'hello',500 version: 'LATEST',501 logGroupName: '/aws/lambda/hello',502 timeout: 4,503 },504 })505 )506 ).to.be.equal(true);507 });508 describe('when attempting to build the Java bridge', () => {509 it("if it's not present yet", async () => {510 await awsInvokeLocal.invokeLocalJava(511 'java',512 'com.serverless.Handler',513 'handleRequest',514 tmpServicePath,515 {}516 );517 expect(callJavaBridgeStub.calledOnce).to.be.equal(true);518 expect(519 callJavaBridgeStub.calledWithExactly(520 tmpServicePath,521 'com.serverless.Handler',522 'handleRequest',523 JSON.stringify({524 event: {},525 context: {526 name: 'hello',527 version: 'LATEST',528 logGroupName: '/aws/lambda/hello',529 timeout: 4,530 },531 })532 )533 ).to.be.equal(true);534 });535 });536 });537 describe('#invokeLocalDocker()', () => {538 let pluginMangerSpawnStub;539 let pluginMangerSpawnPackageStub;540 beforeEach(() => {541 awsInvokeLocal.provider.options.stage = 'dev';542 awsInvokeLocal.options = {543 'stage': 'dev',544 'function': 'first',545 'functionObj': {546 handler: 'handler.hello',547 name: 'hello',548 timeout: 4,549 runtime: 'nodejs12.x',550 environment: {551 functionVar: 'functionValue',552 },553 },554 'data': {},555 'env': 'commandLineEnvVar=commandLineEnvVarValue',556 'docker-arg': '-p 9292:9292',557 };558 serverless.service.provider.environment = {559 providerVar: 'providerValue',560 };561 pluginMangerSpawnStub = sinon.stub(serverless.pluginManager, 'spawn');562 pluginMangerSpawnPackageStub = pluginMangerSpawnStub.withArgs('package').resolves();563 });564 afterEach(() => {565 serverless.pluginManager.spawn.restore();566 fse.removeSync('.serverless');567 });568 it('calls docker with packaged artifact', async () => {569 await awsInvokeLocal.invokeLocalDocker();570 expect(pluginMangerSpawnPackageStub.calledOnce).to.equal(true);571 expect(spawnExtStub.getCall(0).args).to.deep.equal(['docker', ['version']]);572 expect(spawnExtStub.getCall(1).args).to.deep.equal([573 'docker',574 ['images', '-q', 'lambci/lambda:nodejs12.x'],575 ]);576 expect(spawnExtStub.getCall(3).args).to.deep.equal([577 'docker',578 [579 'run',580 '--rm',581 '-v',582 'servicePath:/var/task:ro,delegated',583 '--env',584 'AWS_REGION=us-east-1',585 '--env',586 'AWS_DEFAULT_REGION=us-east-1',587 '--env',588 'AWS_LAMBDA_LOG_GROUP_NAME=/aws/lambda/hello',589 '--env',590 'AWS_LAMBDA_FUNCTION_NAME=hello',591 '--env',592 'AWS_LAMBDA_FUNCTION_MEMORY_SIZE=1024',593 '--env',594 'AWS_ACCESS_KEY_ID=foo',595 '--env',596 'AWS_SECRET_ACCESS_KEY=bar',597 '--env',598 'providerVar=providerValue',599 '--env',600 'functionVar=functionValue',601 '--env',602 'commandLineEnvVar=commandLineEnvVarValue',603 '-p',604 '9292:9292',605 'sls-docker-nodejs12.x',606 'handler.hello',607 '{}',608 ],609 ]);610 });611 });612 describe('#getEnvVarsFromOptions', () => {613 it('returns empty object when env option is not set', () => {614 delete awsInvokeLocal.options.env;615 const envVarsFromOptions = awsInvokeLocal.getEnvVarsFromOptions();616 expect(envVarsFromOptions).to.be.eql({});617 });618 it('returns empty object when env option empty', () => {619 awsInvokeLocal.options.env = '';620 const envVarsFromOptions = awsInvokeLocal.getEnvVarsFromOptions();621 expect(envVarsFromOptions).to.be.eql({});622 });623 it('returns key value for option separated by =', () => {624 awsInvokeLocal.options.env = 'SOME_ENV_VAR=some-value';625 const envVarsFromOptions = awsInvokeLocal.getEnvVarsFromOptions();626 expect(envVarsFromOptions).to.be.eql({ SOME_ENV_VAR: 'some-value' });627 });628 it('returns key with empty value for option without =', () => {629 awsInvokeLocal.options.env = 'SOME_ENV_VAR';630 const envVarsFromOptions = awsInvokeLocal.getEnvVarsFromOptions();631 expect(envVarsFromOptions).to.be.eql({ SOME_ENV_VAR: '' });632 });633 it('returns key with single value for option multiple =s', () => {634 awsInvokeLocal.options.env = 'SOME_ENV_VAR=value1=value2';635 const envVarsFromOptions = awsInvokeLocal.getEnvVarsFromOptions();636 expect(envVarsFromOptions).to.be.eql({ SOME_ENV_VAR: 'value1=value2' });637 });638 });639 describe('#getDockerArgsFromOptions', () => {640 it('returns empty list when docker-arg option is absent', () => {641 delete awsInvokeLocal.options['docker-arg'];642 const dockerArgsFromOptions = awsInvokeLocal.getDockerArgsFromOptions();643 expect(dockerArgsFromOptions).to.eql([]);644 });645 it('returns arg split by space when single docker-arg option is present', () => {646 awsInvokeLocal.options['docker-arg'] = '-p 9229:9229';647 const dockerArgsFromOptions = awsInvokeLocal.getDockerArgsFromOptions();648 expect(dockerArgsFromOptions).to.eql(['-p', '9229:9229']);649 });650 it('returns args split by space when multiple docker-arg options are present', () => {651 awsInvokeLocal.options['docker-arg'] = ['-p 9229:9229', '-v /var/logs:/host-var-logs'];652 const dockerArgsFromOptions = awsInvokeLocal.getDockerArgsFromOptions();653 expect(dockerArgsFromOptions).to.eql(['-p', '9229:9229', '-v', '/var/logs:/host-var-logs']);654 });655 it('returns arg split only by first space when docker-arg option has multiple space', () => {656 awsInvokeLocal.options['docker-arg'] = '-v /My Docs:/docs';657 const dockerArgsFromOptions = awsInvokeLocal.getDockerArgsFromOptions();658 expect(dockerArgsFromOptions).to.eql(['-v', '/My Docs:/docs']);659 });660 });661});662describe('test/unit/lib/plugins/aws/invokeLocal/index.test.js', () => {663 const testRuntime = (functionName, options = {}) => {664 describe.skip('Input resolution', () => {665 // All tested with individual runServerless run666 it('TODO: should accept no data', async () => {667 // Confirm outcome on { stdout }668 await runServerless({669 fixture: 'invocation',670 command: 'invoke local',671 options: {672 ...options,673 function: functionName,674 },675 });676 // Replaces677 // https://github.com/serverless/serverless/blob/95c0bc09421b869ae1d8fc5dea42a2fce1c2023e/test/unit/lib/plugins/aws/invokeLocal/index.test.js#L149-L154678 // https://github.com/serverless/serverless/blob/95c0bc09421b869ae1d8fc5dea42a2fce1c2023e/test/unit/lib/plugins/aws/invokeLocal/index.test.js#L476-L482679 // https://github.com/serverless/serverless/blob/95c0bc09421b869ae1d8fc5dea42a2fce1c2023e/test/unit/lib/plugins/aws/invokeLocal/index.test.js#L489-L498680 // https://github.com/serverless/serverless/blob/95c0bc09421b869ae1d8fc5dea42a2fce1c2023e/test/unit/lib/plugins/aws/invokeLocal/index.test.js#L511-L547681 // https://github.com/serverless/serverless/blob/95c0bc09421b869ae1d8fc5dea42a2fce1c2023e/test/unit/lib/plugins/aws/invokeLocal/index.test.js#L567-L582682 // https://github.com/serverless/serverless/blob/95c0bc09421b869ae1d8fc5dea42a2fce1c2023e/test/unit/lib/plugins/aws/invokeLocal/index.test.js#L627-L637683 // https://github.com/serverless/serverless/blob/95c0bc09421b869ae1d8fc5dea42a2fce1c2023e/test/unit/lib/plugins/aws/invokeLocal/index.test.js#L671-L680684 // https://github.com/serverless/serverless/blob/95c0bc09421b869ae1d8fc5dea42a2fce1c2023e/test/unit/lib/plugins/aws/invokeLocal/index.test.js#L1076-L1086685 // https://github.com/serverless/serverless/blob/95c0bc09421b869ae1d8fc5dea42a2fce1c2023e/test/unit/lib/plugins/aws/invokeLocal/index.test.js#L1116-L1173686 // https://github.com/serverless/serverless/blob/95c0bc09421b869ae1d8fc5dea42a2fce1c2023e/test/unit/lib/plugins/aws/invokeLocal/index.test.js#L1208-L1256687 // https://github.com/serverless/serverless/blob/95c0bc09421b869ae1d8fc5dea42a2fce1c2023e/test/unit/lib/plugins/aws/invokeLocal/index.test.js#L1301-L1334688 });689 it('TODO: should should support plain string data', async () => {690 // Confirm outcome on { stdout }691 await runServerless({692 fixture: 'invocation',693 command: 'invoke local',694 options: {695 ...options,696 function: functionName,697 data: 'inputData',698 },699 });700 // Replaces701 // https://github.com/serverless/serverless/blob/95c0bc09421b869ae1d8fc5dea42a2fce1c2023e/test/unit/lib/plugins/aws/invokeLocal/index.test.js#L161-L166702 });703 describe('Automated JSON parsing', () => {704 before(async () => {705 // Confirm outcome on { stdout }706 await runServerless({707 fixture: 'invocation',708 command: 'invoke local',709 options: {710 ...options,711 function: functionName,712 data: '{"inputKey":"inputValue"}',713 },714 });715 });716 it('TODO: should support JSON string data', () => {717 // Replaces718 // https://github.com/serverless/serverless/blob/95c0bc09421b869ae1d8fc5dea42a2fce1c2023e/test/unit/lib/plugins/aws/invokeLocal/index.test.js#L168-L173719 });720 it('TODO: should support JSON string client context', () => {721 // Replaces722 // https://github.com/serverless/serverless/blob/95c0bc09421b869ae1d8fc5dea42a2fce1c2023e/test/unit/lib/plugins/aws/invokeLocal/index.test.js#L183-L188723 // https://github.com/serverless/serverless/blob/95c0bc09421b869ae1d8fc5dea42a2fce1c2023e/test/unit/lib/plugins/aws/invokeLocal/index.test.js#L502-L509724 });725 });726 describe('"--raw" option', () => {727 before(async () => {728 // Confirm outcome on { stdout }729 await runServerless({730 fixture: 'invocation',731 command: 'invoke local',732 options: {733 ...options,734 function: functionName,735 data: '{"inputKey":"inputValue"}',736 raw: true,737 },738 });739 });740 it('TODO: should should not attempt to parse data with raw option', () => {741 // Replaces742 // https://github.com/serverless/serverless/blob/95c0bc09421b869ae1d8fc5dea42a2fce1c2023e/test/unit/lib/plugins/aws/invokeLocal/index.test.js#L175-L181743 });744 it('TODO: should should not attempt to parse client context with raw option', () => {745 // Replaces746 // https://github.com/serverless/serverless/blob/95c0bc09421b869ae1d8fc5dea42a2fce1c2023e/test/unit/lib/plugins/aws/invokeLocal/index.test.js#L190-L196747 });748 });749 describe('JSON file input', () => {750 before(async () => {751 // Confirm outcome on { stdout }752 await runServerless({753 fixture: 'invocation',754 command: 'invoke local',755 options: {756 ...options,757 function: functionName,758 path: 'payload.json',759 },760 });761 });762 // Single runServerless run763 it('TODO: should support JSON file path as data', () => {764 // Replaces765 // https://github.com/serverless/serverless/blob/95c0bc09421b869ae1d8fc5dea42a2fce1c2023e/test/unit/lib/plugins/aws/invokeLocal/index.test.js#L198-L211766 });767 it('TODO: should support JSON file path as client context', () => {});768 });769 it('TODO: should support YAML file path as data', async () => {770 await runServerless({771 fixture: 'invocation',772 command: 'invoke local',773 options: {774 ...options,775 function: functionName,776 path: 'payload.yaml',777 },778 });779 // Replaces780 // https://github.com/serverless/serverless/blob/95c0bc09421b869ae1d8fc5dea42a2fce1c2023e/test/unit/lib/plugins/aws/invokeLocal/index.test.js#L229-L241781 });782 it('TODO: should support JS file path for data', async () => {783 await runServerless({784 fixture: 'invocation',785 command: 'invoke local',786 options: {787 ...options,788 function: functionName,789 path: 'payload.js',790 },791 });792 // Replaces793 // https://github.com/serverless/serverless/blob/95c0bc09421b869ae1d8fc5dea42a2fce1c2023e/test/unit/lib/plugins/aws/invokeLocal/index.test.js#L243-L263794 });795 it('TODO: should support absolute file path as data', async () => {796 await runServerless({797 fixture: 'invocation',798 command: 'invoke local',799 options: {800 ...options,801 function: functionName,802 path: '' /* TODO: Pass absolute path to payload.json in fixture */,803 },804 });805 // Replaces806 // https://github.com/serverless/serverless/blob/95c0bc09421b869ae1d8fc5dea42a2fce1c2023e/test/unit/lib/plugins/aws/invokeLocal/index.test.js#L213-L227807 });808 it('TODO: should throw error if data file path does not exist', async () => {809 await expect(810 runServerless({811 fixture: 'invocation',812 command: 'invoke local',813 options: {814 ...options,815 function: functionName,816 path: 'not-existing.yaml',817 },818 })819 ).to.eventually.be.rejected.and.have.property('code', 'TODO');820 // Replaces821 // https://github.com/serverless/serverless/blob/95c0bc09421b869ae1d8fc5dea42a2fce1c2023e/test/unit/lib/plugins/aws/invokeLocal/index.test.js#L270-L275822 });823 it('TODO: should throw error if function does not exist', async () => {824 await expect(825 runServerless({826 fixture: 'invocation',827 command: 'invoke local',828 options: {829 ...options,830 function: 'notExisting',831 },832 })833 ).to.eventually.be.rejected.and.have.property('code', 'TODO');834 // Replaces835 // https://github.com/serverless/serverless/blob/95c0bc09421b869ae1d8fc5dea42a2fce1c2023e/test/unit/lib/plugins/aws/invokeLocal/index.test.js#L156-L159836 });837 });838 describe('Environment variables', () => {839 let responseBody;840 before(async () => {841 process.env.AWS_ACCESS_KEY_ID = 'AAKIXXX';842 process.env.AWS_SECRET_ACCESS_KEY = 'ASAKXXX';843 // Confirm outcome on { output }844 const response = await runServerless({845 fixture: 'invocation',846 command: 'invoke local',847 options: {848 ...options,849 function: functionName,850 env: 'PARAM_ENV_VAR=-Dblart=snort',851 },852 configExt: {853 provider: {854 runtime: 'nodejs14.x',855 environment: {856 PROVIDER_LEVEL_VAR: 'PROVIDER_LEVEL_VAR_VALUE',857 NULL_VAR: null,858 },859 region: 'us-east-2',860 },861 functions: {862 fn: {863 environment: {864 FUNCTION_LEVEL_VAR: 'FUNCTION_LEVEL_VAR_VALUE',865 },866 },867 },868 },869 });870 const outputAsJson = (() => {871 try {872 return JSON.parse(response.output);873 } catch (error) {874 log.error('Unexpected response output: %s', response.output);875 throw error;876 }877 })();878 responseBody = JSON.parse(outputAsJson.body);879 });880 after(() => {881 delete process.env.AWS_ACCESS_KEY_ID;882 delete process.env.AWS_SECRET_ACCESS_KEY;883 });884 xit('TODO: should expose eventual AWS credentials in environment variables', () => {885 // Replaces886 // https://github.com/serverless/serverless/blob/95c0bc09421b869ae1d8fc5dea42a2fce1c2023e/test/unit/lib/plugins/aws/invokeLocal/index.test.js#L284-L327887 // https://github.com/serverless/serverless/blob/95c0bc09421b869ae1d8fc5dea42a2fce1c2023e/test/unit/lib/plugins/aws/invokeLocal/index.test.js#L390-L402888 // https://github.com/serverless/serverless/blob/95c0bc09421b869ae1d8fc5dea42a2fce1c2023e/test/unit/lib/plugins/aws/invokeLocal/index.test.js#L404-L415889 // https://github.com/serverless/serverless/blob/95c0bc09421b869ae1d8fc5dea42a2fce1c2023e/test/unit/lib/plugins/aws/invokeLocal/index.test.js#L417-L424890 });891 xit('TODO: should expose `provider.env` in environment variables', () => {892 // Replaces893 // https://github.com/serverless/serverless/blob/95c0bc09421b869ae1d8fc5dea42a2fce1c2023e/test/unit/lib/plugins/aws/invokeLocal/index.test.js#L354-L357894 });895 xit('TODO: should expose `provider.profile` in environment variables', () => {896 // Replaces897 // https://github.com/serverless/serverless/blob/95c0bc09421b869ae1d8fc5dea42a2fce1c2023e/test/unit/lib/plugins/aws/invokeLocal/index.test.js#L359-L363898 });899 xit('TODO: should expose `functions[].env` in environment variables', () => {900 // Replaces901 // https://github.com/serverless/serverless/blob/95c0bc09421b869ae1d8fc5dea42a2fce1c2023e/test/unit/lib/plugins/aws/invokeLocal/index.test.js#L365-L368902 });903 it('should expose `--env` vars in environment variables', async () =>904 expect(responseBody.env.PARAM_ENV_VAR).to.equal('-Dblart=snort'));905 xit('TODO: should expose default lambda environment variables', () => {906 // Replaces907 // https://github.com/serverless/serverless/blob/95c0bc09421b869ae1d8fc5dea42a2fce1c2023e/test/unit/lib/plugins/aws/invokeLocal/index.test.js#L370-L388908 });909 xit('TODO: should resolve region from `service.provider` if not provided via option', () => {910 // Replaces911 // https://github.com/serverless/serverless/blob/95c0bc09421b869ae1d8fc5dea42a2fce1c2023e/test/unit/lib/plugins/aws/invokeLocal/index.test.js#L426-L441912 });913 it('should not expose null environment variables', async () =>914 expect(responseBody.env).to.not.have.property('NULL_VAR'));915 });916 };917 describe('Node.js', () => {918 testRuntime('callback');919 it('should support success resolution via async function', async () => {920 const { output } = await runServerless({921 fixture: 'invocation',922 command: 'invoke local',923 options: { function: 'async' },924 });925 expect(output).to.include('Invoked');926 });927 it('should support success resolution via context.done', async () => {928 const { output } = await runServerless({929 fixture: 'invocation',930 command: 'invoke local',931 options: { function: 'contextDone' },932 });933 expect(output).to.include('Invoked');934 });935 it('should support success resolution via context.succeed', async () => {936 const { output } = await runServerless({937 fixture: 'invocation',938 command: 'invoke local',939 options: { function: 'contextSucceed' },940 });941 expect(output).to.include('Invoked');942 });943 it('should support immediate failure at initialization', async () => {944 await expect(945 runServerless({946 fixture: 'invocation',947 command: 'invoke local',948 options: { function: 'initFail' },949 })950 ).to.eventually.be.rejected.and.have.property(951 'code',952 'INVOKE_LOCAL_LAMBDA_INITIALIZATION_FAILED'953 );954 });955 it('should support immediate failure at invocation', async () => {956 await expect(957 runServerless({958 fixture: 'invocation',959 command: 'invoke local',960 options: { function: 'invocationFail' },961 })962 ).to.eventually.be.rejectedWith('Invocation fail');963 });964 it('should support failure resolution via async function', async () => {965 const { output } = await runServerless({966 fixture: 'invocation',967 command: 'invoke local',968 options: { function: 'async', data: '{"shouldFail":true}' },969 });970 expect(output).to.include('Failed on request');971 });972 it('should support failure resolution via callback', async () => {973 const { output } = await runServerless({974 fixture: 'invocation',975 command: 'invoke local',976 options: { function: 'callback', data: '{"shouldFail":true}' },977 });978 expect(output).to.include('Failed on request');979 });980 it('should support failure resolution via context.done', async () => {981 const { output } = await runServerless({982 fixture: 'invocation',983 command: 'invoke local',984 options: { function: 'contextDone', data: '{"shouldFail":true}' },985 });986 expect(output).to.include('Failed on request');987 });988 it('should support failure resolution via context.fail', async () => {989 const { output } = await runServerless({990 fixture: 'invocation',991 command: 'invoke local',992 options: { function: 'contextSucceed', data: '{"shouldFail":true}' },993 });994 expect(output).to.include('Failed on request');995 });996 it('should recognize first resolution', async () => {997 const { output: firstRunOutput } = await runServerless({998 fixture: 'invocation',999 command: 'invoke local',1000 options: { function: 'doubledResolutionCallbackFirst' },1001 });1002 const { output: secondRunOutput } = await runServerless({1003 fixture: 'invocation',1004 command: 'invoke local',1005 options: { function: 'doubledResolutionPromiseFirst' },1006 });1007 expect(firstRunOutput).to.include('callback');1008 expect(secondRunOutput).to.include('promise');1009 });1010 it('should support context.remainingTimeInMillis()', async () => {1011 const { output } = await runServerless({1012 fixture: 'invocation',1013 command: 'invoke local',1014 options: { function: 'remainingTime' },1015 });1016 const body = JSON.parse(output).body;1017 const [firstRemainingMs, secondRemainingMs, thirdRemainingMs] = JSON.parse(body).data;1018 expect(firstRemainingMs).to.be.lte(3000);1019 expect(secondRemainingMs).to.be.lte(2910);1020 expect(thirdRemainingMs).to.be.lte(secondRemainingMs);1021 });1022 });1023 describe('Python', () => {1024 before(async function () {1025 const executable = process.platform === 'win32' ? 'python.exe' : 'python';1026 try {1027 await spawnExt(executable, ['--version']);1028 } catch (err) {1029 skipWithNotice(this, 'Python runtime is not installed');1030 }1031 });1032 testRuntime('python');1033 describe('context.remainingTimeInMillis', () => {1034 it('should support context.get_remaining_time_in_millis()', async () => {1035 const { output } = await runServerless({1036 fixture: 'invocation',1037 command: 'invoke local',1038 options: { function: 'pythonRemainingTime' },1039 });1040 const { start, stop } = JSON.parse(output);1041 expect(start).to.lte(3000);1042 expect(stop).to.lte(2910);1043 });1044 });1045 });1046 describe('Ruby', () => {1047 before(async function () {1048 const executable = process.platform === 'win32' ? 'ruby.exe' : 'ruby';1049 try {1050 await spawnExt(executable, ['--version']);1051 } catch (err) {1052 skipWithNotice(this, 'Ruby runtime is not installed');1053 }1054 });1055 testRuntime('ruby');1056 it('should support class/module address in handler for "ruby*" runtime', async () => {1057 const { output } = await runServerless({1058 fixture: 'invocation',1059 command: 'invoke local',1060 options: { function: 'rubyClass' },1061 });1062 expect(output).to.include('rubyclass');1063 });1064 it('should support context.get_remaining_time_in_millis()', async () => {1065 const { output } = await runServerless({1066 fixture: 'invocation',1067 command: 'invoke local',1068 options: { function: 'rubyRemainingTime' },1069 });1070 const { start, stop } = JSON.parse(output);1071 expect(start).to.lte(6000);1072 expect(stop).to.lte(5910);1073 });1074 it('should support context.deadline_ms', async () => {1075 const { output } = await runServerless({1076 fixture: 'invocation',1077 command: 'invoke local',1078 options: { function: 'rubyDeadline' },1079 });1080 const { deadlineMs } = JSON.parse(output);1081 expect(deadlineMs).to.be.gt(Date.now());1082 });1083 });1084 describe.skip('Java', () => {1085 // If Java runtime is not installed, skip below tests by:1086 // - Invoke skip with notice as here;1087 // https://github.com/serverless/serverless/blob/2d6824cde531ba56758f441b39b5ab018702e866/lib/plugins/aws/invokeLocal/index.test.js#L1043-L10451088 // - Ensure all other tests are skipped1089 testRuntime('java'); // TODO: Configure java handler1090 });1091 describe.skip('Docker', () => {1092 // If Docker is not installed, skip below tests by:1093 // - Invoke skip with notice as here;1094 // https://github.com/serverless/serverless/blob/2d6824cde531ba56758f441b39b5ab018702e866/lib/plugins/aws/invokeLocal/index.test.js#L1043-L10451095 // - Ensure all other tests are skipped1096 testRuntime('callback', ['--docker']);1097 it('TODO: should support "provided" runtime in docker invocation', () => {});1098 });...

Full Screen

Full Screen

IgnoreEqualValuesProperty.spec.ts

Source:IgnoreEqualValuesProperty.spec.ts Github

copy

Full Screen

1import { IgnoreEqualValuesProperty } from '../../../../src/check/property/IgnoreEqualValuesProperty';2import { PreconditionFailure } from '../../../../src/check/precondition/PreconditionFailure';3import { fakeProperty } from './__test-helpers__/PropertyHelpers';4describe('IgnoreEqualValuesProperty', () => {5 it.each`6 skipRuns7 ${false}8 ${true}9 `('should not call run on the decorated property when property is run on the same value', ({ skipRuns }) => {10 // Arrange11 const { instance: decoratedProperty, run } = fakeProperty();12 // Act13 const property = new IgnoreEqualValuesProperty(decoratedProperty, skipRuns);14 property.run(1);15 property.run(1);16 // Assert17 expect(run).toHaveBeenCalledTimes(1);18 });19 it.each`20 originalValue | originalValuePretty | isAsync21 ${null /* success */} | ${'null'} | ${false}22 ${'error' /* failure */} | ${'"error"'} | ${false}23 ${new PreconditionFailure() /* skip */} | ${'new PreconditionFailure()'} | ${false}24 ${null /* success */} | ${'null'} | ${true}25 ${'error' /* failure */} | ${'"error"'} | ${true}26 ${new PreconditionFailure() /* skip */} | ${'new PreconditionFailure()'} | ${true}27 `(28 'should always return the cached value for skipRuns=false, originalValue=$originalValuePretty, isAsync=$isAsync',29 ({ originalValue, isAsync }) => {30 // Arrange31 // success -> success32 // failure -> failure33 // skip -> skip34 const { instance: decoratedProperty, run } = fakeProperty(isAsync);35 run.mockImplementation(() => (isAsync ? Promise.resolve(originalValue) : originalValue));36 // Act37 const property = new IgnoreEqualValuesProperty(decoratedProperty, false);38 const initialRunOutput = property.run(null);39 const secondRunOutput = property.run(null);40 // Assert41 expect(secondRunOutput).toBe(initialRunOutput);42 }43 );44 it.each`45 originalValue | originalValuePretty | isAsync46 ${null /* success */} | ${'null'} | ${false}47 ${'error' /* failure */} | ${'"error"'} | ${false}48 ${new PreconditionFailure() /* skip */} | ${'new PreconditionFailure()'} | ${false}49 ${null /* success */} | ${'null'} | ${true}50 ${'error' /* failure */} | ${'"error"'} | ${true}51 ${new PreconditionFailure() /* skip */} | ${'new PreconditionFailure()'} | ${true}52 `(53 'should return the cached value but skip success for skipRuns=true, originalValue=$originalValuePretty, isAsync=$isAsync',54 async ({ originalValue, isAsync }) => {55 // Arrange56 // success -> skip57 // failure -> failure58 // skip -> skip59 const { instance: decoratedProperty, run } = fakeProperty(isAsync);60 run.mockImplementation(() => (isAsync ? Promise.resolve(originalValue) : originalValue));61 // Act62 const property = new IgnoreEqualValuesProperty(decoratedProperty, true);63 const initialRunOutput = await property.run(null);64 const secondRunOutput = await property.run(null);65 // Assert66 if (initialRunOutput === null) {67 // success68 expect(secondRunOutput).not.toBe(initialRunOutput);69 expect(PreconditionFailure.isFailure(secondRunOutput)).toBe(true);70 } else {71 // failure or skip72 expect(secondRunOutput).toBe(initialRunOutput);73 }74 }75 );76 it.each`77 skipRuns78 ${false}79 ${true}80 `('should run decorated property when property is run on another value', ({ skipRuns }) => {81 // Arrange82 const { instance: decoratedProperty, run } = fakeProperty();83 // Act84 const property = new IgnoreEqualValuesProperty(decoratedProperty, skipRuns);85 property.run(1);86 property.run(2);87 // Assert88 expect(run).toHaveBeenCalledTimes(2);89 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const fc = require('fast-check');2const { secondRunOutput } = require('fast-check-monorepo');3fc.assert(4 fc.property(fc.integer(), fc.integer(), (a, b) => {5 return a + b === b + a;6 }),7 { verbose: true, numRuns: 1000, seed: 42 }8);9secondRunOutput(fc, { verbose: true, numRuns: 1000, seed: 42 });

Full Screen

Using AI Code Generation

copy

Full Screen

1const { secondRunOutput } = require('fast-check-monorepo');2secondRunOutput();3{4 "devDependencies": {5 }6}

Full Screen

Using AI Code Generation

copy

Full Screen

1const { secondRunOutput } = require('fast-check-monorepo');2secondRunOutput();3const { thirdRunOutput } = require('fast-check-monorepo');4thirdRunOutput();5const { fourthRunOutput } = require('fast-check-monorepo');6fourthRunOutput();7const { fifthRunOutput } = require('fast-check-monorepo');8fifthRunOutput();9const { sixthRunOutput } = require('fast-check-monorepo');10sixthRunOutput();11const { seventhRunOutput } = require('fast-check-monorepo');12seventhRunOutput();13const { eighthRunOutput } = require('fast-check-monorepo');14eighthRunOutput();15const { ninthRunOutput } = require('fast-check-monorepo');16ninthRunOutput();17const { tenthRunOutput } = require('fast-check-monorepo');18tenthRunOutput();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { secondRunOutput } = require('fast-check-monorepo')2const fc = require('fast-check')3const gen = fc.array(fc.record({ a: fc.nat() }), 1, 3)4const p = (a) => a.length === 25fc.assert(fc.property(gen, p), { seed: 42, examples: 1, verbose: true })6secondRunOutput()7{8 "scripts": {9 },10 "dependencies": {11 }12}

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 fast-check-monorepo 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