Skip to content

Commit

Permalink
Merge pull request #188 from elastic-coders/fix-windows-unittests
Browse files Browse the repository at this point in the history
Use path where needed to make unit tests on Windows pass.
  • Loading branch information
HyperBrain authored Aug 10, 2017
2 parents dad3a9b + 6575b36 commit c838a31
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 16 deletions.
4 changes: 2 additions & 2 deletions tests/packExternalModules.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ describe('packExternalModules', () => {
sandbox.restore();
});

describe('packageModules()', () => {
describe('packExternalModules()', () => {
it('should do nothing if webpackIncludeModules is not set', () => {
_.unset(serverless, 'service.custom.webpackIncludeModules');
return expect(module.packExternalModules({ stats: [] })).to.eventually.deep.equal({ stats: [] })
Expand Down Expand Up @@ -154,7 +154,7 @@ describe('packExternalModules', () => {
'bluebird@^3.4.0'
],
{
cwd: 'outputPath/dependencies',
cwd: path.join('outputPath', 'dependencies'),
maxBuffer: 204800,
save: true
}),
Expand Down
21 changes: 13 additions & 8 deletions tests/packageModules.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const BbPromise = require('bluebird');
const _ = require('lodash');
const chai = require('chai');
const path = require('path');
const sinon = require('sinon');
const mockery = require('mockery');
const Serverless = require('serverless');
Expand Down Expand Up @@ -134,10 +135,12 @@ describe('packageModules', () => {
fsMock._streamMock.on.withArgs('close').yields();
fsMock._statMock.isDirectory.returns(false);

const expectedArtifactPath = path.join('.serverless', 'test-service.zip');

return expect(module.packageModules(stats)).to.be.fulfilled
.then(() => BbPromise.all([
expect(func1).to.have.a.nested.property('package.artifact').that.equals('.serverless/test-service.zip'),
expect(func2).to.have.a.nested.property('package.artifact').that.equals('.serverless/test-service.zip'),
expect(func1).to.have.a.nested.property('package.artifact').that.equals(expectedArtifactPath),
expect(func2).to.have.a.nested.property('package.artifact').that.equals(expectedArtifactPath),
]));
});

Expand Down Expand Up @@ -205,8 +208,8 @@ describe('packageModules', () => {

return expect(module.packageModules(stats)).to.be.fulfilled
.then(() => BbPromise.all([
expect(func1).to.have.a.nested.property('package.artifact').that.equals('.serverless/func1.zip'),
expect(func2).to.have.a.nested.property('package.artifact').that.equals('.serverless/func2.zip'),
expect(func1).to.have.a.nested.property('package.artifact').that.equals(path.join('.serverless', 'func1.zip')),
expect(func2).to.have.a.nested.property('package.artifact').that.equals(path.join('.serverless', 'func2.zip')),
]));
});

Expand Down Expand Up @@ -252,20 +255,22 @@ describe('packageModules', () => {
fsMock._streamMock.on.withArgs('close').yields();
fsMock._statMock.isDirectory.returns(false);

const expectedArtifactPath = path.join('.serverless', 'test-service.zip');

return BbPromise.each([ '1.18.1', '2.17.0', '10.15.3', ], version => {
getVersionStub.returns(version);
return expect(module.packageModules(stats)).to.be.fulfilled
.then(() => BbPromise.all([
expect(func1).to.have.a.nested.property('package.artifact').that.equals('.serverless/test-service.zip'),
expect(func2).to.have.a.nested.property('package.artifact').that.equals('.serverless/test-service.zip'),
expect(func1).to.have.a.nested.property('package.artifact').that.equals(expectedArtifactPath),
expect(func2).to.have.a.nested.property('package.artifact').that.equals(expectedArtifactPath),
]));
})
.then(() => BbPromise.each([ '1.17.0', '1.16.0-alpha', '1.15.3', ], version => {
getVersionStub.returns(version);
return expect(module.packageModules(stats)).to.be.fulfilled
.then(() => BbPromise.all([
expect(func1).to.have.a.nested.property('artifact').that.equals('.serverless/test-service.zip'),
expect(func2).to.have.a.nested.property('artifact').that.equals('.serverless/test-service.zip'),
expect(func1).to.have.a.nested.property('artifact').that.equals(expectedArtifactPath),
expect(func2).to.have.a.nested.property('artifact').that.equals(expectedArtifactPath),
]));
}));
});
Expand Down
13 changes: 7 additions & 6 deletions tests/validate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const _ = require('lodash');
const chai = require('chai');
const sinon = require('sinon');
const mockery = require('mockery');
const path = require('path');
const Serverless = require('serverless');
const makeFsExtraMock = require('./fs-extra.mock');

Expand Down Expand Up @@ -104,7 +105,7 @@ describe('validate', () => {
return module
.validate()
.then(() => expect(module.webpackConfig.output).to.eql({
path: `${testServicePath}/${testOptionsOut}/service`,
path: path.join(testServicePath, testOptionsOut, 'service'),
filename: 'filename',
}));
});
Expand Down Expand Up @@ -135,7 +136,7 @@ describe('validate', () => {
.validate()
.then(() => expect(module.webpackConfig.output).to.eql({
libraryTarget: 'commonjs',
path: `${testServicePath}/.webpack/service`,
path: path.join(testServicePath, '.webpack', 'service'),
filename: '[name].js',
}));
});
Expand All @@ -152,7 +153,7 @@ describe('validate', () => {
.validate()
.then(() => expect(module.webpackConfig.output).to.eql({
libraryTarget: 'commonjs',
path: `${testServicePath}/.webpack/service`,
path: path.join(testServicePath, '.webpack', 'service'),
filename: '[name].js',
}));
});
Expand All @@ -166,7 +167,7 @@ describe('validate', () => {
.validate()
.then(() => expect(module.webpackConfig.output).to.eql({
libraryTarget: 'commonjs',
path: `${testServicePath}/.webpack/service`,
path: path.join(testServicePath, '.webpack', 'service'),
filename: '[name].js',
}));
});
Expand All @@ -176,7 +177,7 @@ describe('validate', () => {
it('should load a webpack config from file if `custom.webpack` is a string', () => {
const testConfig = 'testconfig';
const testServicePath = 'testpath';
const requiredPath = `${testServicePath}/${testConfig}`;
const requiredPath = path.join(testServicePath, testConfig);
module.serverless.config.servicePath = testServicePath;
module.serverless.service.custom.webpack = testConfig;
serverless.utils.fileExistsSync = sinon.stub().returns(true);
Expand Down Expand Up @@ -206,7 +207,7 @@ describe('validate', () => {
it('should load a default file if no custom config is provided', () => {
const testConfig = 'webpack.config.js';
const testServicePath = 'testpath';
const requiredPath = `${testServicePath}/${testConfig}`;
const requiredPath = path.join(testServicePath, testConfig);
module.serverless.config.servicePath = testServicePath;
serverless.utils.fileExistsSync = sinon.stub().returns(true);
const loadedConfig = {
Expand Down

0 comments on commit c838a31

Please sign in to comment.