2017-08-05 01:20:38 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
const BbPromise = require('bluebird');
|
|
|
|
|
const _ = require('lodash');
|
|
|
|
|
const path = require('path');
|
|
|
|
|
const chai = require('chai');
|
|
|
|
|
const sinon = require('sinon');
|
|
|
|
|
const mockery = require('mockery');
|
|
|
|
|
const Serverless = require('serverless');
|
2018-03-07 02:33:03 +01:00
|
|
|
const Configuration = require('../lib/Configuration');
|
2017-08-05 01:20:38 +02:00
|
|
|
|
|
|
|
|
// Mocks
|
|
|
|
|
const fsExtraMockFactory = require('./mocks/fs-extra.mock');
|
|
|
|
|
const packageMock = require('./mocks/package.mock.json');
|
2017-11-17 12:14:48 +01:00
|
|
|
const packageLocalRefMock = require('./mocks/packageLocalRef.mock.json');
|
2018-05-03 12:59:38 +02:00
|
|
|
const packageIgnoredDevDepsMock = require('./mocks/packageIgnoredDevDeps.mock.json');
|
2017-08-05 01:20:38 +02:00
|
|
|
|
|
|
|
|
chai.use(require('chai-as-promised'));
|
|
|
|
|
chai.use(require('sinon-chai'));
|
|
|
|
|
|
|
|
|
|
const expect = chai.expect;
|
|
|
|
|
|
2018-02-26 04:50:51 -05:00
|
|
|
class ChunkMock {
|
|
|
|
|
constructor(modules) {
|
|
|
|
|
this._modules = modules;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
forEachModule(fn) {
|
|
|
|
|
_.forEach(this._modules, fn);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-28 18:49:19 +01:00
|
|
|
const packagerMockFactory = {
|
|
|
|
|
create(sandbox) {
|
|
|
|
|
const packagerMock = {
|
|
|
|
|
lockfileName: 'mocked-lock.json',
|
2018-04-30 15:39:02 +02:00
|
|
|
copyPackageSectionNames: [ 'section1', 'section2' ],
|
2018-03-08 02:57:03 +01:00
|
|
|
mustCopyModules: true,
|
2018-02-28 18:49:19 +01:00
|
|
|
rebaseLockfile: sandbox.stub(),
|
|
|
|
|
getProdDependencies: sandbox.stub(),
|
|
|
|
|
install: sandbox.stub(),
|
2018-03-09 18:59:12 +01:00
|
|
|
prune: sandbox.stub(),
|
|
|
|
|
runScripts: sandbox.stub()
|
2018-02-28 18:49:19 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return packagerMock;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2017-08-05 01:20:38 +02:00
|
|
|
describe('packExternalModules', () => {
|
|
|
|
|
let sandbox;
|
|
|
|
|
let baseModule;
|
|
|
|
|
let serverless;
|
|
|
|
|
let module;
|
|
|
|
|
|
|
|
|
|
// Mocks
|
2018-02-28 18:49:19 +01:00
|
|
|
let packagerFactoryMock;
|
|
|
|
|
let packagerMock;
|
2017-08-05 01:20:38 +02:00
|
|
|
let fsExtraMock;
|
|
|
|
|
// Serverless stubs
|
|
|
|
|
let writeFileSyncStub;
|
2017-12-18 13:52:03 -02:00
|
|
|
let readFileSyncStub;
|
2017-08-05 01:20:38 +02:00
|
|
|
|
|
|
|
|
before(() => {
|
2018-07-07 16:12:24 +02:00
|
|
|
sandbox = sinon.createSandbox();
|
2018-02-28 18:49:19 +01:00
|
|
|
sandbox.usingPromise(BbPromise.Promise);
|
2017-08-05 01:20:38 +02:00
|
|
|
|
2018-02-28 18:49:19 +01:00
|
|
|
packagerMock = packagerMockFactory.create(sandbox);
|
2017-08-05 01:20:38 +02:00
|
|
|
fsExtraMock = fsExtraMockFactory.create(sandbox);
|
|
|
|
|
|
2018-02-28 18:49:19 +01:00
|
|
|
// Setup packager mocks
|
|
|
|
|
packagerFactoryMock = {
|
|
|
|
|
get: sinon.stub()
|
|
|
|
|
};
|
|
|
|
|
packagerFactoryMock.get.withArgs('npm').returns(packagerMock);
|
|
|
|
|
packagerFactoryMock.get.throws(new Error('Packager not mocked'));
|
|
|
|
|
|
|
|
|
|
mockery.enable({ useCleanCache: true, warnOnUnregistered: false });
|
2017-08-05 01:20:38 +02:00
|
|
|
mockery.registerMock('fs-extra', fsExtraMock);
|
2018-02-28 18:49:19 +01:00
|
|
|
mockery.registerMock('./packagers', packagerFactoryMock);
|
2017-08-05 01:20:38 +02:00
|
|
|
mockery.registerMock(path.join(process.cwd(), 'package.json'), packageMock);
|
|
|
|
|
baseModule = require('../lib/packExternalModules');
|
|
|
|
|
Object.freeze(baseModule);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
after(() => {
|
|
|
|
|
mockery.disable();
|
|
|
|
|
mockery.deregisterAll();
|
2018-02-28 18:49:19 +01:00
|
|
|
sandbox.restore();
|
2017-08-05 01:20:38 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
|
serverless = new Serverless();
|
|
|
|
|
serverless.cli = {
|
|
|
|
|
log: sandbox.stub(),
|
|
|
|
|
consoleLog: sandbox.stub()
|
|
|
|
|
};
|
2017-10-03 15:36:27 +02:00
|
|
|
_.set(serverless, 'service.service', 'test-service');
|
2017-08-05 01:20:38 +02:00
|
|
|
|
|
|
|
|
writeFileSyncStub = sandbox.stub(serverless.utils, 'writeFileSync');
|
2017-12-18 13:52:03 -02:00
|
|
|
readFileSyncStub = sandbox.stub(serverless.utils, 'readFileSync');
|
2017-08-05 01:20:38 +02:00
|
|
|
_.set(serverless, 'service.custom.webpackIncludeModules', true);
|
|
|
|
|
|
|
|
|
|
module = _.assign({
|
|
|
|
|
serverless,
|
2017-09-21 11:58:53 +02:00
|
|
|
options: {
|
|
|
|
|
verbose: true
|
|
|
|
|
},
|
2018-03-07 02:33:03 +01:00
|
|
|
configuration: new Configuration({
|
|
|
|
|
webpack: {
|
2018-03-07 19:17:38 +01:00
|
|
|
includeModules: true
|
2018-03-07 02:33:03 +01:00
|
|
|
}
|
|
|
|
|
})
|
2017-08-05 01:20:38 +02:00
|
|
|
}, baseModule);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
|
// Reset all counters and restore all stubbed functions
|
2018-02-28 18:49:19 +01:00
|
|
|
writeFileSyncStub.restore();
|
|
|
|
|
readFileSyncStub.restore();
|
2017-10-03 15:36:27 +02:00
|
|
|
fsExtraMock.pathExists.reset();
|
2017-09-07 15:00:49 +02:00
|
|
|
fsExtraMock.copy.reset();
|
2017-08-05 01:20:38 +02:00
|
|
|
sandbox.reset();
|
|
|
|
|
});
|
|
|
|
|
|
2017-08-10 14:05:41 +02:00
|
|
|
describe('packExternalModules()', () => {
|
2017-09-07 15:00:49 +02:00
|
|
|
// Test data
|
|
|
|
|
const stats = {
|
|
|
|
|
stats: [
|
|
|
|
|
{
|
|
|
|
|
compilation: {
|
|
|
|
|
chunks: [
|
2018-02-26 04:50:51 -05:00
|
|
|
new ChunkMock([
|
|
|
|
|
{
|
|
|
|
|
identifier: _.constant('"crypto"')
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
identifier: _.constant('"uuid/v4"')
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
identifier: _.constant('"mockery"')
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
identifier: _.constant('"@scoped/vendor/module1"')
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
identifier: _.constant('external "@scoped/vendor/module2"')
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
identifier: _.constant('external "uuid/v4"')
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
identifier: _.constant('external "bluebird"')
|
|
|
|
|
},
|
|
|
|
|
])
|
2017-09-07 15:00:49 +02:00
|
|
|
],
|
|
|
|
|
compiler: {
|
|
|
|
|
outputPath: '/my/Service/Path/.webpack/service'
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
};
|
|
|
|
|
const noExtStats = {
|
|
|
|
|
stats: [
|
|
|
|
|
{
|
|
|
|
|
compilation: {
|
|
|
|
|
chunks: [
|
2018-02-26 04:50:51 -05:00
|
|
|
new ChunkMock([
|
|
|
|
|
{
|
|
|
|
|
identifier: _.constant('"crypto"')
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
identifier: _.constant('"uuid/v4"')
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
identifier: _.constant('"mockery"')
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
identifier: _.constant('"@scoped/vendor/module1"')
|
|
|
|
|
},
|
|
|
|
|
])
|
2017-09-07 15:00:49 +02:00
|
|
|
],
|
|
|
|
|
compiler: {
|
|
|
|
|
outputPath: '/my/Service/Path/.webpack/service'
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
};
|
2017-11-17 12:14:48 +01:00
|
|
|
const statsWithFileRef = {
|
2018-05-02 12:37:04 +02:00
|
|
|
stats: [
|
|
|
|
|
{
|
|
|
|
|
compilation: {
|
|
|
|
|
chunks: [
|
|
|
|
|
new ChunkMock([
|
|
|
|
|
{
|
|
|
|
|
identifier: _.constant('"crypto"')
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
identifier: _.constant('"uuid/v4"')
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
identifier: _.constant('"mockery"')
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
identifier: _.constant('"@scoped/vendor/module1"')
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
identifier: _.constant('external "@scoped/vendor/module2"')
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
identifier: _.constant('external "uuid/v4"')
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
identifier: _.constant('external "localmodule"')
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
identifier: _.constant('external "bluebird"')
|
|
|
|
|
},
|
|
|
|
|
])
|
|
|
|
|
],
|
|
|
|
|
compiler: {
|
|
|
|
|
outputPath: '/my/Service/Path/.webpack/service'
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
};
|
|
|
|
|
const statsWithDevDependency = {
|
2017-11-17 12:14:48 +01:00
|
|
|
stats: [
|
|
|
|
|
{
|
|
|
|
|
compilation: {
|
|
|
|
|
chunks: [
|
2018-02-26 04:50:51 -05:00
|
|
|
new ChunkMock([
|
|
|
|
|
{
|
|
|
|
|
identifier: _.constant('"crypto"')
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
identifier: _.constant('"uuid/v4"')
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
identifier: _.constant('external "eslint"')
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
identifier: _.constant('"mockery"')
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
identifier: _.constant('"@scoped/vendor/module1"')
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
identifier: _.constant('external "@scoped/vendor/module2"')
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
identifier: _.constant('external "uuid/v4"')
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
identifier: _.constant('external "localmodule"')
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
identifier: _.constant('external "bluebird"')
|
|
|
|
|
},
|
|
|
|
|
])
|
2017-11-17 12:14:48 +01:00
|
|
|
],
|
|
|
|
|
compiler: {
|
|
|
|
|
outputPath: '/my/Service/Path/.webpack/service'
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
};
|
2018-05-03 12:59:38 +02:00
|
|
|
const statsWithIgnoredDevDependency = {
|
|
|
|
|
stats: [
|
|
|
|
|
{
|
|
|
|
|
compilation: {
|
|
|
|
|
chunks: [
|
|
|
|
|
new ChunkMock([
|
|
|
|
|
{
|
|
|
|
|
identifier: _.constant('"crypto"')
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
identifier: _.constant('"uuid/v4"')
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
identifier: _.constant('"mockery"')
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
identifier: _.constant('"@scoped/vendor/module1"')
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
identifier: _.constant('external "@scoped/vendor/module2"')
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
identifier: _.constant('external "uuid/v4"')
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
identifier: _.constant('external "localmodule"')
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
identifier: _.constant('external "bluebird"')
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
identifier: _.constant('external "aws-sdk"')
|
|
|
|
|
},
|
|
|
|
|
])
|
|
|
|
|
],
|
|
|
|
|
compiler: {
|
|
|
|
|
outputPath: '/my/Service/Path/.webpack/service'
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
};
|
2017-09-07 15:00:49 +02:00
|
|
|
|
2017-08-05 01:20:38 +02:00
|
|
|
it('should do nothing if webpackIncludeModules is not set', () => {
|
2018-03-07 02:33:03 +01:00
|
|
|
module.configuration = new Configuration();
|
2017-10-23 07:29:17 -06:00
|
|
|
module.compileStats = { stats: [] };
|
|
|
|
|
return expect(module.packExternalModules()).to.be.fulfilled
|
2017-08-05 01:20:38 +02:00
|
|
|
.then(() => BbPromise.all([
|
|
|
|
|
expect(fsExtraMock.copy).to.not.have.been.called,
|
2018-02-28 18:49:19 +01:00
|
|
|
expect(packagerFactoryMock.get).to.not.have.been.called,
|
2017-08-05 01:20:38 +02:00
|
|
|
expect(writeFileSyncStub).to.not.have.been.called,
|
|
|
|
|
]));
|
|
|
|
|
});
|
|
|
|
|
|
2018-04-30 15:39:02 +02:00
|
|
|
it('should copy needed package sections if available', () => {
|
|
|
|
|
const originalPackageJSON = {
|
|
|
|
|
name: 'test-service',
|
|
|
|
|
version: '1.0.0',
|
|
|
|
|
description: 'Packaged externals for test-service',
|
|
|
|
|
private: true,
|
|
|
|
|
scripts: {},
|
|
|
|
|
section1: {
|
|
|
|
|
value: 'myValue'
|
|
|
|
|
},
|
|
|
|
|
dependencies: {
|
|
|
|
|
'@scoped/vendor': '1.0.0',
|
|
|
|
|
uuid: '^5.4.1',
|
|
|
|
|
bluebird: '^3.4.0'
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
const expectedCompositePackageJSON = {
|
|
|
|
|
name: 'test-service',
|
|
|
|
|
version: '1.0.0',
|
|
|
|
|
description: 'Packaged externals for test-service',
|
|
|
|
|
private: true,
|
|
|
|
|
scripts: {},
|
|
|
|
|
section1: originalPackageJSON.section1,
|
|
|
|
|
dependencies: {
|
|
|
|
|
'@scoped/vendor': '1.0.0',
|
|
|
|
|
uuid: '^5.4.1',
|
|
|
|
|
bluebird: '^3.4.0'
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
const expectedPackageJSON = {
|
|
|
|
|
name: 'test-service',
|
|
|
|
|
version: '1.0.0',
|
|
|
|
|
description: 'Packaged externals for test-service',
|
|
|
|
|
private: true,
|
|
|
|
|
scripts: {},
|
|
|
|
|
dependencies: {
|
|
|
|
|
'@scoped/vendor': '1.0.0',
|
|
|
|
|
uuid: '^5.4.1',
|
|
|
|
|
bluebird: '^3.4.0'
|
|
|
|
|
},
|
|
|
|
|
section1: originalPackageJSON.section1
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
module.webpackOutputPath = 'outputPath';
|
|
|
|
|
readFileSyncStub.onFirstCall().returns(originalPackageJSON);
|
|
|
|
|
readFileSyncStub.throws(new Error('Unexpected call to readFileSync'));
|
|
|
|
|
fsExtraMock.pathExists.yields(null, false);
|
|
|
|
|
fsExtraMock.copy.yields();
|
|
|
|
|
packagerMock.getProdDependencies.returns(BbPromise.resolve({}));
|
|
|
|
|
packagerMock.install.returns(BbPromise.resolve());
|
|
|
|
|
packagerMock.prune.returns(BbPromise.resolve());
|
|
|
|
|
packagerMock.runScripts.returns(BbPromise.resolve());
|
|
|
|
|
module.compileStats = stats;
|
|
|
|
|
return expect(module.packExternalModules()).to.be.fulfilled
|
|
|
|
|
.then(() => BbPromise.all([
|
|
|
|
|
// The module package JSON and the composite one should have been stored
|
|
|
|
|
expect(writeFileSyncStub).to.have.been.calledTwice,
|
|
|
|
|
expect(writeFileSyncStub.firstCall.args[1]).to.equal(JSON.stringify(expectedCompositePackageJSON, null, 2)),
|
|
|
|
|
expect(writeFileSyncStub.secondCall.args[1]).to.equal(JSON.stringify(expectedPackageJSON, null, 2)),
|
|
|
|
|
// The modules should have been copied
|
|
|
|
|
expect(fsExtraMock.copy).to.have.been.calledOnce,
|
|
|
|
|
// npm ls and npm prune should have been called
|
|
|
|
|
expect(packagerMock.getProdDependencies).to.have.been.calledOnce,
|
|
|
|
|
expect(packagerMock.install).to.have.been.calledOnce,
|
|
|
|
|
expect(packagerMock.prune).to.have.been.calledOnce,
|
|
|
|
|
expect(packagerMock.runScripts).to.have.been.calledOnce,
|
|
|
|
|
]));
|
|
|
|
|
});
|
|
|
|
|
|
2017-08-05 01:20:38 +02:00
|
|
|
it('should install external modules', () => {
|
2017-10-03 15:36:27 +02:00
|
|
|
const expectedCompositePackageJSON = {
|
|
|
|
|
name: 'test-service',
|
|
|
|
|
version: '1.0.0',
|
|
|
|
|
description: 'Packaged externals for test-service',
|
|
|
|
|
private: true,
|
2018-03-09 18:59:12 +01:00
|
|
|
scripts: {},
|
2017-10-03 15:36:27 +02:00
|
|
|
dependencies: {
|
|
|
|
|
'@scoped/vendor': '1.0.0',
|
|
|
|
|
uuid: '^5.4.1',
|
|
|
|
|
bluebird: '^3.4.0'
|
|
|
|
|
}
|
|
|
|
|
};
|
2017-08-05 01:20:38 +02:00
|
|
|
const expectedPackageJSON = {
|
2018-03-09 18:59:12 +01:00
|
|
|
name: 'test-service',
|
|
|
|
|
version: '1.0.0',
|
|
|
|
|
description: 'Packaged externals for test-service',
|
|
|
|
|
private: true,
|
|
|
|
|
scripts: {},
|
2017-08-05 01:20:38 +02:00
|
|
|
dependencies: {
|
|
|
|
|
'@scoped/vendor': '1.0.0',
|
|
|
|
|
uuid: '^5.4.1',
|
|
|
|
|
bluebird: '^3.4.0'
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
module.webpackOutputPath = 'outputPath';
|
2017-10-03 15:36:27 +02:00
|
|
|
fsExtraMock.pathExists.yields(null, false);
|
2017-08-05 01:20:38 +02:00
|
|
|
fsExtraMock.copy.yields();
|
2018-02-28 18:49:19 +01:00
|
|
|
packagerMock.getProdDependencies.returns(BbPromise.resolve({}));
|
|
|
|
|
packagerMock.install.returns(BbPromise.resolve());
|
|
|
|
|
packagerMock.prune.returns(BbPromise.resolve());
|
2018-03-09 18:59:12 +01:00
|
|
|
packagerMock.runScripts.returns(BbPromise.resolve());
|
2017-10-23 07:29:17 -06:00
|
|
|
module.compileStats = stats;
|
|
|
|
|
return expect(module.packExternalModules()).to.be.fulfilled
|
2017-08-05 01:20:38 +02:00
|
|
|
.then(() => BbPromise.all([
|
|
|
|
|
// The module package JSON and the composite one should have been stored
|
|
|
|
|
expect(writeFileSyncStub).to.have.been.calledTwice,
|
2017-10-03 15:36:27 +02:00
|
|
|
expect(writeFileSyncStub.firstCall.args[1]).to.equal(JSON.stringify(expectedCompositePackageJSON, null, 2)),
|
2017-08-05 01:20:38 +02:00
|
|
|
expect(writeFileSyncStub.secondCall.args[1]).to.equal(JSON.stringify(expectedPackageJSON, null, 2)),
|
|
|
|
|
// The modules should have been copied
|
|
|
|
|
expect(fsExtraMock.copy).to.have.been.calledOnce,
|
2017-09-07 15:00:49 +02:00
|
|
|
// npm ls and npm prune should have been called
|
2018-02-28 18:49:19 +01:00
|
|
|
expect(packagerMock.getProdDependencies).to.have.been.calledOnce,
|
|
|
|
|
expect(packagerMock.install).to.have.been.calledOnce,
|
|
|
|
|
expect(packagerMock.prune).to.have.been.calledOnce,
|
2018-03-09 18:59:12 +01:00
|
|
|
expect(packagerMock.runScripts).to.have.been.calledOnce,
|
2017-11-17 12:14:48 +01:00
|
|
|
]));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should rebase file references', () => {
|
2017-12-18 13:52:03 -02:00
|
|
|
const expectedLocalModule = 'file:../../locals/../../mymodule';
|
2017-11-17 12:14:48 +01:00
|
|
|
const expectedCompositePackageJSON = {
|
|
|
|
|
name: 'test-service',
|
|
|
|
|
version: '1.0.0',
|
|
|
|
|
description: 'Packaged externals for test-service',
|
|
|
|
|
private: true,
|
2018-03-09 18:59:12 +01:00
|
|
|
scripts: {},
|
2017-11-17 12:14:48 +01:00
|
|
|
dependencies: {
|
|
|
|
|
'@scoped/vendor': '1.0.0',
|
|
|
|
|
uuid: '^5.4.1',
|
|
|
|
|
localmodule: 'file:../../locals/../../mymodule',
|
|
|
|
|
bluebird: '^3.4.0'
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
const expectedPackageJSON = {
|
2018-03-09 18:59:12 +01:00
|
|
|
name: 'test-service',
|
|
|
|
|
version: '1.0.0',
|
|
|
|
|
description: 'Packaged externals for test-service',
|
|
|
|
|
private: true,
|
|
|
|
|
scripts: {},
|
2017-11-17 12:14:48 +01:00
|
|
|
dependencies: {
|
|
|
|
|
'@scoped/vendor': '1.0.0',
|
|
|
|
|
uuid: '^5.4.1',
|
2017-12-18 13:52:03 -02:00
|
|
|
localmodule: expectedLocalModule,
|
2017-11-17 12:14:48 +01:00
|
|
|
bluebird: '^3.4.0'
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2017-12-18 13:52:03 -02:00
|
|
|
const fakePackageLockJSON = {
|
|
|
|
|
name: 'test-service',
|
|
|
|
|
version: '1.0.0',
|
|
|
|
|
description: 'Packaged externals for test-service',
|
|
|
|
|
private: true,
|
|
|
|
|
dependencies: {
|
|
|
|
|
'@scoped/vendor': '1.0.0',
|
|
|
|
|
uuid: {
|
|
|
|
|
version: '^5.4.1'
|
|
|
|
|
},
|
|
|
|
|
bluebird: {
|
|
|
|
|
version: '^3.4.0'
|
|
|
|
|
},
|
|
|
|
|
localmodule: {
|
|
|
|
|
version: 'file:../../mymodule'
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2018-03-07 02:33:03 +01:00
|
|
|
module.configuration = new Configuration({
|
|
|
|
|
webpack: {
|
2018-03-07 19:17:38 +01:00
|
|
|
includeModules: {
|
2018-03-07 02:33:03 +01:00
|
|
|
packagePath: path.join('locals', 'package.json')
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
2017-11-17 12:14:48 +01:00
|
|
|
module.webpackOutputPath = 'outputPath';
|
2018-04-30 11:27:18 +02:00
|
|
|
readFileSyncStub.onFirstCall().returns(packageLocalRefMock);
|
2017-12-18 13:52:03 -02:00
|
|
|
readFileSyncStub.returns(fakePackageLockJSON);
|
|
|
|
|
fsExtraMock.pathExists.yields(null, true);
|
2017-11-17 12:14:48 +01:00
|
|
|
fsExtraMock.copy.yields();
|
2018-02-28 18:49:19 +01:00
|
|
|
packagerMock.getProdDependencies.returns(BbPromise.resolve({}));
|
|
|
|
|
packagerMock.rebaseLockfile.callsFake((pathToPackageRoot, lockfile) => lockfile);
|
|
|
|
|
packagerMock.install.returns(BbPromise.resolve());
|
|
|
|
|
packagerMock.prune.returns(BbPromise.resolve());
|
2018-03-09 18:59:12 +01:00
|
|
|
packagerMock.runScripts.returns(BbPromise.resolve());
|
2017-11-17 12:14:48 +01:00
|
|
|
module.compileStats = statsWithFileRef;
|
|
|
|
|
|
|
|
|
|
sandbox.stub(process, 'cwd').returns(path.join('/my/Service/Path'));
|
|
|
|
|
mockery.registerMock(path.join(process.cwd(), 'locals', 'package.json'), packageLocalRefMock);
|
2018-02-26 04:50:51 -05:00
|
|
|
|
2017-11-17 12:14:48 +01:00
|
|
|
return expect(module.packExternalModules()).to.be.fulfilled
|
|
|
|
|
.then(() => BbPromise.all([
|
|
|
|
|
// The module package JSON and the composite one should have been stored
|
2017-12-18 13:52:03 -02:00
|
|
|
expect(writeFileSyncStub).to.have.been.calledThrice,
|
2017-11-17 12:14:48 +01:00
|
|
|
expect(writeFileSyncStub.firstCall.args[1]).to.equal(JSON.stringify(expectedCompositePackageJSON, null, 2)),
|
2017-12-18 13:52:03 -02:00
|
|
|
expect(writeFileSyncStub.thirdCall.args[1]).to.equal(JSON.stringify(expectedPackageJSON, null, 2)),
|
2018-03-08 02:57:03 +01:00
|
|
|
// The modules and the lock file should have been copied
|
|
|
|
|
expect(fsExtraMock.copy).to.have.been.calledTwice,
|
2018-02-28 18:49:19 +01:00
|
|
|
// Lock file rebase should have been called
|
|
|
|
|
expect(packagerMock.rebaseLockfile).to.have.been.calledOnce,
|
|
|
|
|
expect(packagerMock.rebaseLockfile).to.have.been.calledWith(sinon.match.any, sinon.match(fakePackageLockJSON)),
|
2017-11-17 12:14:48 +01:00
|
|
|
// npm ls and npm prune should have been called
|
2018-02-28 18:49:19 +01:00
|
|
|
expect(packagerMock.getProdDependencies).to.have.been.calledOnce,
|
|
|
|
|
expect(packagerMock.install).to.have.been.calledOnce,
|
|
|
|
|
expect(packagerMock.prune).to.have.been.calledOnce,
|
2018-03-09 18:59:12 +01:00
|
|
|
expect(packagerMock.runScripts).to.have.been.calledOnce,
|
2018-02-28 18:49:19 +01:00
|
|
|
]))
|
|
|
|
|
.finally(() => {
|
|
|
|
|
process.cwd.restore();
|
|
|
|
|
});
|
2017-09-07 15:00:49 +02:00
|
|
|
});
|
|
|
|
|
|
2017-10-31 15:07:43 +01:00
|
|
|
it('should skip module copy for Google provider', () => {
|
|
|
|
|
const expectedCompositePackageJSON = {
|
|
|
|
|
name: 'test-service',
|
|
|
|
|
version: '1.0.0',
|
|
|
|
|
description: 'Packaged externals for test-service',
|
|
|
|
|
private: true,
|
2018-03-09 18:59:12 +01:00
|
|
|
scripts: {},
|
2017-10-31 15:07:43 +01:00
|
|
|
dependencies: {
|
|
|
|
|
'@scoped/vendor': '1.0.0',
|
|
|
|
|
uuid: '^5.4.1',
|
|
|
|
|
bluebird: '^3.4.0'
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
const expectedPackageJSON = {
|
2018-03-09 18:59:12 +01:00
|
|
|
name: 'test-service',
|
|
|
|
|
version: '1.0.0',
|
|
|
|
|
description: 'Packaged externals for test-service',
|
|
|
|
|
private: true,
|
|
|
|
|
scripts: {},
|
2017-10-31 15:07:43 +01:00
|
|
|
dependencies: {
|
|
|
|
|
'@scoped/vendor': '1.0.0',
|
|
|
|
|
uuid: '^5.4.1',
|
|
|
|
|
bluebird: '^3.4.0'
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
_.set(serverless, 'service.provider.name', 'google');
|
|
|
|
|
module.webpackOutputPath = 'outputPath';
|
|
|
|
|
fsExtraMock.pathExists.yields(null, false);
|
|
|
|
|
fsExtraMock.copy.yields();
|
2018-02-28 18:49:19 +01:00
|
|
|
packagerMock.getProdDependencies.returns(BbPromise.resolve({}));
|
|
|
|
|
packagerMock.install.returns(BbPromise.resolve());
|
|
|
|
|
packagerMock.prune.returns(BbPromise.resolve());
|
2018-03-09 18:59:12 +01:00
|
|
|
packagerMock.runScripts.returns(BbPromise.resolve());
|
2017-10-31 15:07:43 +01:00
|
|
|
module.compileStats = stats;
|
|
|
|
|
return expect(module.packExternalModules()).to.be.fulfilled
|
|
|
|
|
.then(() => BbPromise.all([
|
|
|
|
|
// The module package JSON and the composite one should have been stored
|
|
|
|
|
expect(writeFileSyncStub).to.have.been.calledTwice,
|
|
|
|
|
expect(writeFileSyncStub.firstCall.args[1]).to.equal(JSON.stringify(expectedCompositePackageJSON, null, 2)),
|
|
|
|
|
expect(writeFileSyncStub.secondCall.args[1]).to.equal(JSON.stringify(expectedPackageJSON, null, 2)),
|
|
|
|
|
// The modules should have been copied
|
|
|
|
|
expect(fsExtraMock.copy).to.have.not.been.called,
|
|
|
|
|
// npm ls and npm prune should have been called
|
2018-02-28 18:49:19 +01:00
|
|
|
expect(packagerMock.getProdDependencies).to.have.been.calledOnce,
|
|
|
|
|
expect(packagerMock.install).to.have.been.calledOnce,
|
|
|
|
|
expect(packagerMock.prune).to.not.have.been.called,
|
2018-03-09 18:59:12 +01:00
|
|
|
expect(packagerMock.runScripts).to.not.have.been.called,
|
2017-10-31 15:07:43 +01:00
|
|
|
]));
|
|
|
|
|
});
|
|
|
|
|
|
2018-02-28 18:49:19 +01:00
|
|
|
it('should reject if packager install fails', () => {
|
2017-09-07 15:00:49 +02:00
|
|
|
module.webpackOutputPath = 'outputPath';
|
2017-10-03 15:36:27 +02:00
|
|
|
fsExtraMock.pathExists.yields(null, false);
|
2017-09-07 15:00:49 +02:00
|
|
|
fsExtraMock.copy.yields();
|
2018-02-28 18:49:19 +01:00
|
|
|
packagerMock.getProdDependencies.returns(BbPromise.resolve({}));
|
|
|
|
|
packagerMock.install.callsFake(() => BbPromise.reject(new Error('npm install failed')));
|
|
|
|
|
packagerMock.prune.returns(BbPromise.resolve());
|
2018-03-09 18:59:12 +01:00
|
|
|
packagerMock.runScripts.returns(BbPromise.resolve());
|
2017-10-23 07:29:17 -06:00
|
|
|
module.compileStats = stats;
|
|
|
|
|
return expect(module.packExternalModules()).to.be.rejectedWith('npm install failed')
|
2017-09-07 15:00:49 +02:00
|
|
|
.then(() => BbPromise.all([
|
2017-10-03 15:36:27 +02:00
|
|
|
// npm ls and npm install should have been called
|
2018-02-28 18:49:19 +01:00
|
|
|
expect(packagerMock.getProdDependencies).to.have.been.calledOnce,
|
|
|
|
|
expect(packagerMock.install).to.have.been.calledOnce,
|
|
|
|
|
expect(packagerMock.prune).to.not.have.been.called,
|
2018-03-09 18:59:12 +01:00
|
|
|
expect(packagerMock.runScripts).to.not.have.been.called,
|
2017-09-07 15:00:49 +02:00
|
|
|
]));
|
|
|
|
|
});
|
|
|
|
|
|
2018-02-28 18:49:19 +01:00
|
|
|
it('should reject if packager returns a critical error', () => {
|
2017-09-07 15:00:49 +02:00
|
|
|
module.webpackOutputPath = 'outputPath';
|
2017-10-03 15:36:27 +02:00
|
|
|
fsExtraMock.pathExists.yields(null, false);
|
2017-09-07 15:00:49 +02:00
|
|
|
fsExtraMock.copy.yields();
|
2018-02-28 18:49:19 +01:00
|
|
|
packagerMock.getProdDependencies.callsFake(() => BbPromise.reject(new Error('something went wrong')));
|
2017-10-23 07:29:17 -06:00
|
|
|
module.compileStats = stats;
|
|
|
|
|
return expect(module.packExternalModules()).to.be.rejectedWith('something went wrong')
|
2017-09-07 15:00:49 +02:00
|
|
|
.then(() => BbPromise.all([
|
|
|
|
|
// The module package JSON and the composite one should have been stored
|
|
|
|
|
expect(writeFileSyncStub).to.not.have.been.called,
|
|
|
|
|
// The modules should have been copied
|
|
|
|
|
expect(fsExtraMock.copy).to.not.have.been.called,
|
|
|
|
|
// npm ls and npm prune should have been called
|
2018-02-28 18:49:19 +01:00
|
|
|
expect(packagerMock.getProdDependencies).to.have.been.calledOnce,
|
|
|
|
|
expect(packagerMock.install).to.not.have.been.called,
|
|
|
|
|
expect(packagerMock.prune).to.not.have.been.called,
|
2018-03-09 18:59:12 +01:00
|
|
|
expect(packagerMock.runScripts).to.not.have.been.called,
|
2017-09-07 15:00:49 +02:00
|
|
|
]));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should not install modules if no external modules are reported', () => {
|
|
|
|
|
module.webpackOutputPath = 'outputPath';
|
|
|
|
|
fsExtraMock.copy.yields();
|
2018-02-28 18:49:19 +01:00
|
|
|
packagerMock.getProdDependencies.returns(BbPromise.resolve());
|
2017-10-23 07:29:17 -06:00
|
|
|
module.compileStats = noExtStats;
|
|
|
|
|
return expect(module.packExternalModules()).to.be.fulfilled
|
|
|
|
|
.then(() => BbPromise.all([
|
2017-09-07 15:00:49 +02:00
|
|
|
// The module package JSON and the composite one should have been stored
|
|
|
|
|
expect(writeFileSyncStub).to.not.have.been.called,
|
|
|
|
|
// The modules should have been copied
|
|
|
|
|
expect(fsExtraMock.copy).to.not.have.been.called,
|
2018-02-28 18:49:19 +01:00
|
|
|
// npm install and npm prune should not have been called
|
|
|
|
|
expect(packagerMock.getProdDependencies).to.have.been.calledOnce,
|
|
|
|
|
expect(packagerMock.install).to.not.have.been.called,
|
|
|
|
|
expect(packagerMock.prune).to.not.have.been.called,
|
2018-03-09 18:59:12 +01:00
|
|
|
expect(packagerMock.runScripts).to.not.have.been.called,
|
2017-08-05 01:20:38 +02:00
|
|
|
]));
|
|
|
|
|
});
|
2017-09-19 12:47:56 +02:00
|
|
|
|
2018-02-28 18:49:19 +01:00
|
|
|
it('should report ignored packager problems in verbose mode', () => {
|
|
|
|
|
module.webpackOutputPath = 'outputPath';
|
|
|
|
|
fsExtraMock.pathExists.yields(null, false);
|
|
|
|
|
fsExtraMock.copy.yields();
|
|
|
|
|
packagerMock.getProdDependencies.returns(BbPromise.resolve({
|
|
|
|
|
problems: [
|
|
|
|
|
'Problem 1',
|
|
|
|
|
'Problem 2'
|
|
|
|
|
]
|
|
|
|
|
}));
|
|
|
|
|
packagerMock.install.returns(BbPromise.resolve());
|
|
|
|
|
packagerMock.prune.returns(BbPromise.resolve());
|
2018-03-09 18:59:12 +01:00
|
|
|
packagerMock.runScripts.returns(BbPromise.resolve());
|
2018-02-28 18:49:19 +01:00
|
|
|
module.compileStats = stats;
|
|
|
|
|
return expect(module.packExternalModules()).to.be.fulfilled
|
|
|
|
|
.then(() => {
|
|
|
|
|
expect(packagerMock.getProdDependencies).to.have.been.calledOnce;
|
|
|
|
|
expect(serverless.cli.log).to.have.been.calledWith('=> Problem 1');
|
|
|
|
|
expect(serverless.cli.log).to.have.been.calledWith('=> Problem 2');
|
|
|
|
|
return null;
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2017-09-19 12:47:56 +02:00
|
|
|
it('should install external modules when forced', () => {
|
2017-10-03 15:36:27 +02:00
|
|
|
const expectedCompositePackageJSON = {
|
|
|
|
|
name: 'test-service',
|
|
|
|
|
version: '1.0.0',
|
|
|
|
|
description: 'Packaged externals for test-service',
|
|
|
|
|
private: true,
|
2018-03-09 18:59:12 +01:00
|
|
|
scripts: {},
|
2017-10-03 15:36:27 +02:00
|
|
|
dependencies: {
|
|
|
|
|
'@scoped/vendor': '1.0.0',
|
|
|
|
|
uuid: '^5.4.1',
|
|
|
|
|
bluebird: '^3.4.0',
|
|
|
|
|
pg: '^4.3.5'
|
|
|
|
|
}
|
|
|
|
|
};
|
2017-09-19 12:47:56 +02:00
|
|
|
const expectedPackageJSON = {
|
2018-03-09 18:59:12 +01:00
|
|
|
name: 'test-service',
|
|
|
|
|
version: '1.0.0',
|
|
|
|
|
description: 'Packaged externals for test-service',
|
|
|
|
|
private: true,
|
|
|
|
|
scripts: {},
|
2017-09-19 12:47:56 +02:00
|
|
|
dependencies: {
|
|
|
|
|
'@scoped/vendor': '1.0.0',
|
|
|
|
|
uuid: '^5.4.1',
|
|
|
|
|
bluebird: '^3.4.0',
|
|
|
|
|
pg: '^4.3.5'
|
|
|
|
|
}
|
|
|
|
|
};
|
2018-03-07 02:33:03 +01:00
|
|
|
module.configuration = new Configuration({
|
|
|
|
|
webpack: {
|
2018-03-07 19:17:38 +01:00
|
|
|
includeModules: {
|
2018-03-07 02:33:03 +01:00
|
|
|
forceInclude: ['pg']
|
|
|
|
|
}
|
2017-09-19 12:47:56 +02:00
|
|
|
}
|
2018-03-07 02:33:03 +01:00
|
|
|
});
|
2017-09-19 12:47:56 +02:00
|
|
|
module.webpackOutputPath = 'outputPath';
|
2017-10-03 15:36:27 +02:00
|
|
|
fsExtraMock.pathExists.yields(null, false);
|
2017-09-19 12:47:56 +02:00
|
|
|
fsExtraMock.copy.yields();
|
2018-02-28 18:49:19 +01:00
|
|
|
packagerMock.getProdDependencies.returns(BbPromise.resolve({}));
|
|
|
|
|
packagerMock.install.returns(BbPromise.resolve());
|
|
|
|
|
packagerMock.prune.returns(BbPromise.resolve());
|
2018-03-09 18:59:12 +01:00
|
|
|
packagerMock.runScripts.returns(BbPromise.resolve());
|
2017-10-23 07:29:17 -06:00
|
|
|
module.compileStats = stats;
|
|
|
|
|
return expect(module.packExternalModules()).to.be.fulfilled
|
2017-09-19 12:47:56 +02:00
|
|
|
.then(() => BbPromise.all([
|
|
|
|
|
// The module package JSON and the composite one should have been stored
|
|
|
|
|
expect(writeFileSyncStub).to.have.been.calledTwice,
|
2017-10-03 15:36:27 +02:00
|
|
|
expect(writeFileSyncStub.firstCall.args[1]).to.equal(JSON.stringify(expectedCompositePackageJSON, null, 2)),
|
2017-09-19 12:47:56 +02:00
|
|
|
expect(writeFileSyncStub.secondCall.args[1]).to.equal(JSON.stringify(expectedPackageJSON, null, 2)),
|
|
|
|
|
// The modules should have been copied
|
|
|
|
|
expect(fsExtraMock.copy).to.have.been.calledOnce,
|
|
|
|
|
// npm ls and npm prune should have been called
|
2018-02-28 18:49:19 +01:00
|
|
|
expect(packagerMock.getProdDependencies).to.have.been.calledOnce,
|
|
|
|
|
expect(packagerMock.install).to.have.been.calledOnce,
|
|
|
|
|
expect(packagerMock.prune).to.have.been.calledOnce,
|
2018-03-09 18:59:12 +01:00
|
|
|
expect(packagerMock.runScripts).to.have.been.calledOnce,
|
2017-09-19 12:47:56 +02:00
|
|
|
]));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should add forced external modules without version when not in production dependencies', () => {
|
2017-10-03 15:36:27 +02:00
|
|
|
const expectedCompositePackageJSON = {
|
|
|
|
|
name: 'test-service',
|
|
|
|
|
version: '1.0.0',
|
|
|
|
|
description: 'Packaged externals for test-service',
|
|
|
|
|
private: true,
|
2018-03-09 18:59:12 +01:00
|
|
|
scripts: {},
|
2017-10-03 15:36:27 +02:00
|
|
|
dependencies: {
|
|
|
|
|
'@scoped/vendor': '1.0.0',
|
|
|
|
|
uuid: '^5.4.1',
|
|
|
|
|
bluebird: '^3.4.0',
|
|
|
|
|
'not-in-prod-deps': ''
|
|
|
|
|
}
|
|
|
|
|
};
|
2017-09-19 12:47:56 +02:00
|
|
|
const expectedPackageJSON = {
|
2018-03-09 18:59:12 +01:00
|
|
|
name: 'test-service',
|
|
|
|
|
version: '1.0.0',
|
|
|
|
|
description: 'Packaged externals for test-service',
|
|
|
|
|
private: true,
|
|
|
|
|
scripts: {},
|
2017-09-19 12:47:56 +02:00
|
|
|
dependencies: {
|
|
|
|
|
'@scoped/vendor': '1.0.0',
|
|
|
|
|
uuid: '^5.4.1',
|
|
|
|
|
bluebird: '^3.4.0',
|
|
|
|
|
'not-in-prod-deps': ''
|
|
|
|
|
}
|
|
|
|
|
};
|
2018-03-07 02:33:03 +01:00
|
|
|
module.configuration = new Configuration({
|
|
|
|
|
webpack: {
|
2018-03-07 19:17:38 +01:00
|
|
|
includeModules: {
|
2018-03-07 02:33:03 +01:00
|
|
|
forceInclude: ['not-in-prod-deps']
|
|
|
|
|
}
|
2017-09-19 12:47:56 +02:00
|
|
|
}
|
2018-03-07 02:33:03 +01:00
|
|
|
});
|
2017-09-19 12:47:56 +02:00
|
|
|
module.webpackOutputPath = 'outputPath';
|
2017-10-03 15:36:27 +02:00
|
|
|
fsExtraMock.pathExists.yields(null, false);
|
2017-09-19 12:47:56 +02:00
|
|
|
fsExtraMock.copy.yields();
|
2018-02-28 18:49:19 +01:00
|
|
|
packagerMock.getProdDependencies.returns(BbPromise.resolve({}));
|
|
|
|
|
packagerMock.install.returns(BbPromise.resolve());
|
|
|
|
|
packagerMock.prune.returns(BbPromise.resolve());
|
2018-03-09 18:59:12 +01:00
|
|
|
packagerMock.runScripts.returns(BbPromise.resolve());
|
2017-10-23 07:29:17 -06:00
|
|
|
module.compileStats = stats;
|
|
|
|
|
return expect(module.packExternalModules()).to.be.fulfilled
|
2017-09-19 12:47:56 +02:00
|
|
|
.then(() => BbPromise.all([
|
|
|
|
|
// The module package JSON and the composite one should have been stored
|
|
|
|
|
expect(writeFileSyncStub).to.have.been.calledTwice,
|
2017-10-03 15:36:27 +02:00
|
|
|
expect(writeFileSyncStub.firstCall.args[1]).to.equal(JSON.stringify(expectedCompositePackageJSON, null, 2)),
|
2017-10-19 11:03:52 +02:00
|
|
|
expect(writeFileSyncStub.secondCall.args[1]).to.equal(JSON.stringify(expectedPackageJSON, null, 2)),
|
|
|
|
|
// The modules should have been copied
|
|
|
|
|
expect(fsExtraMock.copy).to.have.been.calledOnce,
|
|
|
|
|
// npm ls and npm prune should have been called
|
2018-02-28 18:49:19 +01:00
|
|
|
expect(packagerMock.getProdDependencies).to.have.been.calledOnce,
|
|
|
|
|
expect(packagerMock.install).to.have.been.calledOnce,
|
|
|
|
|
expect(packagerMock.prune).to.have.been.calledOnce,
|
2018-03-09 18:59:12 +01:00
|
|
|
expect(packagerMock.runScripts).to.have.been.calledOnce,
|
2017-10-19 11:03:52 +02:00
|
|
|
]));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should exclude external modules when forced', () => {
|
|
|
|
|
const expectedCompositePackageJSON = {
|
|
|
|
|
name: 'test-service',
|
|
|
|
|
version: '1.0.0',
|
|
|
|
|
description: 'Packaged externals for test-service',
|
|
|
|
|
private: true,
|
2018-03-09 18:59:12 +01:00
|
|
|
scripts: {},
|
2017-10-19 11:03:52 +02:00
|
|
|
dependencies: {
|
|
|
|
|
'@scoped/vendor': '1.0.0',
|
|
|
|
|
bluebird: '^3.4.0',
|
|
|
|
|
pg: '^4.3.5'
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
const expectedPackageJSON = {
|
2018-03-09 18:59:12 +01:00
|
|
|
name: 'test-service',
|
|
|
|
|
version: '1.0.0',
|
|
|
|
|
description: 'Packaged externals for test-service',
|
|
|
|
|
private: true,
|
|
|
|
|
scripts: {},
|
2017-10-19 11:03:52 +02:00
|
|
|
dependencies: {
|
|
|
|
|
'@scoped/vendor': '1.0.0',
|
|
|
|
|
bluebird: '^3.4.0',
|
|
|
|
|
pg: '^4.3.5'
|
|
|
|
|
}
|
|
|
|
|
};
|
2018-03-07 02:33:03 +01:00
|
|
|
module.configuration = new Configuration({
|
|
|
|
|
webpack: {
|
2018-03-07 19:17:38 +01:00
|
|
|
includeModules: {
|
2018-03-07 02:33:03 +01:00
|
|
|
forceInclude: ['pg'],
|
|
|
|
|
forceExclude: ['uuid']
|
|
|
|
|
}
|
2017-10-19 11:03:52 +02:00
|
|
|
}
|
2018-03-07 02:33:03 +01:00
|
|
|
});
|
2017-10-19 11:03:52 +02:00
|
|
|
module.webpackOutputPath = 'outputPath';
|
|
|
|
|
fsExtraMock.pathExists.yields(null, false);
|
|
|
|
|
fsExtraMock.copy.yields();
|
2018-02-28 18:49:19 +01:00
|
|
|
packagerMock.getProdDependencies.returns(BbPromise.resolve({}));
|
|
|
|
|
packagerMock.install.returns(BbPromise.resolve());
|
|
|
|
|
packagerMock.prune.returns(BbPromise.resolve());
|
2018-03-09 18:59:12 +01:00
|
|
|
packagerMock.runScripts.returns(BbPromise.resolve());
|
2017-10-23 07:29:17 -06:00
|
|
|
module.compileStats = stats;
|
|
|
|
|
return expect(module.packExternalModules()).to.be.fulfilled
|
2017-10-19 11:03:52 +02:00
|
|
|
.then(() => BbPromise.all([
|
|
|
|
|
// The module package JSON and the composite one should have been stored
|
|
|
|
|
expect(writeFileSyncStub).to.have.been.calledTwice,
|
|
|
|
|
expect(writeFileSyncStub.firstCall.args[1]).to.equal(JSON.stringify(expectedCompositePackageJSON, null, 2)),
|
2017-09-19 12:47:56 +02:00
|
|
|
expect(writeFileSyncStub.secondCall.args[1]).to.equal(JSON.stringify(expectedPackageJSON, null, 2)),
|
|
|
|
|
// The modules should have been copied
|
|
|
|
|
expect(fsExtraMock.copy).to.have.been.calledOnce,
|
|
|
|
|
// npm ls and npm prune should have been called
|
2018-02-28 18:49:19 +01:00
|
|
|
expect(packagerMock.getProdDependencies).to.have.been.calledOnce,
|
|
|
|
|
expect(packagerMock.install).to.have.been.calledOnce,
|
2018-05-02 12:37:04 +02:00
|
|
|
expect(packagerMock.prune).to.have.been.calledOnce,
|
|
|
|
|
expect(packagerMock.runScripts).to.have.been.calledOnce,
|
|
|
|
|
]));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should reject if devDependency is required at runtime', () => {
|
|
|
|
|
module.webpackOutputPath = 'outputPath';
|
|
|
|
|
fsExtraMock.pathExists.yields(null, false);
|
|
|
|
|
fsExtraMock.copy.yields();
|
|
|
|
|
packagerMock.getProdDependencies.returns(BbPromise.resolve({}));
|
|
|
|
|
packagerMock.install.returns(BbPromise.resolve());
|
|
|
|
|
packagerMock.prune.returns(BbPromise.resolve());
|
|
|
|
|
packagerMock.runScripts.returns(BbPromise.resolve());
|
|
|
|
|
module.compileStats = statsWithDevDependency;
|
|
|
|
|
return expect(module.packExternalModules()).to.be.rejectedWith('Serverless-webpack dependency error: eslint.')
|
|
|
|
|
.then(() => BbPromise.all([
|
2018-05-03 12:59:38 +02:00
|
|
|
expect(module.serverless.cli.log).to.have.been.calledWith(sinon.match(/ERROR: Runtime dependency 'eslint' found in devDependencies/)),
|
2018-05-02 12:37:04 +02:00
|
|
|
// npm ls and npm install should have been called
|
|
|
|
|
expect(packagerMock.getProdDependencies).to.have.been.calledOnce,
|
|
|
|
|
expect(packagerMock.install).to.not.have.been.called,
|
|
|
|
|
expect(packagerMock.prune).to.not.have.been.called,
|
|
|
|
|
expect(packagerMock.runScripts).to.not.have.been.called,
|
|
|
|
|
]));
|
|
|
|
|
});
|
|
|
|
|
|
2018-05-03 12:59:38 +02:00
|
|
|
it('should ignore aws-sdk if set only in devDependencies', () => {
|
|
|
|
|
module.configuration = new Configuration({
|
|
|
|
|
webpack: {
|
|
|
|
|
includeModules: {
|
|
|
|
|
packagePath: path.join('ignoreDevDeps', 'package.json')
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
module.webpackOutputPath = 'outputPath';
|
|
|
|
|
fsExtraMock.pathExists.yields(null, false);
|
|
|
|
|
fsExtraMock.copy.yields();
|
|
|
|
|
packagerMock.getProdDependencies.returns(BbPromise.resolve({}));
|
|
|
|
|
packagerMock.install.returns(BbPromise.resolve());
|
|
|
|
|
packagerMock.prune.returns(BbPromise.resolve());
|
|
|
|
|
packagerMock.runScripts.returns(BbPromise.resolve());
|
|
|
|
|
module.compileStats = statsWithIgnoredDevDependency;
|
|
|
|
|
mockery.registerMock(path.join(process.cwd(), 'ignoreDevDeps', 'package.json'), packageIgnoredDevDepsMock);
|
|
|
|
|
return expect(module.packExternalModules()).to.be.fulfilled
|
|
|
|
|
.then(() => BbPromise.all([
|
2018-05-16 10:09:22 +02:00
|
|
|
expect(module.serverless.cli.log).to.have.been.calledWith(sinon.match(/INFO: Runtime dependency 'aws-sdk' found in devDependencies/)),
|
2018-05-03 12:59:38 +02:00
|
|
|
// npm ls and npm install should have been called
|
|
|
|
|
expect(packagerMock.getProdDependencies).to.have.been.calledOnce,
|
|
|
|
|
expect(packagerMock.install).to.have.been.calledOnce,
|
|
|
|
|
expect(packagerMock.prune).to.have.been.calledOnce,
|
|
|
|
|
expect(packagerMock.runScripts).to.have.been.calledOnce,
|
|
|
|
|
]));
|
|
|
|
|
});
|
|
|
|
|
|
2018-05-02 12:37:04 +02:00
|
|
|
it('should succeed if devDependency is required at runtime but forcefully excluded', () => {
|
|
|
|
|
module.configuration = new Configuration({
|
|
|
|
|
webpack: {
|
|
|
|
|
includeModules: {
|
|
|
|
|
forceExclude: ['eslint']
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
module.webpackOutputPath = 'outputPath';
|
|
|
|
|
fsExtraMock.pathExists.yields(null, false);
|
|
|
|
|
fsExtraMock.copy.yields();
|
|
|
|
|
packagerMock.getProdDependencies.returns(BbPromise.resolve({}));
|
|
|
|
|
packagerMock.install.returns(BbPromise.resolve());
|
|
|
|
|
packagerMock.prune.returns(BbPromise.resolve());
|
|
|
|
|
packagerMock.runScripts.returns(BbPromise.resolve());
|
|
|
|
|
module.compileStats = statsWithDevDependency;
|
|
|
|
|
return expect(module.packExternalModules()).to.be.fulfilled
|
|
|
|
|
.then(() => BbPromise.all([
|
|
|
|
|
// npm ls and npm install should have been called
|
|
|
|
|
expect(packagerMock.getProdDependencies).to.have.been.calledOnce,
|
|
|
|
|
expect(packagerMock.install).to.have.been.calledOnce,
|
2018-02-28 18:49:19 +01:00
|
|
|
expect(packagerMock.prune).to.have.been.calledOnce,
|
2018-03-09 18:59:12 +01:00
|
|
|
expect(packagerMock.runScripts).to.have.been.calledOnce,
|
2017-10-03 15:36:27 +02:00
|
|
|
]));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should read package-lock if found', () => {
|
|
|
|
|
const expectedCompositePackageJSON = {
|
|
|
|
|
name: 'test-service',
|
|
|
|
|
version: '1.0.0',
|
|
|
|
|
description: 'Packaged externals for test-service',
|
|
|
|
|
private: true,
|
2018-03-09 18:59:12 +01:00
|
|
|
scripts: {},
|
2017-10-03 15:36:27 +02:00
|
|
|
dependencies: {
|
|
|
|
|
'@scoped/vendor': '1.0.0',
|
|
|
|
|
uuid: '^5.4.1',
|
|
|
|
|
bluebird: '^3.4.0'
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
const expectedPackageJSON = {
|
2018-03-09 18:59:12 +01:00
|
|
|
name: 'test-service',
|
|
|
|
|
version: '1.0.0',
|
|
|
|
|
description: 'Packaged externals for test-service',
|
|
|
|
|
private: true,
|
|
|
|
|
scripts: {},
|
2017-10-03 15:36:27 +02:00
|
|
|
dependencies: {
|
|
|
|
|
'@scoped/vendor': '1.0.0',
|
|
|
|
|
uuid: '^5.4.1',
|
|
|
|
|
bluebird: '^3.4.0'
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
module.webpackOutputPath = 'outputPath';
|
|
|
|
|
fsExtraMock.pathExists.yields(null, true);
|
|
|
|
|
fsExtraMock.copy.yields();
|
2018-04-30 11:27:18 +02:00
|
|
|
readFileSyncStub.onFirstCall().returns(packageMock);
|
2018-02-28 18:49:19 +01:00
|
|
|
readFileSyncStub.returns({ info: 'lockfile' });
|
|
|
|
|
packagerMock.rebaseLockfile.callsFake((pathToPackageRoot, lockfile) => lockfile);
|
|
|
|
|
packagerMock.getProdDependencies.returns(BbPromise.resolve({}));
|
|
|
|
|
packagerMock.install.returns(BbPromise.resolve());
|
|
|
|
|
packagerMock.prune.returns(BbPromise.resolve());
|
2018-03-09 18:59:12 +01:00
|
|
|
packagerMock.runScripts.returns(BbPromise.resolve());
|
2017-10-23 07:29:17 -06:00
|
|
|
module.compileStats = stats;
|
|
|
|
|
return expect(module.packExternalModules()).to.be.fulfilled
|
2017-10-03 15:36:27 +02:00
|
|
|
.then(() => BbPromise.all([
|
|
|
|
|
// The module package JSON and the composite one should have been stored
|
2018-02-28 18:49:19 +01:00
|
|
|
expect(writeFileSyncStub).to.have.been.calledThrice,
|
2017-10-03 15:36:27 +02:00
|
|
|
expect(writeFileSyncStub.firstCall.args[1]).to.equal(JSON.stringify(expectedCompositePackageJSON, null, 2)),
|
2018-02-28 18:49:19 +01:00
|
|
|
expect(writeFileSyncStub.secondCall.args[1]).to.equal(JSON.stringify({ info: 'lockfile' }, null, 2)),
|
|
|
|
|
expect(writeFileSyncStub.thirdCall.args[1]).to.equal(JSON.stringify(expectedPackageJSON, null, 2)),
|
2018-03-08 02:57:03 +01:00
|
|
|
// The modules and the lock file should have been copied
|
|
|
|
|
expect(fsExtraMock.copy).to.have.been.calledTwice,
|
2017-10-03 15:36:27 +02:00
|
|
|
// npm ls and npm prune should have been called
|
2018-02-28 18:49:19 +01:00
|
|
|
expect(packagerMock.getProdDependencies).to.have.been.calledOnce,
|
|
|
|
|
expect(packagerMock.install).to.have.been.calledOnce,
|
|
|
|
|
expect(packagerMock.prune).to.have.been.calledOnce,
|
2018-03-09 18:59:12 +01:00
|
|
|
expect(packagerMock.runScripts).to.have.been.calledOnce,
|
2017-10-03 15:36:27 +02:00
|
|
|
]));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should continue if package-lock cannot be read', () => {
|
|
|
|
|
const expectedCompositePackageJSON = {
|
|
|
|
|
name: 'test-service',
|
|
|
|
|
version: '1.0.0',
|
|
|
|
|
description: 'Packaged externals for test-service',
|
|
|
|
|
private: true,
|
2018-03-09 18:59:12 +01:00
|
|
|
scripts: {},
|
2017-10-03 15:36:27 +02:00
|
|
|
dependencies: {
|
|
|
|
|
'@scoped/vendor': '1.0.0',
|
|
|
|
|
uuid: '^5.4.1',
|
|
|
|
|
bluebird: '^3.4.0'
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
const expectedPackageJSON = {
|
2018-03-09 18:59:12 +01:00
|
|
|
name: 'test-service',
|
|
|
|
|
version: '1.0.0',
|
|
|
|
|
description: 'Packaged externals for test-service',
|
|
|
|
|
private: true,
|
|
|
|
|
scripts: {},
|
2017-10-03 15:36:27 +02:00
|
|
|
dependencies: {
|
|
|
|
|
'@scoped/vendor': '1.0.0',
|
|
|
|
|
uuid: '^5.4.1',
|
|
|
|
|
bluebird: '^3.4.0'
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
module.webpackOutputPath = 'outputPath';
|
2018-04-30 11:27:18 +02:00
|
|
|
readFileSyncStub.onFirstCall().returns(packageMock);
|
2017-12-18 13:52:03 -02:00
|
|
|
readFileSyncStub.throws(new Error('Failed to read package-lock.json'));
|
2017-10-03 15:36:27 +02:00
|
|
|
fsExtraMock.pathExists.yields(null, true);
|
2017-12-18 13:52:03 -02:00
|
|
|
fsExtraMock.copy.onFirstCall().yields();
|
2018-02-28 18:49:19 +01:00
|
|
|
packagerMock.getProdDependencies.returns(BbPromise.resolve({}));
|
|
|
|
|
packagerMock.install.returns(BbPromise.resolve());
|
|
|
|
|
packagerMock.prune.returns(BbPromise.resolve());
|
2018-03-09 18:59:12 +01:00
|
|
|
packagerMock.runScripts.returns(BbPromise.resolve());
|
2017-10-23 07:29:17 -06:00
|
|
|
module.compileStats = stats;
|
|
|
|
|
return expect(module.packExternalModules()).to.be.fulfilled
|
2017-10-03 15:36:27 +02:00
|
|
|
.then(() => BbPromise.all([
|
|
|
|
|
// The module package JSON and the composite one should have been stored
|
|
|
|
|
expect(writeFileSyncStub).to.have.been.calledTwice,
|
|
|
|
|
expect(writeFileSyncStub.firstCall.args[1]).to.equal(JSON.stringify(expectedCompositePackageJSON, null, 2)),
|
|
|
|
|
expect(writeFileSyncStub.secondCall.args[1]).to.equal(JSON.stringify(expectedPackageJSON, null, 2)),
|
|
|
|
|
// The modules should have been copied
|
2017-12-18 13:52:03 -02:00
|
|
|
expect(fsExtraMock.copy).to.have.been.calledOnce,
|
2017-10-03 15:36:27 +02:00
|
|
|
// npm ls and npm prune should have been called
|
2018-02-28 18:49:19 +01:00
|
|
|
expect(packagerMock.getProdDependencies).to.have.been.calledOnce,
|
|
|
|
|
expect(packagerMock.install).to.have.been.calledOnce,
|
|
|
|
|
expect(packagerMock.prune).to.have.been.calledOnce,
|
2018-03-09 18:59:12 +01:00
|
|
|
expect(packagerMock.runScripts).to.have.been.calledOnce,
|
2017-09-19 12:47:56 +02:00
|
|
|
]));
|
|
|
|
|
});
|
2017-09-21 11:58:53 +02:00
|
|
|
|
2018-03-08 02:57:03 +01:00
|
|
|
it('should skip module copy if demanded by packager', () => {
|
|
|
|
|
const expectedCompositePackageJSON = {
|
|
|
|
|
name: 'test-service',
|
|
|
|
|
version: '1.0.0',
|
|
|
|
|
description: 'Packaged externals for test-service',
|
|
|
|
|
private: true,
|
2018-03-09 18:59:12 +01:00
|
|
|
scripts: {},
|
2018-03-08 02:57:03 +01:00
|
|
|
dependencies: {
|
|
|
|
|
'@scoped/vendor': '1.0.0',
|
|
|
|
|
uuid: '^5.4.1',
|
|
|
|
|
bluebird: '^3.4.0'
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
const expectedPackageJSON = {
|
2018-03-09 18:59:12 +01:00
|
|
|
name: 'test-service',
|
|
|
|
|
version: '1.0.0',
|
|
|
|
|
description: 'Packaged externals for test-service',
|
|
|
|
|
private: true,
|
|
|
|
|
scripts: {},
|
2018-03-08 02:57:03 +01:00
|
|
|
dependencies: {
|
|
|
|
|
'@scoped/vendor': '1.0.0',
|
|
|
|
|
uuid: '^5.4.1',
|
|
|
|
|
bluebird: '^3.4.0'
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
module.webpackOutputPath = 'outputPath';
|
|
|
|
|
fsExtraMock.pathExists.yields(null, false);
|
|
|
|
|
fsExtraMock.copy.onFirstCall().yields();
|
|
|
|
|
packagerMock.getProdDependencies.returns(BbPromise.resolve({}));
|
|
|
|
|
packagerMock.install.returns(BbPromise.resolve());
|
|
|
|
|
packagerMock.prune.returns(BbPromise.resolve());
|
2018-03-09 18:59:12 +01:00
|
|
|
packagerMock.runScripts.returns(BbPromise.resolve());
|
2018-03-08 02:57:03 +01:00
|
|
|
packagerMock.mustCopyModules = false;
|
|
|
|
|
module.compileStats = stats;
|
|
|
|
|
return expect(module.packExternalModules()).to.be.fulfilled
|
|
|
|
|
.then(() => BbPromise.all([
|
|
|
|
|
// The module package JSON and the composite one should have been stored
|
|
|
|
|
expect(writeFileSyncStub).to.have.been.calledTwice,
|
|
|
|
|
expect(writeFileSyncStub.firstCall.args[1]).to.equal(JSON.stringify(expectedCompositePackageJSON, null, 2)),
|
|
|
|
|
expect(writeFileSyncStub.secondCall.args[1]).to.equal(JSON.stringify(expectedPackageJSON, null, 2)),
|
|
|
|
|
// The modules should not have been copied
|
|
|
|
|
expect(fsExtraMock.copy).to.not.have.been.called,
|
|
|
|
|
// npm ls and npm prune should have been called
|
|
|
|
|
expect(packagerMock.getProdDependencies).to.have.been.calledOnce,
|
|
|
|
|
expect(packagerMock.install).to.have.been.calledOnce,
|
|
|
|
|
expect(packagerMock.prune).to.have.been.calledOnce,
|
2018-03-09 18:59:12 +01:00
|
|
|
expect(packagerMock.runScripts).to.have.been.calledOnce,
|
2018-03-08 02:57:03 +01:00
|
|
|
]))
|
|
|
|
|
.finally(() => {
|
|
|
|
|
packagerMock.mustCopyModules = true;
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2017-09-21 11:58:53 +02:00
|
|
|
describe('peer dependencies', () => {
|
|
|
|
|
before(() => {
|
|
|
|
|
const peerDepPackageJson = require('./data/package-peerdeps.json');
|
|
|
|
|
mockery.deregisterMock(path.join(process.cwd(), 'package.json'));
|
|
|
|
|
mockery.registerMock(path.join(process.cwd(), 'package.json'), peerDepPackageJson);
|
|
|
|
|
// Mock request-promise package.json
|
|
|
|
|
const rpPackageJson = require('./data/rp-package.json');
|
|
|
|
|
const rpPackagePath = path.join(
|
|
|
|
|
process.cwd(),
|
|
|
|
|
'node_modules',
|
|
|
|
|
'request-promise',
|
|
|
|
|
'package.json'
|
|
|
|
|
);
|
|
|
|
|
mockery.registerMock(rpPackagePath, rpPackageJson);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
after(() => {
|
|
|
|
|
mockery.deregisterMock(path.join(process.cwd(), 'package.json'));
|
|
|
|
|
mockery.registerMock(path.join(process.cwd(), 'package.json'), packageMock);
|
|
|
|
|
const rpPackagePath = path.join(
|
|
|
|
|
process.cwd(),
|
|
|
|
|
'node_modules',
|
|
|
|
|
'request-promise',
|
|
|
|
|
'package.json'
|
|
|
|
|
);
|
|
|
|
|
mockery.deregisterMock(rpPackagePath);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should install external peer dependencies', () => {
|
2017-10-03 15:36:27 +02:00
|
|
|
const expectedCompositePackageJSON = {
|
|
|
|
|
name: 'test-service',
|
|
|
|
|
version: '1.0.0',
|
|
|
|
|
description: 'Packaged externals for test-service',
|
|
|
|
|
private: true,
|
2018-03-09 18:59:12 +01:00
|
|
|
scripts: {},
|
2017-10-03 15:36:27 +02:00
|
|
|
dependencies: {
|
|
|
|
|
bluebird: '^3.5.0',
|
|
|
|
|
'request-promise': '^4.2.1',
|
|
|
|
|
request: '^2.82.0'
|
|
|
|
|
}
|
|
|
|
|
};
|
2017-09-21 11:58:53 +02:00
|
|
|
const expectedPackageJSON = {
|
2018-03-09 18:59:12 +01:00
|
|
|
name: 'test-service',
|
|
|
|
|
version: '1.0.0',
|
|
|
|
|
description: 'Packaged externals for test-service',
|
|
|
|
|
private: true,
|
|
|
|
|
scripts: {},
|
2017-09-21 11:58:53 +02:00
|
|
|
dependencies: {
|
|
|
|
|
bluebird: '^3.5.0',
|
|
|
|
|
'request-promise': '^4.2.1',
|
|
|
|
|
request: '^2.82.0'
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const dependencyGraph = require('./data/npm-ls-peerdeps.json');
|
2018-02-26 04:50:51 -05:00
|
|
|
const peerDepStats = {
|
|
|
|
|
stats: [
|
|
|
|
|
{
|
|
|
|
|
compilation: {
|
|
|
|
|
chunks: [
|
|
|
|
|
new ChunkMock([
|
|
|
|
|
{
|
|
|
|
|
identifier: _.constant('"crypto"')
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
identifier: _.constant('"uuid/v4"')
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
identifier: _.constant('"mockery"')
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
identifier: _.constant('"@scoped/vendor/module1"')
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
identifier: _.constant('external "bluebird"')
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
identifier: _.constant('external "request-promise"')
|
|
|
|
|
}
|
|
|
|
|
])
|
|
|
|
|
],
|
|
|
|
|
compiler: {
|
|
|
|
|
outputPath: '/my/Service/Path/.webpack/service'
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
};
|
2017-09-21 11:58:53 +02:00
|
|
|
|
|
|
|
|
module.webpackOutputPath = 'outputPath';
|
2017-10-03 15:36:27 +02:00
|
|
|
fsExtraMock.pathExists.yields(null, false);
|
2017-09-21 11:58:53 +02:00
|
|
|
fsExtraMock.copy.yields();
|
2018-02-28 18:49:19 +01:00
|
|
|
packagerMock.getProdDependencies.returns(BbPromise.resolve(dependencyGraph));
|
|
|
|
|
packagerMock.install.returns(BbPromise.resolve());
|
|
|
|
|
packagerMock.prune.returns(BbPromise.resolve());
|
2018-03-09 18:59:12 +01:00
|
|
|
packagerMock.runScripts.returns(BbPromise.resolve());
|
2017-10-23 07:29:17 -06:00
|
|
|
module.compileStats = peerDepStats;
|
|
|
|
|
return expect(module.packExternalModules()).to.be.fulfilled
|
2017-09-21 11:58:53 +02:00
|
|
|
.then(() => BbPromise.all([
|
|
|
|
|
// The module package JSON and the composite one should have been stored
|
|
|
|
|
expect(writeFileSyncStub).to.have.been.calledTwice,
|
2017-10-03 15:36:27 +02:00
|
|
|
expect(writeFileSyncStub.firstCall.args[1]).to.equal(JSON.stringify(expectedCompositePackageJSON, null, 2)),
|
2017-09-21 11:58:53 +02:00
|
|
|
expect(writeFileSyncStub.secondCall.args[1]).to.equal(JSON.stringify(expectedPackageJSON, null, 2)),
|
|
|
|
|
// The modules should have been copied
|
|
|
|
|
expect(fsExtraMock.copy).to.have.been.calledOnce,
|
|
|
|
|
// npm ls and npm prune should have been called
|
2018-02-28 18:49:19 +01:00
|
|
|
expect(packagerMock.getProdDependencies).to.have.been.calledOnce,
|
|
|
|
|
expect(packagerMock.install).to.have.been.calledOnce,
|
|
|
|
|
expect(packagerMock.prune).to.have.been.calledOnce,
|
2018-03-09 18:59:12 +01:00
|
|
|
expect(packagerMock.runScripts).to.have.been.calledOnce,
|
2017-09-21 11:58:53 +02:00
|
|
|
]));
|
|
|
|
|
});
|
|
|
|
|
});
|
2017-08-05 01:20:38 +02:00
|
|
|
});
|
|
|
|
|
});
|