Skip to content

Commit

Permalink
fix for aio app init <dir> --import <config> (#244)
Browse files Browse the repository at this point in the history
* fix aio app init <proj> --import
* add a test for absolut path
* fix windows tests
* fix merged tests
  • Loading branch information
moritzraho authored May 28, 2020
1 parent 5406d4f commit df8ca18
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 6 deletions.
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

0 comments on commit df8ca18

Please sign in to comment.