Skip to content

Instantly share code, notes, and snippets.

@jpmonette
Created August 7, 2017 14:59
Show Gist options
  • Save jpmonette/714712823c21c256635104f4da828dc8 to your computer and use it in GitHub Desktop.
Save jpmonette/714712823c21c256635104f4da828dc8 to your computer and use it in GitHub Desktop.
Watching for changes in SFDX project
const chokidar = require('chokidar');
const shell = require('shelljs')
chokidar
.watch('./force-app')
.on('change', onChange)
// On File Change
function onChange (path) {
console.log('Updating ' + path + '...')
shell.exec('sfdx force:source:push', () => {
if (path.indexOf('Test.cls') !== -1) onUpsertTest(path)
})
}
// On Test Change
function onUpsertTest(path) {
let fileName = path.split('/')[4].split('.')[0]
console.log('Running tests for ' + fileName + '...')
shell.exec('sfdx force:apex:test:run --resultformat human --classnames ' + fileName)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment