Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

inform user if no actions were built #448

Merged
merged 3 commits into from
Aug 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions src/commands/app/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const { runScript, writeConfig } = require('../../lib/app-helper')
const RuntimeLib = require('@adobe/aio-lib-runtime')
const { bundle } = require('@adobe/aio-lib-web')
const fs = require('fs-extra')
// const aioLogger = require('@adobe/aio-lib-core-logging')('@adobe/aio-cli-plugin-app:build', { provider: 'debug' })
const aioLogger = require('@adobe/aio-lib-core-logging')('@adobe/aio-cli-plugin-app:build', { provider: 'debug' })

class Build extends BaseCommand {
async run () {
Expand Down Expand Up @@ -72,13 +72,24 @@ class Build extends BaseCommand {

if (flags.actions) {
if (config.app.hasBackend && (flags['force-build'] || !fs.existsSync(config.actions.dist))) {
spinner.start(`Building actions for '${name}'`)
try {
let builtList = []
const script = await runScript(config.hooks['build-actions'])
aioLogger.debug(`run hook for 'build-actions' for actions in '${name}' returned ${script}`)
spinner.start(`Building actions for '${name}'`)
if (!script) {
await RuntimeLib.buildActions(config, filterActions)
builtList = await RuntimeLib.buildActions(config, filterActions)
}
spinner.succeed(chalk.green(`Building actions for '${name}'`))
if (builtList.length > 0) {
spinner.succeed(chalk.green(`Built ${builtList.length} action(s) for '${name}'`))
} else {
if (script) {
spinner.fail(chalk.green(`build-action skipped by hook '${name}'`))
} else {
spinner.fail(chalk.green(`No actions built for '${name}'`))
}
}
aioLogger.debug(`RuntimeLib.buildActions returned ${builtList}`)
} catch (err) {
spinner.fail(chalk.green(`Building actions for '${name}'`))
throw err
Expand Down
43 changes: 23 additions & 20 deletions test/__mocks__/ora.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,29 @@ OF ANY KIND, either express or implied. See the License for the specific languag
governing permissions and limitations under the License.
*/

const spinner = {
stopAndPersist: jest.fn(() => {
// console.error('stopAndPersist')
}),
stop: jest.fn((value) => {
console.error(value)
}),
start: jest.fn((value) => {
console.error(value)
}),
warn: jest.fn((value) => {
console.error(value)
}),
info: jest.fn((msg) => {
console.log(msg)
}),
error: jest.fn(),
fail: jest.fn(),
succeed: jest.fn((value) => {
console.error(value)
})
}

module.exports = () => {
const spinner = {
stopAndPersist: jest.fn(() => {
// console.error('stopAndPersist')
}),
stop: jest.fn(),
start: jest.fn(() => {
// console.error('start')
}),
warn: jest.fn(() => {
// console.error('warn')
}),
info: jest.fn((msg) => {
console.log(msg)
}),
error: jest.fn(),
fail: jest.fn(),
succeed: jest.fn(() => {
// console.error('succeed')
})
}
return spinner
}
15 changes: 11 additions & 4 deletions test/commands/app/build.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ const path = require('path')
const cloneDeep = require('lodash.clonedeep')
const dataMocks = require('../../data-mocks/config-loader')

const ora = require('ora')
jest.mock('ora')

const mockFS = require('fs-extra')
jest.mock('fs-extra')

Expand Down Expand Up @@ -199,16 +202,20 @@ test('flags', async () => {
expect(TheCommand.flags.extension.exclusive).toEqual(['action'])
})

let spinner

describe('run', () => {
let command
beforeEach(() => {
spinner = ora()
command = new TheCommand([])
command.error = jest.fn()
command.log = jest.fn()
command.getAppExtConfigs = jest.fn()
command.appConfig = cloneDeep(sampleAppConfig)

mockRuntimeLib.buildActions.mockReset()
mockRuntimeLib.buildActions.mockReturnValue([])
})

afterEach(() => {
Expand Down Expand Up @@ -301,7 +308,6 @@ describe('run', () => {

test('build & deploy --skip-static', async () => {
command.getAppExtConfigs.mockReturnValueOnce(createAppConfig(command.appConfig))

command.argv = ['--skip-static']
await command.run()
expect(command.error).toHaveBeenCalledTimes(0)
Expand All @@ -311,7 +317,6 @@ describe('run', () => {

test('build & deploy --skip-web-assets', async () => {
command.getAppExtConfigs.mockReturnValueOnce(createAppConfig(command.appConfig))

command.argv = ['--skip-web-assets']
await command.run()
expect(command.error).toHaveBeenCalledTimes(0)
Expand All @@ -322,9 +327,11 @@ describe('run', () => {
test('build & deploy only some actions using --action', async () => {
const appConfig = createAppConfig(command.appConfig)
command.getAppExtConfigs.mockReturnValueOnce(appConfig)

command.argv = ['--skip-static', '-a', 'a', '-a', 'b', '--action', 'c']
command.argv = ['--skip-static', '-a', 'a', '-a=b', '--action', 'c']
mockRuntimeLib.buildActions.mockReturnValue(['a', 'b', 'c'])
await command.run()
expect(spinner.start).toBeCalledWith('Building actions for \'application\'')
expect(spinner.succeed).toBeCalledWith(expect.stringContaining('Built 3 action(s) for \'application\''))
expect(command.error).toHaveBeenCalledTimes(0)
expect(mockRuntimeLib.buildActions).toHaveBeenCalledTimes(1)
expect(mockRuntimeLib.buildActions).toHaveBeenCalledWith(appConfig.application, ['a', 'b', 'c'])
Expand Down