Skip to content
Closed
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
4 changes: 2 additions & 2 deletions lib/ActionGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class ActionGenerator extends Generator {
return true
}
return `'${input}' is not a valid action name, please make sure that:
The name has at least 3 characters or less than 33 characters.
The name has at least 3 characters or less than 33 characters.
The first character is an alphanumeric character.
The subsequent characters are alphanumeric.
The last character isn't a space.
Expand Down Expand Up @@ -136,7 +136,7 @@ Note: characters can only be split by '-'.
utils.addDependencies(this, options.dependencies)
}
// make sure wskdebug is there
utils.addDependencies(this, { '@openwhisk/wskdebug': '^1.3.0', ...options.devDependencies }, true)
utils.addDependencies(this, options.devDependencies, true)
// make sure the node engines are added
this.addPackageJsonNodeEngines()
}
Expand Down
21 changes: 12 additions & 9 deletions test/lib/ActionGenerator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ describe('implementation', () => {
test('rejects invalid name with a message`', async () => {
const invalidName = 'a'
const invalidNameMessage = `'${invalidName}' is not a valid action name, please make sure that:
The name has at least 3 characters or less than 33 characters.
The name has at least 3 characters or less than 33 characters.
The first character is an alphanumeric character.
The subsequent characters are alphanumeric.
The last character isn't a space.
Expand Down Expand Up @@ -192,9 +192,6 @@ Note: characters can only be split by '-'.
'runtimeManifest',
// function path should be checked to be relative to config file
{ packages: { 'dx-excshell-1': { actions: { myAction: { annotations: { 'require-adobe-auth': true }, function: expect.stringContaining('myAction/index.js'), runtime: constants.defaultRuntimeKind, web: 'yes' } }, license: 'Apache-2.0' } } })

// 3. make sure wskdebug dev dependency was added to package.json
expect(utils.addDependencies).toHaveBeenCalledWith(actionGenerator, { '@openwhisk/wskdebug': expect.any(String) }, true)
})

test('with extra dependencies and manifest already exists', () => {
Expand All @@ -212,27 +209,33 @@ Note: characters can only be split by '-'.
}
})

actionGenerator.addAction('myAction', './templateFile.js', { dependencies: { abc: '1.2.3', def: '4.5.6' }, devDependencies: { xyz: '3.2.1', vuw: '6.5.4' } })
actionGenerator.addAction('myAction', './templateFile.js', {
dependencies: { abc: '1.2.3', def: '4.5.6' },
devDependencies: { xyz: '3.2.1', vuw: '6.5.4' }
})

// 1. test copy action template to right destination
expect(actionGenerator.fs.copyTpl).toHaveBeenCalledWith(n('/fakeTplDir/templateFile.js'), n(`${actionFolderPath}/myAction/index.js`), {}, {}, {})
expect(actionGenerator.fs.copyTpl).toHaveBeenCalledWith(
n('/fakeTplDir/templateFile.js'),
n(`${actionFolderPath}/myAction/index.js`), {}, {}, {})

// 2. test manifest creation with action information, and preserving previous content
expect(utils.writeKeyYAMLConfig).toHaveBeenCalledWith(
actionGenerator,
n('/fakeDestRoot/src/dx-excshell-1/ext.config.yaml'),
'runtimeManifest',
// function path should be checked to be relative to config file
{ packages: { 'dx-excshell-1': { actions: { actionxyz: { function: 'fake.js' }, myAction: { annotations: { 'require-adobe-auth': true }, function: expect.stringContaining('myAction/index.js'), runtime: constants.defaultRuntimeKind, web: 'yes' } } } } })
// 3. make sure wskdebug dev dependency was added to package.json
// 3. make sure (dev)dependencies get added to package.json
expect(utils.addDependencies).toHaveBeenCalledTimes(2)
// prod
expect(utils.addDependencies).toHaveBeenCalledWith(actionGenerator, {
abc: '1.2.3', def: '4.5.6'
})
// dev
expect(utils.addDependencies).toHaveBeenCalledWith(actionGenerator, {
xyz: '3.2.1',
vuw: '6.5.4',
'@openwhisk/wskdebug': expect.any(String)
vuw: '6.5.4'
}, true)
})

Expand Down