Skip to content

Commit

Permalink
Fixed unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Frank Schmid committed Jul 30, 2017
1 parent 0617fdc commit b2626e5
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 92 deletions.
89 changes: 0 additions & 89 deletions tests/run.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
6 changes: 3 additions & 3 deletions tests/validate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ describe('validate', () => {
expect(module.webpackConfig.output).to.eql({
libraryTarget: 'commonjs',
path: `${testServicePath}/.webpack`,
filename: testEntry,
filename: '[name].js',
});
});
});
Expand All @@ -161,7 +161,7 @@ describe('validate', () => {
expect(module.webpackConfig.output).to.eql({
libraryTarget: 'commonjs',
path: `${testServicePath}/.webpack`,
filename: 'last',
filename: '[name].js',
});
});
});
Expand All @@ -177,7 +177,7 @@ describe('validate', () => {
expect(module.webpackConfig.output).to.eql({
libraryTarget: 'commonjs',
path: `${testServicePath}/.webpack`,
filename: 'handler.js',
filename: '[name].js',
});
});
});
Expand Down

0 comments on commit b2626e5

Please # to comment.