Skip to content

Commit ac438d4

Browse files
author
Frank Schmid
committed
Added unit test for Google to check that no module copy occurs
1 parent e5efb8f commit ac438d4

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

tests/packExternalModules.test.js

+47
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,53 @@ describe('packExternalModules', () => {
212212
]));
213213
});
214214

215+
it('should skip module copy for Google provider', () => {
216+
const expectedCompositePackageJSON = {
217+
name: 'test-service',
218+
version: '1.0.0',
219+
description: 'Packaged externals for test-service',
220+
private: true,
221+
dependencies: {
222+
'@scoped/vendor': '1.0.0',
223+
uuid: '^5.4.1',
224+
bluebird: '^3.4.0'
225+
}
226+
};
227+
const expectedPackageJSON = {
228+
dependencies: {
229+
'@scoped/vendor': '1.0.0',
230+
uuid: '^5.4.1',
231+
bluebird: '^3.4.0'
232+
}
233+
};
234+
235+
_.set(serverless, 'service.provider.name', 'google');
236+
module.webpackOutputPath = 'outputPath';
237+
fsExtraMock.pathExists.yields(null, false);
238+
fsExtraMock.copy.yields();
239+
childProcessMock.exec.onFirstCall().yields(null, '{}', '');
240+
childProcessMock.exec.onSecondCall().yields(null, '', '');
241+
childProcessMock.exec.onThirdCall().yields();
242+
module.compileStats = stats;
243+
return expect(module.packExternalModules()).to.be.fulfilled
244+
.then(() => BbPromise.all([
245+
// The module package JSON and the composite one should have been stored
246+
expect(writeFileSyncStub).to.have.been.calledTwice,
247+
expect(writeFileSyncStub.firstCall.args[1]).to.equal(JSON.stringify(expectedCompositePackageJSON, null, 2)),
248+
expect(writeFileSyncStub.secondCall.args[1]).to.equal(JSON.stringify(expectedPackageJSON, null, 2)),
249+
// The modules should have been copied
250+
expect(fsExtraMock.copy).to.have.not.been.called,
251+
// npm ls and npm prune should have been called
252+
expect(childProcessMock.exec).to.have.been.calledTwice,
253+
expect(childProcessMock.exec.firstCall).to.have.been.calledWith(
254+
'npm ls -prod -json -depth=1'
255+
),
256+
expect(childProcessMock.exec.secondCall).to.have.been.calledWith(
257+
'npm install'
258+
)
259+
]));
260+
});
261+
215262
it('should reject if npm install fails', () => {
216263
module.webpackOutputPath = 'outputPath';
217264
fsExtraMock.pathExists.yields(null, false);

0 commit comments

Comments
 (0)