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

fix for aio app init <dir> --import <config> #244

Merged
merged 7 commits into from
May 28, 2020
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
5 changes: 5 additions & 0 deletions src/commands/app/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ class InitCommand extends BaseCommand {
const { args, flags } = this.parse(InitCommand)
let res

if (flags.import) {
// resolve to absolute path before any chdir
flags.import = path.resolve(flags.import)
}

if (args.path !== '.') {
const destDir = path.resolve(args.path)
fs.ensureDirSync(destDir)
Expand Down
46 changes: 40 additions & 6 deletions test/commands/app/init.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ OF ANY KIND, either express or implied. See the License for the specific languag
governing permissions and limitations under the License.
*/
const fs = require('fs-extra')
const path = require('path')

const TheCommand = require('../../../src/commands/app/init')
const BaseCommand = require('../../../src/BaseCommand')
Expand Down Expand Up @@ -356,7 +357,10 @@ describe('run', () => {
'adobe-services': 'AdobeTargetSDK,CampaignSDK'
})

expect(importLib.importConfigJson).toHaveBeenCalledWith('config.json', process.cwd(), { interactive: false, merge: true }, { SERVICE_API_KEY: 'fakeId123' })
expect(importLib.importConfigJson).toHaveBeenCalledWith(path.resolve('config.json'),
process.cwd(),
{ interactive: false, merge: true },
{ SERVICE_API_KEY: 'fakeId123' })
})

test('no-path --import file={name: lifeisgood, services:AdobeTargetSDK,CampaignSDK, credentials:fake}', async () => {
Expand All @@ -381,7 +385,10 @@ describe('run', () => {
'adobe-services': 'AdobeTargetSDK,CampaignSDK'
})

expect(importLib.importConfigJson).toHaveBeenCalledWith('config.json', process.cwd(), { interactive: false, merge: true }, { SERVICE_API_KEY: '' })
expect(importLib.importConfigJson).toHaveBeenCalledWith(path.resolve('config.json'),
process.cwd(),
{ interactive: false, merge: true },
{ SERVICE_API_KEY: '' })
})

test('no-path --import file={name: lifeisgood, services:AdobeTargetSDK,CampaignSDK, credentials:null}', async () => {
Expand All @@ -406,7 +413,10 @@ describe('run', () => {
'adobe-services': 'AdobeTargetSDK,CampaignSDK'
})

expect(importLib.importConfigJson).toHaveBeenCalledWith('config.json', process.cwd(), { interactive: false, merge: true }, { SERVICE_API_KEY: '' })
expect(importLib.importConfigJson).toHaveBeenCalledWith(path.resolve('config.json'),
process.cwd(),
{ interactive: false, merge: true },
{ SERVICE_API_KEY: '' })
})

test('no-path --yes --import file={name: lifeisgood, services:AdobeTargetSDK,CampaignSDK, credentials:fake,jwt}', async () => {
Expand All @@ -429,8 +439,10 @@ describe('run', () => {
'project-name': project.name,
'adobe-services': 'AdobeTargetSDK,CampaignSDK'
})

expect(importLib.importConfigJson).toHaveBeenCalledWith('config.json', process.cwd(), { interactive: false, merge: true }, { SERVICE_API_KEY: 'fakeId123' })
expect(importLib.importConfigJson).toHaveBeenCalledWith(path.resolve('config.json'),
process.cwd(),
{ interactive: false, merge: true },
{ SERVICE_API_KEY: 'fakeId123' })
})

test('some-path --import file={name: lifeisgood, services:undefined, credentials:fake,jwt}', async () => {
Expand All @@ -451,7 +463,29 @@ describe('run', () => {
'adobe-services': ''
})

expect(importLib.importConfigJson).toHaveBeenCalledWith('config.json', process.cwd(), { interactive: false, merge: true }, { SERVICE_API_KEY: 'fakeId123' })
// Note here path.resolve uses another cwd than the mocked process.cwd
expect(importLib.importConfigJson).toHaveBeenCalledWith(path.resolve('config.json'),
process.cwd(),
{ interactive: false, merge: true },
{ SERVICE_API_KEY: 'fakeId123' })
})

test('some-path --import ../fake/config.json', async () => {
await TheCommand.run(['some-path', '--import', '../fake/config.json'])
// Note here path.resolve uses another cwd than the mocked process.cwd
expect(importLib.importConfigJson).toHaveBeenCalledWith(path.resolve('../fake/config.json'),
process.cwd(),
{ interactive: false, merge: true },
{ SERVICE_API_KEY: 'fakeId123' })
})

test('some-path --import /abs/fake/config.json', async () => {
await TheCommand.run(['some-path', '--import', '/abs/fake/config.json'])
// Note here path.resolve uses another cwd than the mocked process.cwd
expect(importLib.importConfigJson).toHaveBeenCalledWith(path.resolve('/abs/fake/config.json'),
process.cwd(),
{ interactive: false, merge: true },
{ SERVICE_API_KEY: 'fakeId123' })
})

test('no cli context', async () => {
Expand Down