diff --git a/package.json b/package.json index ccee628c..2fc63517 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "@parcel/reporter-cli": "2.0.0-beta.3.1", "ajv": "^6.12.2", "chalk": "^4.0.0", - "chokidar": "^3.4.2", + "chokidar": "^3.5.2", "cli-ux": "^5.4.5", "debug": "^4.1.1", "dedent-js": "^1.0.1", diff --git a/src/lib/actions-watcher.js b/src/lib/actions-watcher.js index a473cf49..6e0e6bed 100644 --- a/src/lib/actions-watcher.js +++ b/src/lib/actions-watcher.js @@ -81,6 +81,7 @@ function createChangeHandler (watcherOptions) { let undeployedFile = '' return async (filePath) => { + aioLogger.debug('Code change triggered...') if (deploymentInProgress) { aioLogger.debug(`${filePath} has changed. Deploy in progress. This change will be deployed after completion of current deployment.`) undeployedFile = filePath @@ -91,8 +92,12 @@ function createChangeHandler (watcherOptions) { try { aioLogger.debug(`${filePath} has changed. Redeploying actions.`) const filterActions = getActionNameFromPath(filePath, watcherOptions) - await buildAndDeploy(watcherOptions, filterActions) - aioLogger.debug('Deployment successful') + if (!filterActions.length) { + log(' -> A non-action file was changed, restart is required to deploy...') + } else { + await buildAndDeploy(watcherOptions, filterActions) + aioLogger.debug('Deployment successful') + } } catch (err) { log(' -> Error encountered while deploying actions. Stopping auto refresh.') aioLogger.debug(err) diff --git a/test/commands/lib/actions-watcher.test.js b/test/commands/lib/actions-watcher.test.js index 0e2c9bd2..7d1ebc06 100644 --- a/test/commands/lib/actions-watcher.test.js +++ b/test/commands/lib/actions-watcher.test.js @@ -14,6 +14,7 @@ const chokidar = require('chokidar') const mockLogger = require('@adobe/aio-lib-core-logging') const buildActions = require('../../../src/lib/build-actions') const deployActions = require('../../../src/lib/deploy-actions') +const buildAndDeploy = require('../../../src/lib/deploy-actions') const util = require('util') const dataMocks = require('../../data-mocks/config-loader') const sleep = util.promisify(setTimeout) @@ -38,6 +39,7 @@ beforeEach(() => { buildActions.mockReset() deployActions.mockReset() + buildAndDeploy.mockReset() }) test('exports', () => { @@ -153,7 +155,7 @@ test('onChange handler calls buildActions with filterActions', async () => { ) }) -test('onChange handler calls buildActions without filterActions when actions are undefined', async () => { +test('on non-action file changed, skip build&deploy', async () => { const { application } = createAppConfig() const cloneApplication = cloneDeep(application) Object.entries(cloneApplication.manifest.full.packages).forEach(([, pkg]) => { @@ -176,10 +178,10 @@ test('onChange handler calls buildActions without filterActions when actions are await actionsWatcher({ config: cloneApplication, log }) expect(typeof onChangeHandler).toEqual('function') - deployActions.mockImplementation(async () => await sleep(2000)) - onChangeHandler('/myactions/action.js') + buildAndDeploy.mockImplementation(async () => await sleep(2000)) + onChangeHandler('/myactions/utils.js') await jest.runAllTimers() - expect(buildActions).toHaveBeenCalledWith(cloneApplication, []) + expect(buildAndDeploy).not.toHaveBeenCalled() })