Skip to content

Commit c838a31

Browse files
authored
Merge pull request #188 from elastic-coders/fix-windows-unittests
Use path where needed to make unit tests on Windows pass.
2 parents dad3a9b + 6575b36 commit c838a31

File tree

3 files changed

+22
-16
lines changed

3 files changed

+22
-16
lines changed

tests/packExternalModules.test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ describe('packExternalModules', () => {
7676
sandbox.restore();
7777
});
7878

79-
describe('packageModules()', () => {
79+
describe('packExternalModules()', () => {
8080
it('should do nothing if webpackIncludeModules is not set', () => {
8181
_.unset(serverless, 'service.custom.webpackIncludeModules');
8282
return expect(module.packExternalModules({ stats: [] })).to.eventually.deep.equal({ stats: [] })
@@ -154,7 +154,7 @@ describe('packExternalModules', () => {
154154
'bluebird@^3.4.0'
155155
],
156156
{
157-
cwd: 'outputPath/dependencies',
157+
cwd: path.join('outputPath', 'dependencies'),
158158
maxBuffer: 204800,
159159
save: true
160160
}),

tests/packageModules.test.js

+13-8
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
const BbPromise = require('bluebird');
44
const _ = require('lodash');
55
const chai = require('chai');
6+
const path = require('path');
67
const sinon = require('sinon');
78
const mockery = require('mockery');
89
const Serverless = require('serverless');
@@ -134,10 +135,12 @@ describe('packageModules', () => {
134135
fsMock._streamMock.on.withArgs('close').yields();
135136
fsMock._statMock.isDirectory.returns(false);
136137

138+
const expectedArtifactPath = path.join('.serverless', 'test-service.zip');
139+
137140
return expect(module.packageModules(stats)).to.be.fulfilled
138141
.then(() => BbPromise.all([
139-
expect(func1).to.have.a.nested.property('package.artifact').that.equals('.serverless/test-service.zip'),
140-
expect(func2).to.have.a.nested.property('package.artifact').that.equals('.serverless/test-service.zip'),
142+
expect(func1).to.have.a.nested.property('package.artifact').that.equals(expectedArtifactPath),
143+
expect(func2).to.have.a.nested.property('package.artifact').that.equals(expectedArtifactPath),
141144
]));
142145
});
143146

@@ -205,8 +208,8 @@ describe('packageModules', () => {
205208

206209
return expect(module.packageModules(stats)).to.be.fulfilled
207210
.then(() => BbPromise.all([
208-
expect(func1).to.have.a.nested.property('package.artifact').that.equals('.serverless/func1.zip'),
209-
expect(func2).to.have.a.nested.property('package.artifact').that.equals('.serverless/func2.zip'),
211+
expect(func1).to.have.a.nested.property('package.artifact').that.equals(path.join('.serverless', 'func1.zip')),
212+
expect(func2).to.have.a.nested.property('package.artifact').that.equals(path.join('.serverless', 'func2.zip')),
210213
]));
211214
});
212215

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

258+
const expectedArtifactPath = path.join('.serverless', 'test-service.zip');
259+
255260
return BbPromise.each([ '1.18.1', '2.17.0', '10.15.3', ], version => {
256261
getVersionStub.returns(version);
257262
return expect(module.packageModules(stats)).to.be.fulfilled
258263
.then(() => BbPromise.all([
259-
expect(func1).to.have.a.nested.property('package.artifact').that.equals('.serverless/test-service.zip'),
260-
expect(func2).to.have.a.nested.property('package.artifact').that.equals('.serverless/test-service.zip'),
264+
expect(func1).to.have.a.nested.property('package.artifact').that.equals(expectedArtifactPath),
265+
expect(func2).to.have.a.nested.property('package.artifact').that.equals(expectedArtifactPath),
261266
]));
262267
})
263268
.then(() => BbPromise.each([ '1.17.0', '1.16.0-alpha', '1.15.3', ], version => {
264269
getVersionStub.returns(version);
265270
return expect(module.packageModules(stats)).to.be.fulfilled
266271
.then(() => BbPromise.all([
267-
expect(func1).to.have.a.nested.property('artifact').that.equals('.serverless/test-service.zip'),
268-
expect(func2).to.have.a.nested.property('artifact').that.equals('.serverless/test-service.zip'),
272+
expect(func1).to.have.a.nested.property('artifact').that.equals(expectedArtifactPath),
273+
expect(func2).to.have.a.nested.property('artifact').that.equals(expectedArtifactPath),
269274
]));
270275
}));
271276
});

tests/validate.test.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const _ = require('lodash');
44
const chai = require('chai');
55
const sinon = require('sinon');
66
const mockery = require('mockery');
7+
const path = require('path');
78
const Serverless = require('serverless');
89
const makeFsExtraMock = require('./fs-extra.mock');
910

@@ -104,7 +105,7 @@ describe('validate', () => {
104105
return module
105106
.validate()
106107
.then(() => expect(module.webpackConfig.output).to.eql({
107-
path: `${testServicePath}/${testOptionsOut}/service`,
108+
path: path.join(testServicePath, testOptionsOut, 'service'),
108109
filename: 'filename',
109110
}));
110111
});
@@ -135,7 +136,7 @@ describe('validate', () => {
135136
.validate()
136137
.then(() => expect(module.webpackConfig.output).to.eql({
137138
libraryTarget: 'commonjs',
138-
path: `${testServicePath}/.webpack/service`,
139+
path: path.join(testServicePath, '.webpack', 'service'),
139140
filename: '[name].js',
140141
}));
141142
});
@@ -152,7 +153,7 @@ describe('validate', () => {
152153
.validate()
153154
.then(() => expect(module.webpackConfig.output).to.eql({
154155
libraryTarget: 'commonjs',
155-
path: `${testServicePath}/.webpack/service`,
156+
path: path.join(testServicePath, '.webpack', 'service'),
156157
filename: '[name].js',
157158
}));
158159
});
@@ -166,7 +167,7 @@ describe('validate', () => {
166167
.validate()
167168
.then(() => expect(module.webpackConfig.output).to.eql({
168169
libraryTarget: 'commonjs',
169-
path: `${testServicePath}/.webpack/service`,
170+
path: path.join(testServicePath, '.webpack', 'service'),
170171
filename: '[name].js',
171172
}));
172173
});
@@ -176,7 +177,7 @@ describe('validate', () => {
176177
it('should load a webpack config from file if `custom.webpack` is a string', () => {
177178
const testConfig = 'testconfig';
178179
const testServicePath = 'testpath';
179-
const requiredPath = `${testServicePath}/${testConfig}`;
180+
const requiredPath = path.join(testServicePath, testConfig);
180181
module.serverless.config.servicePath = testServicePath;
181182
module.serverless.service.custom.webpack = testConfig;
182183
serverless.utils.fileExistsSync = sinon.stub().returns(true);
@@ -206,7 +207,7 @@ describe('validate', () => {
206207
it('should load a default file if no custom config is provided', () => {
207208
const testConfig = 'webpack.config.js';
208209
const testServicePath = 'testpath';
209-
const requiredPath = `${testServicePath}/${testConfig}`;
210+
const requiredPath = path.join(testServicePath, testConfig);
210211
module.serverless.config.servicePath = testServicePath;
211212
serverless.utils.fileExistsSync = sinon.stub().returns(true);
212213
const loadedConfig = {

0 commit comments

Comments
 (0)