Skip to content

Commit

Permalink
fix: debug actions via aio app run for extensions (file not found) (#160
Browse files Browse the repository at this point in the history
)
  • Loading branch information
shazron authored Aug 9, 2021
1 parent 8d4a4b9 commit 8248789
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
8 changes: 7 additions & 1 deletion generators/add-vscode-config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,16 @@ class AddVsCodeConfig extends Generator {
const remoteRoot = this.options[Option.REMOTE_ROOT]
const envFile = this.options[Option.ENV_FILE]

// make sure the action path is a relative path, using appConfig.root
let actionFileRelativePath = action.function
if (path.isAbsolute(actionFileRelativePath)) {
actionFileRelativePath = path.relative(appConfig.root, actionFileRelativePath)
}

const launchConfig = createPwaNodeLaunchConfiguration({
packageName,
actionName,
actionFileRelativePath: action.function,
actionFileRelativePath,
envFileRelativePath: envFile,
remoteRoot,
nodeVersion
Expand Down
34 changes: 31 additions & 3 deletions test/generators/add-vscode-config/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@ jest.mock('fs-extra')
const theGeneratorPath = require.resolve('../../../generators/add-vscode-config')
const Generator = require('yeoman-generator')

const createOptions = () => {
const createOptions = ({ actionPathIsAbsolute = false } = {}) => {
const root = '/root'
let actionPath = path.join('src', 'actions', 'action-1')
if (actionPathIsAbsolute) {
actionPath = path.join(root, actionPath)
}

return {
'app-config': {
app: {
Expand All @@ -36,7 +42,7 @@ const createOptions = () => {
__APP_PACKAGE__: {
actions: {
'action-1': {
function: path.join('src', 'actions', 'action-1')
function: actionPath
}
}
}
Expand All @@ -47,7 +53,7 @@ const createOptions = () => {
src: 'html',
distDev: 'dist-dev'
},
root: 'root'
root
},
'frontend-url': 'https://localhost:9080',
'env-file': 'my/.env'
Expand Down Expand Up @@ -292,6 +298,28 @@ test('output check', async () => {
assert.JSONFileContent(destFile, createTestLaunchConfiguration(options['app-config'].ow.package, true))
})

test('output check (action path is absolute)', async () => {
const options = createOptions({ actionPathIsAbsolute: true })
const pkg = options['app-config'].manifest.full.packages.__APP_PACKAGE__
pkg.actions['action-1'].runtime = 'nodejs:14'
pkg.actions['action-1'].annotations = {
'require-adobe-auth': true
}
options['app-config'].ow.apihost = 'https://adobeioruntime.net'
options['destination-file'] = 'foo/bar.json'

fs.lstatSync.mockReturnValue({
isDirectory: () => false
})

const result = helpers.run(theGeneratorPath).withOptions(options)
await expect(result).resolves.not.toThrow()

const destFile = options['destination-file']
assert.file(destFile) // destination file is written
assert.JSONFileContent(destFile, createTestLaunchConfiguration(options['app-config'].ow.package, true))
})

test('output check (custom package)', async () => {
const customPackage = 'my-custom-package'
const options = createOptions()
Expand Down

0 comments on commit 8248789

Please sign in to comment.