From b2626e5fda9089e2ea98122479bdc916e2cdd2ed Mon Sep 17 00:00:00 2001 From: Frank Schmid Date: Sun, 30 Jul 2017 17:36:40 +0200 Subject: [PATCH] Fixed unit tests --- tests/run.test.js | 89 ------------------------------------------ tests/validate.test.js | 6 +-- 2 files changed, 3 insertions(+), 92 deletions(-) diff --git a/tests/run.test.js b/tests/run.test.js index efd0ec5fa9..e443e1fa70 100644 --- a/tests/run.test.js +++ b/tests/run.test.js @@ -57,95 +57,6 @@ describe('run', () => { sandbox.restore(); }); - describe('utils', () => { - it('should expose utils methods', () => { - expect(module.loadHandler).to.be.a('function'); - expect(module.getEvent).to.be.a('function'); - expect(module.getContext).to.be.a('function'); - }); - - describe('loadHandler', () => { - const testFunctionId = 'testFunctionId'; - const testHandlerModuleName = 'testHandlerModule'; - const testHandlerFunctionName = 'testHandlerFunction'; - const testFunctionsConfig = { - [testFunctionId]: { - handler: `${testHandlerModuleName}.${testHandlerFunctionName}`, - } - }; - const testPath = '/testpath'; - const testFilename = `${testHandlerModuleName}.js`; - const testModuleFileName = `${testPath}/${testFilename}`; - const testStats = { - compilation: { - options: { - output: { - path: testPath, - filename: testFilename, - }, - }, - }, - }; - const testHandlerFunction = sinon.spy(); - const testModule = { - [testHandlerFunctionName]: testHandlerFunction, - }; - - before(() => { - mockery.registerMock(testModuleFileName, testModule); - }); - - after(() => { - mockery.deregisterMock(testModuleFileName); - }); - - beforeEach(() => { - serverless.service.functions = testFunctionsConfig; - }); - - it('should require the handler module', () => { - const res = module.loadHandler(testStats, testFunctionId); - expect(res).to.equal(testHandlerFunction); - expect(utilsMock.purgeCache).to.have.not.been.called; - }); - - it('should purge the modules cache if required', () => { - const res = module.loadHandler(testStats, testFunctionId, true); - expect(utilsMock.purgeCache).to.have.been.calledWith(testModuleFileName); - }); - }); - - it('should return a default event with `getEvent` and no option path', () => { - module.options.path = null; - const res = module.getEvent(); - expect(res).to.equal(null); - }); - - it('should load an event object from disk with `getEvent`', () => { - const testPath = 'testPath'; - module.options.path = testPath; - const testExampleObject = {}; - module.serverless.utils.readFileSync = sinon.stub().returns(testExampleObject); - const res = module.getEvent(); - expect(res).to.equal(testExampleObject); - }); - - it('should return an context object with `getContext`', () => { - const testFunctionName = 'testFunctionName'; - const res = module.getContext(testFunctionName); - expect(res).to.eql({ - awsRequestId: 'testguid', - functionName: testFunctionName, - functionVersion: '$LATEST', - invokeid: 'testguid', - isDefaultFunctionVersion: true, - logGroupName: `/aws/lambda/${testFunctionName}`, - logStreamName: '2016/02/14/[HEAD]13370a84ca4ed8b77c427af260', - memoryLimitInMB: '1024', - }); - }); - }); - describe('watch', () => { let spawnStub; diff --git a/tests/validate.test.js b/tests/validate.test.js index 62555c6fc2..20184ddb6e 100644 --- a/tests/validate.test.js +++ b/tests/validate.test.js @@ -142,7 +142,7 @@ describe('validate', () => { expect(module.webpackConfig.output).to.eql({ libraryTarget: 'commonjs', path: `${testServicePath}/.webpack`, - filename: testEntry, + filename: '[name].js', }); }); }); @@ -161,7 +161,7 @@ describe('validate', () => { expect(module.webpackConfig.output).to.eql({ libraryTarget: 'commonjs', path: `${testServicePath}/.webpack`, - filename: 'last', + filename: '[name].js', }); }); }); @@ -177,7 +177,7 @@ describe('validate', () => { expect(module.webpackConfig.output).to.eql({ libraryTarget: 'commonjs', path: `${testServicePath}/.webpack`, - filename: 'handler.js', + filename: '[name].js', }); }); });