diff --git a/lib/builtins/build-flows/nodejs-npm.js b/lib/builtins/build-flows/nodejs-npm.js index d7715170..b4f9c8ce 100644 --- a/lib/builtins/build-flows/nodejs-npm.js +++ b/lib/builtins/build-flows/nodejs-npm.js @@ -26,8 +26,9 @@ class NodeJsNpmBuildFlow extends AbstractBuildFlow { * @param {String} options.buildFile full path for zip file to generate * @param {Boolean} options.doDebug debug flag */ - constructor({ cwd, src, buildFile, doDebug }) { + constructor({ cwd, src, buildFile, doDebug, noNPMInstall }) { super({ cwd, src, buildFile, doDebug }); + this.noNPMInstall = noNPMInstall; } /** @@ -37,9 +38,15 @@ class NodeJsNpmBuildFlow extends AbstractBuildFlow { execute(callback) { const installCmd = this._hasLockFile() ? 'ci' : 'install'; const quietFlag = this.doDebug ? '' : ' --quiet'; - this.env.NODE_ENV = 'production'; - this.debug(`Installing NodeJS dependencies based on the ${NodeJsNpmBuildFlow.manifest}.`); - this.execCommand(`npm ${installCmd}${quietFlag}`); + + if (this.noNPMInstall) { + this.debug('noNPMInstall flag is true. Skipping npm install.'); + } else { + this.env.NODE_ENV = 'production'; + this.debug(`Installing NodeJS dependencies based on the ${NodeJsNpmBuildFlow.manifest}.`); + this.execCommand(`npm ${installCmd}${quietFlag}`); + } + this.createZip(callback); } diff --git a/lib/commands/deploy/helper.js b/lib/commands/deploy/helper.js index ec9c242a..6391097e 100644 --- a/lib/commands/deploy/helper.js +++ b/lib/commands/deploy/helper.js @@ -51,11 +51,12 @@ function deploySkillMetadata(options, callback) { * Deploy skill code by calling SkillCodeController * @param {String} profile ask-cli profile * @param {Boolean} doDebug + * @param {Boolean} shouldDereferenceSymlinks If true, will copy symlinked files and folders into final build * @param {*} callback (error, uniqueCodeList) * @param {*} callback.uniqueCodeList [{ src, build{file, folder}}, buildFlow, regionsList }] */ -function buildSkillCode(profile, doDebug, callback) { - const skillCodeController = new SkillCodeController({ profile, doDebug }); +function buildSkillCode({ profile, doDebug, shouldDereferenceSymlinks, noNPMInstall }, callback) { + const skillCodeController = new SkillCodeController({ profile, doDebug, shouldDereferenceSymlinks, noNPMInstall }); skillCodeController.buildCode((buildErr, uniqueCodeList) => { if (buildErr) { return callback(buildErr); @@ -71,7 +72,7 @@ function buildSkillCode(profile, doDebug, callback) { * @param {Boolean} ignoreHash * @param {*} callback (error) */ -function deploySkillInfrastructure(profile, doDebug, ignoreHash, callback) { +function deploySkillInfrastructure({ profile, doDebug, ignoreHash }, callback) { const skillInfraController = new SkillInfrastructureController({ profile, doDebug, ignoreHash }); skillInfraController.deployInfrastructure((deployError) => { if (deployError) { @@ -87,7 +88,7 @@ function deploySkillInfrastructure(profile, doDebug, ignoreHash, callback) { * @param {Boolean} doDebug The flag of debug or not * @param {Function} callback */ -function enableSkill(profile, doDebug, callback) { +function enableSkill({ profile, doDebug }, callback) { const skillMetaController = new SkillMetadataController({ profile, doDebug }); Messenger.getInstance().info('\n==================== Enable Skill ===================='); try { diff --git a/lib/commands/deploy/index.js b/lib/commands/deploy/index.js index 8c2eb3bc..14500a37 100644 --- a/lib/commands/deploy/index.js +++ b/lib/commands/deploy/index.js @@ -30,7 +30,7 @@ class DeployCommand extends AbstractCommand { } optionalOptions() { - return ['ignore-hash', 'target', 'profile', 'debug']; + return ['ignore-hash', 'target', 'profile', 'debug', 'dereference-symlinks', 'no-npm-install']; } handle(cmd, cb) { @@ -62,7 +62,14 @@ class DeployCommand extends AbstractCommand { return cb(new CliError(errMessage)); } - const options = { profile, doDebug: cmd.debug, ignoreHash: cmd.ignoreHash, target: cmd.target }; + const options = { + profile, + doDebug: cmd.debug, + ignoreHash: cmd.ignoreHash, + target: cmd.target, + shouldDereferenceSymlinks: !!cmd.dereferenceSymlinks, + noNPMInstall: !cmd.npmInstall + }; deployResources(options, (deployErr) => { // Write updates back to resources file if (deployErr) { @@ -80,7 +87,7 @@ class DeployCommand extends AbstractCommand { } // Post deploy logic // call smapiClient to enable skill - helper.enableSkill(profile, cmd.debug, (enableError) => { + helper.enableSkill({ profile, doDebug: cmd.debug }, (enableError) => { if (enableError instanceof CliWarn) { Messenger.getInstance().warn(enableError); return cb(); @@ -123,10 +130,11 @@ class DeployCommand extends AbstractCommand { * @param {String} profile The profile name * @param {Boolean} doDebug The flag of debug or not * @param {Boolean} ignoreHash The flag to ignore difference between local and remote version + * @param {Boolean} shouldDereferenceSymlinks If true, will copy symlinked files and folders into final build * @param {Function} callback */ function deployResources(options, callback) { - const { profile, doDebug, target, ignoreHash } = options; + const { profile, doDebug, target, ignoreHash, shouldDereferenceSymlinks, noNPMInstall } = options; _deploySkillMetadata(options, (err) => { if (err) { return callback(err); @@ -148,7 +156,7 @@ function deployResources(options, callback) { return callback(); } Messenger.getInstance().info('\n==================== Build Skill Code ===================='); - helper.buildSkillCode(profile, doDebug, (buildErr, uniqueCodeList) => { + helper.buildSkillCode({ profile, doDebug, shouldDereferenceSymlinks, noNPMInstall }, (buildErr, uniqueCodeList) => { if (buildErr) { return callback(buildErr); } @@ -165,7 +173,7 @@ with build flow ${codeProperty.buildFlow}.`); return callback(); } Messenger.getInstance().info('\n==================== Deploy Skill Infrastructure ===================='); - helper.deploySkillInfrastructure(profile, doDebug, ignoreHash, (infraErr) => { + helper.deploySkillInfrastructure({ profile, doDebug, ignoreHash }, (infraErr) => { if (infraErr) { return callback(infraErr); } diff --git a/lib/commands/option-model.json b/lib/commands/option-model.json index 5538ad9a..e01ea40b 100644 --- a/lib/commands/option-model.json +++ b/lib/commands/option-model.json @@ -200,5 +200,15 @@ "name": "watch", "description": "Uses nodemon to monitor changes and automatically restart the run session.", "stringInput": "NONE" + }, + "dereference-symlinks": { + "name": "dereference-symlinks", + "description": "Copies symlinked files from code source as actual files instead of symlinks", + "stringInput": "NONE" + }, + "no-npm-install": { + "name": "no-npm-install", + "description": "Skips running `npm install` before deploying code", + "stringInput": "NONE" } } diff --git a/lib/controllers/skill-code-controller/code-builder.js b/lib/controllers/skill-code-controller/code-builder.js index f86c49cc..af3822de 100644 --- a/lib/controllers/skill-code-controller/code-builder.js +++ b/lib/controllers/skill-code-controller/code-builder.js @@ -19,12 +19,14 @@ const BUILD_FLOWS = [ class CodeBuilder { /** * Constructor for CodeBuilder - * @param {Object} config { src, build, doDebug }, where build = { folder, file }. + * @param {Object} config { src, build, shouldDereferenceSymlinks, noNPMInstall, doDebug }, where build = { folder, file }. */ constructor(config) { - const { src, build, doDebug } = config; + const { src, build, shouldDereferenceSymlinks, noNPMInstall, doDebug } = config; this.src = src; this.build = build; + this.shouldDereferenceSymlinks = shouldDereferenceSymlinks || false; + this.noNPMInstall = noNPMInstall || false; this.doDebug = doDebug; this.BuildFlowClass = {}; this._selectBuildFlowClass(); @@ -40,7 +42,7 @@ class CodeBuilder { } catch (fsErr) { return process.nextTick(callback(fsErr)); } - const options = { cwd: this.build.folder, src: this.src, buildFile: this.build.file, doDebug: this.doDebug }; + const options = { cwd: this.build.folder, src: this.src, buildFile: this.build.file, doDebug: this.doDebug, noNPMInstall: this.noNPMInstall }; const builder = new this.BuildFlowClass(options); builder.execute((error) => callback(error)); } @@ -48,7 +50,10 @@ class CodeBuilder { _setUpBuildFolder() { fs.ensureDirSync(this.build.folder); fs.emptyDirSync(this.build.folder); - fs.copySync(path.resolve(this.src), this.build.folder, { filter: src => !src.includes(this.build.folder) }); + fs.copySync(path.resolve(this.src), this.build.folder, { + filter: src => !src.includes(this.build.folder), + dereference: this.shouldDereferenceSymlinks + }); } _selectBuildFlowClass() { diff --git a/lib/controllers/skill-code-controller/index.js b/lib/controllers/skill-code-controller/index.js index fa54c687..b6001a25 100644 --- a/lib/controllers/skill-code-controller/index.js +++ b/lib/controllers/skill-code-controller/index.js @@ -11,8 +11,10 @@ module.exports = class SkillCodeController { * @param {Object} configuration { profile, doDebug } */ constructor(configuration) { - const { profile, doDebug } = configuration; + const { profile, doDebug, shouldDereferenceSymlinks, noNPMInstall } = configuration; this.profile = profile; + this.shouldDereferenceSymlinks = shouldDereferenceSymlinks; + this.noNPMInstall = noNPMInstall; this.doDebug = doDebug; } @@ -33,6 +35,8 @@ module.exports = class SkillCodeController { const codeBuilder = new CodeBuilder({ src: codeProperty.src, build: codeProperty.build, + shouldDereferenceSymlinks: this.shouldDereferenceSymlinks, + noNPMInstall: this.noNPMInstall, doDebug: this.doDebug }); codeProperty.buildFlow = codeBuilder.BuildFlowClass.name; diff --git a/test/integration/code-builder/code-builder-test.js b/test/integration/code-builder/code-builder-test.js index a7cd568a..84e2e707 100644 --- a/test/integration/code-builder/code-builder-test.js +++ b/test/integration/code-builder/code-builder-test.js @@ -125,6 +125,53 @@ describe('code builder test', () => { }); }); + it('| should dereference symlinked files into build', (done) => { + const sourceDirName = 'with-symlinks'; + const config = setUpTempFolder(sourceDirName); + const sourceDir = path.join(fixturesDirectory, sourceDirName); + sinon.stub(process, 'cwd').returns(sourceDir); + + config.shouldDereferenceSymlinks = true; + const codeBuilder = new CodeBuilder(config); + + codeBuilder.execute((err, res) => { + expect(err).eql(null); + expect(res).eql(undefined); + expect(fs.lstatSync(path.join(config.build.folder, 'symlinked-folder', 'symlinked-file.js')).isSymbolicLink()).eq(false); + done(); + }); + }); + + it('| should NOT dereference symlinked files into build', (done) => { + const sourceDirName = 'with-symlinks'; + const config = setUpTempFolder(sourceDirName); + const sourceDir = path.join(fixturesDirectory, sourceDirName); + sinon.stub(process, 'cwd').returns(sourceDir); + + const codeBuilder = new CodeBuilder(config); + + codeBuilder.execute((err, res) => { + expect(err).eql(null); + expect(res).eql(undefined); + expect(fs.lstatSync(path.join(config.build.folder, 'symlinked-folder', 'symlinked-file.js')).isSymbolicLink()).eq(false); + done(); + }); + }); + + it('| should NOT run NPM install if this is an NPM project and noNPMInstall is true', (done) => { + const config = setUpTempFolder('nodejs-npm'); + + config.noNPMInstall = true; + const codeBuilder = new CodeBuilder(config); + + codeBuilder.execute((err, res) => { + expect(err).eql(null); + expect(res).eql(undefined); + expect(() => fs.statSync(path.join(config.build.folder, 'node_modules'))).to.throw(); + done(); + }); + }); + afterEach(() => { sinon.restore(); }); diff --git a/test/integration/fixtures/code-builder/symlinked-folder/symlinked-file.js b/test/integration/fixtures/code-builder/symlinked-folder/symlinked-file.js new file mode 100644 index 00000000..ff4ec9c3 --- /dev/null +++ b/test/integration/fixtures/code-builder/symlinked-folder/symlinked-file.js @@ -0,0 +1 @@ +console.log('symlinked file'); \ No newline at end of file diff --git a/test/integration/fixtures/code-builder/with-symlinks/lambda/index.js b/test/integration/fixtures/code-builder/with-symlinks/lambda/index.js new file mode 100644 index 00000000..f7991b44 --- /dev/null +++ b/test/integration/fixtures/code-builder/with-symlinks/lambda/index.js @@ -0,0 +1 @@ +console.log('node lambda code'); diff --git a/test/integration/fixtures/code-builder/with-symlinks/lambda/package.json b/test/integration/fixtures/code-builder/with-symlinks/lambda/package.json new file mode 100644 index 00000000..55763134 --- /dev/null +++ b/test/integration/fixtures/code-builder/with-symlinks/lambda/package.json @@ -0,0 +1,14 @@ +{ + "name": "hello-world", + "version": "1.1.0", + "description": "test", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "Amazon Alexa", + "license": "ISC", + "dependencies": { + "ask-sdk-core": "^2.6.0" + } +} diff --git a/test/unit/commands/deploy/helper-test.js b/test/unit/commands/deploy/helper-test.js index 562241ea..60d71c56 100644 --- a/test/unit/commands/deploy/helper-test.js +++ b/test/unit/commands/deploy/helper-test.js @@ -16,6 +16,8 @@ describe('Commands deploy test - helper test', () => { const TEST_IGNORE_HASH = false; const TEST_VENDOR_ID = 'vendor'; const TEST_DO_DEBUG = false; + const TEST_SHOULD_DEREFERENCE_SYMLINKS = true; + const TEST_NO_NPM_INSTALL = false; const TEST_OPTIONS = { profile: TEST_PROFILE, doDebug: TEST_DO_DEBUG, ignoreHash: TEST_IGNORE_HASH }; describe('# test helper method - confirmProfile', () => { @@ -97,7 +99,12 @@ describe('Commands deploy test - helper test', () => { // setup sinon.stub(SkillCodeController.prototype, 'buildCode').callsArgWith(0, 'error'); // call - helper.buildSkillCode(TEST_PROFILE, TEST_DO_DEBUG, (err, res) => { + helper.buildSkillCode({ + profile: TEST_PROFILE, + doDebug: TEST_DO_DEBUG, + shouldDereferenceSymlinks: TEST_SHOULD_DEREFERENCE_SYMLINKS, + noNPMInstall: TEST_NO_NPM_INSTALL + }, (err, res) => { // verify expect(err).equal('error'); expect(res).equal(undefined); @@ -109,7 +116,12 @@ describe('Commands deploy test - helper test', () => { // setup sinon.stub(SkillCodeController.prototype, 'buildCode').callsArgWith(0); // call - helper.buildSkillCode(TEST_PROFILE, TEST_DO_DEBUG, (err, res) => { + helper.buildSkillCode({ + profile: TEST_PROFILE, + doDebug: TEST_DO_DEBUG, + shouldDereferenceSymlinks: TEST_SHOULD_DEREFERENCE_SYMLINKS, + noNPMInstall: TEST_NO_NPM_INSTALL + }, (err, res) => { // verify expect(err).equal(null); expect(res).equal(undefined); @@ -127,7 +139,7 @@ describe('Commands deploy test - helper test', () => { // setup sinon.stub(SkillInfrastructureController.prototype, 'deployInfrastructure').callsArgWith(0, 'error'); // call - helper.deploySkillInfrastructure(TEST_PROFILE, TEST_DO_DEBUG, TEST_IGNORE_HASH, (err, res) => { + helper.deploySkillInfrastructure({ profile: TEST_PROFILE, doDebug: TEST_DO_DEBUG, ignoreHash: TEST_IGNORE_HASH }, (err, res) => { // verify expect(err).equal('error'); expect(res).equal(undefined); @@ -139,7 +151,7 @@ describe('Commands deploy test - helper test', () => { // setup sinon.stub(SkillInfrastructureController.prototype, 'deployInfrastructure').callsArgWith(0); // call - helper.deploySkillInfrastructure(TEST_PROFILE, TEST_DO_DEBUG, TEST_IGNORE_HASH, (err, res) => { + helper.deploySkillInfrastructure({ profile: TEST_PROFILE, doDebug: TEST_DO_DEBUG, ignoreHash: TEST_IGNORE_HASH }, (err, res) => { // verify expect(err).equal(undefined); expect(res).equal(undefined); @@ -165,7 +177,7 @@ describe('Commands deploy test - helper test', () => { // setup sinon.stub(SkillMetadataController.prototype, 'enableSkill').callsArgWith(0, 'error'); // call - helper.enableSkill(TEST_PROFILE, TEST_DO_DEBUG, (err) => { + helper.enableSkill({ profile: TEST_PROFILE, doDebug: TEST_DO_DEBUG }, (err) => { expect(err).equal('error'); expect(infoStub.args[0][0]).equal('\n==================== Enable Skill ===================='); done(); @@ -176,7 +188,7 @@ describe('Commands deploy test - helper test', () => { // setup sinon.stub(SkillMetadataController.prototype, 'validateDomain').throws('test-error'); // call - helper.enableSkill(TEST_PROFILE, TEST_DO_DEBUG, (err) => { + helper.enableSkill({ profile: TEST_PROFILE, doDebug: TEST_DO_DEBUG }, (err) => { expect(err.name).equal('test-error'); expect(infoStub.args[0][0]).equal('\n==================== Enable Skill ===================='); done(); @@ -187,7 +199,7 @@ describe('Commands deploy test - helper test', () => { // setup sinon.stub(SkillMetadataController.prototype, 'enableSkill').callsArgWith(0); // call - helper.enableSkill(TEST_PROFILE, TEST_DO_DEBUG, (err, res) => { + helper.enableSkill({ profile: TEST_PROFILE, doDebug: TEST_DO_DEBUG }, (err, res) => { // verify expect(err).equal(undefined); expect(res).equal(undefined); diff --git a/test/unit/commands/deploy/index-test.js b/test/unit/commands/deploy/index-test.js index a8cd8704..9e1d6a6a 100644 --- a/test/unit/commands/deploy/index-test.js +++ b/test/unit/commands/deploy/index-test.js @@ -45,7 +45,7 @@ describe('Commands deploy test - command class test', () => { expect(instance.name()).equal('deploy'); expect(instance.description()).equal('deploy the skill project'); expect(instance.requiredOptions()).deep.equal([]); - expect(instance.optionalOptions()).deep.equal(['ignore-hash', 'target', 'profile', 'debug']); + expect(instance.optionalOptions()).deep.equal(['ignore-hash', 'target', 'profile', 'debug', 'dereference-symlinks', 'no-npm-install']); }); describe('validate command handle', () => { @@ -187,7 +187,7 @@ describe('Commands deploy test - command class test', () => { sinon.stub(helper, 'deploySkillMetadata').callsArgWith(1, 'The hash of current skill package folder does not change compared to the last deploy hash result, ' + 'CLI will skip the deploy of skill package.'); - sinon.stub(helper, 'buildSkillCode').callsArgWith(2, 'error'); + sinon.stub(helper, 'buildSkillCode').callsArgWith(1, 'error'); // call instance.handle(TEST_CMD, (err) => { // verify @@ -206,7 +206,7 @@ describe('Commands deploy test - command class test', () => { 'The hash of current skill package folder does not change compared to the last deploy hash result, ' + 'CLI will skip the deploy of skill package.'); sinon.stub(ResourcesConfig.prototype, 'getCodeRegions').returns([]); - sinon.stub(helper, 'enableSkill').callsArgWith(2); + sinon.stub(helper, 'enableSkill').callsArgWith(1); // call instance.handle(TEST_CMD, (err) => { // verify @@ -222,7 +222,7 @@ describe('Commands deploy test - command class test', () => { it('| helper deploy skill with skill metadata target, expect skip deploy metadata and skip build and infra deploy', (done) => { // setup sinon.stub(helper, 'deploySkillMetadata').callsArgWith(1); - sinon.stub(helper, 'enableSkill').callsArgWith(2); + sinon.stub(helper, 'enableSkill').callsArgWith(1); const cmd = { ...TEST_CMD, target: CONSTANTS.DEPLOY_TARGET.SKILL_METADATA }; // call @@ -260,7 +260,7 @@ describe('Commands deploy test - command class test', () => { it('| helper build skill code fails, expect throw error', (done) => { // setup sinon.stub(helper, 'deploySkillMetadata').callsArgWith(1); - sinon.stub(helper, 'buildSkillCode').callsArgWith(2, 'error'); + sinon.stub(helper, 'buildSkillCode').callsArgWith(1, 'error'); // call instance.handle(TEST_CMD, (err) => { // verify @@ -295,9 +295,9 @@ describe('Commands deploy test - command class test', () => { it('| helper deploy skill infra without infraType, expect skip the flow by calling back', (done) => { // setup sinon.stub(helper, 'deploySkillMetadata').callsArgWith(1); - sinon.stub(helper, 'buildSkillCode').callsArgWith(2, null, TEST_CODE_BUILD_RESULT); - sinon.stub(helper, 'deploySkillInfrastructure').callsArgWith(2, 'error'); - sinon.stub(helper, 'enableSkill').callsArgWith(2); + sinon.stub(helper, 'buildSkillCode').callsArgWith(1, null, TEST_CODE_BUILD_RESULT); + sinon.stub(helper, 'deploySkillInfrastructure').callsArgWith(1, 'error'); + sinon.stub(helper, 'enableSkill').callsArgWith(1); sinon.stub(stringUtils, 'isNonBlankString').returns(true); stringUtils.isNonBlankString.withArgs('@ask-cli/cfn-deployer').returns(false); sinon.stub(path, 'resolve').returns(TEST_CODE_SRC_BASENAME); @@ -325,9 +325,9 @@ with build flow ${TEST_CODE_BUILD_RESULT[0].buildFlow}.`); it('| helper deploy skill with infrastructure target, expect skip skill metadata; build code and deploy infrastructure', (done) => { // setup sinon.stub(helper, 'deploySkillMetadata').callsArgWith(1); - sinon.stub(helper, 'enableSkill').callsArgWith(2); - sinon.stub(helper, 'buildSkillCode').callsArgWith(2, null, TEST_CODE_BUILD_RESULT); - sinon.stub(helper, 'deploySkillInfrastructure').callsArgWith(3); + sinon.stub(helper, 'enableSkill').callsArgWith(1); + sinon.stub(helper, 'buildSkillCode').callsArgWith(1, null, TEST_CODE_BUILD_RESULT); + sinon.stub(helper, 'deploySkillInfrastructure').callsArgWith(1); sinon.stub(path, 'resolve').returns(TEST_CODE_SRC_BASENAME); sinon.stub(fs, 'statSync').returns({ isDirectory: () => true @@ -369,9 +369,9 @@ with build flow ${TEST_CODE_BUILD_RESULT[0].buildFlow}.`); it('| helper deploy skill infra fails, expect throw error', (done) => { // setup sinon.stub(helper, 'deploySkillMetadata').callsArgWith(1); - sinon.stub(helper, 'buildSkillCode').callsArgWith(2, null, TEST_CODE_BUILD_RESULT); - sinon.stub(helper, 'deploySkillInfrastructure').callsArgWith(3, 'error'); - sinon.stub(helper, 'enableSkill').callsArgWith(2); + sinon.stub(helper, 'buildSkillCode').callsArgWith(1, null, TEST_CODE_BUILD_RESULT); + sinon.stub(helper, 'deploySkillInfrastructure').callsArgWith(1, 'error'); + sinon.stub(helper, 'enableSkill').callsArgWith(1); sinon.stub(path, 'resolve').returns(TEST_CODE_SRC_BASENAME); sinon.stub(fs, 'statSync').returns({ isDirectory: () => true @@ -398,9 +398,9 @@ with build flow ${TEST_CODE_BUILD_RESULT[0].buildFlow}.`); it('| deploy skill all pass, expect deploy succeeds and enableSkill get called', (done) => { // setup sinon.stub(helper, 'deploySkillMetadata').callsArgWith(1); - sinon.stub(helper, 'buildSkillCode').callsArgWith(2, null, TEST_CODE_BUILD_RESULT); - sinon.stub(helper, 'deploySkillInfrastructure').callsArgWith(3); - sinon.stub(helper, 'enableSkill').callsArgWith(2); + sinon.stub(helper, 'buildSkillCode').callsArgWith(1, null, TEST_CODE_BUILD_RESULT); + sinon.stub(helper, 'deploySkillInfrastructure').callsArgWith(1); + sinon.stub(helper, 'enableSkill').callsArgWith(1); sinon.stub(path, 'resolve').returns(TEST_CODE_SRC_BASENAME); sinon.stub(fs, 'statSync').returns({ isDirectory: () => true @@ -447,9 +447,9 @@ with build flow ${TEST_CODE_BUILD_RESULT[0].buildFlow}.`); // setup const TEST_WARN = new CliWarn('warn'); sinon.stub(helper, 'deploySkillMetadata').callsArgWith(1); - sinon.stub(helper, 'buildSkillCode').callsArgWith(2, null, TEST_CODE_BUILD_RESULT); - sinon.stub(helper, 'deploySkillInfrastructure').callsArgWith(3); - sinon.stub(helper, 'enableSkill').callsArgWith(2, TEST_WARN); + sinon.stub(helper, 'buildSkillCode').callsArgWith(1, null, TEST_CODE_BUILD_RESULT); + sinon.stub(helper, 'deploySkillInfrastructure').callsArgWith(1); + sinon.stub(helper, 'enableSkill').callsArgWith(1, TEST_WARN); // call instance.handle(TEST_CMD, (err) => { // verify @@ -459,13 +459,13 @@ with build flow ${TEST_CODE_BUILD_RESULT[0].buildFlow}.`); }); }); - it('| can callbcak error when enable fails', (done) => { + it('| can callback error when enable fails', (done) => { // setup const TEST_ERROR = 'error'; sinon.stub(helper, 'deploySkillMetadata').callsArgWith(1); - sinon.stub(helper, 'buildSkillCode').callsArgWith(2, null, TEST_CODE_BUILD_RESULT); - sinon.stub(helper, 'deploySkillInfrastructure').callsArgWith(3); - sinon.stub(helper, 'enableSkill').callsArgWith(2, 'error'); + sinon.stub(helper, 'buildSkillCode').callsArgWith(1, null, TEST_CODE_BUILD_RESULT); + sinon.stub(helper, 'deploySkillInfrastructure').callsArgWith(1); + sinon.stub(helper, 'enableSkill').callsArgWith(1, 'error'); // call instance.handle(TEST_CMD, (err) => { // verify diff --git a/test/unit/controller/skill-code-controller-test.js b/test/unit/controller/skill-code-controller-test.js index 5b1e1677..59d703dc 100644 --- a/test/unit/controller/skill-code-controller-test.js +++ b/test/unit/controller/skill-code-controller-test.js @@ -10,12 +10,16 @@ describe('Controller test - skill code controller test', () => { const FIXTURE_RESOURCES_CONFIG_FILE_PATH = path.join(process.cwd(), 'test', 'unit', 'fixture', 'model', 'regular-proj', 'ask-resources.json'); const TEST_PROFILE = 'default'; // test file uses 'default' profile const TEST_DO_DEBUG = false; + const TEST_SHOULD_DEREFERENCE_SYMLINKS = false; + const TEST_NO_NPM_INSTALL = false; const TEST_CODE_SRC = './awsStack/lambda-NA/src'; const TEST_EU_CODE_SRC = './awsStack/lambda-EU/src'; const TEST_CODE_BUILD = 'build'; const TEST_CONFIGURATION = { profile: TEST_PROFILE, - doDebug: TEST_DO_DEBUG + doDebug: TEST_DO_DEBUG, + shouldDereferenceSymlinks: TEST_SHOULD_DEREFERENCE_SYMLINKS, + noNPMInstall: TEST_NO_NPM_INSTALL }; describe('# inspect correctness for constructor', () => {