diff --git a/assets/create-template/templates/default/template/index.js b/assets/create-template/templates/default/template/index.js index caf30a6b1c2..5a4ab9f2892 100644 --- a/assets/create-template/templates/default/template/index.js +++ b/assets/create-template/templates/default/template/index.js @@ -1,6 +1,7 @@ import { File, Text } from '@asyncapi/generator-react-sdk'; -export default function ({ asyncapi, params, originalAsyncAPI }) { +// Pass the others parameters to get the specificatin of the asyncapi document +export default function ({ asyncapi }) { return ( My application's markdown file. diff --git a/src/commands/new/template.ts b/src/commands/new/template.ts index 7c50477a205..1745539d27a 100644 --- a/src/commands/new/template.ts +++ b/src/commands/new/template.ts @@ -38,8 +38,6 @@ export default class template extends Command { const { name: projectName, template: templateName, - file, - 'force-write': forceWrite, } = flags; const PROJECT_DIRECTORY = join(process.cwd(), projectName); diff --git a/test/integration/new/template.test.ts b/test/integration/new/template.test.ts new file mode 100644 index 00000000000..4040fdab64d --- /dev/null +++ b/test/integration/new/template.test.ts @@ -0,0 +1,67 @@ +import { test } from '@oclif/test'; +import TestHelper from '../../helpers'; +import { expect } from '@oclif/test'; + +const testHelper = new TestHelper(); +const successMessage = (projectName: string) => + '🎉 Your template is succesfully created!'; + +const errorMessages = { + alreadyExists: (projectName: string) => + `Unable to create the project because the directory "${projectName}" already exists at "${process.cwd()}/${projectName}". +To specify a different name for the new project, please run the command below with a unique project name:`}; + +describe('new template', () => { + before(() => { + try { + testHelper.deleteDummyProjectDirectory(); + } catch (e: any) { + if (e.code !== 'ENOENT') { + throw e; + } + } + }); + + describe('creation of new project is successful', () => { + afterEach(() => { + testHelper.deleteDummyProjectDirectory(); + }); + + test + .stderr() + .stdout() + .command(['new:template', '-n=test-project']) + .it('runs new template command with name flag', async (ctx,done) => { + expect(ctx.stderr).to.equal(''); + expect(ctx.stdout).to.contains(successMessage('test-project')); + done(); + }); + }); + + describe('when new project name already exists', () => { + beforeEach(() => { + try { + testHelper.createDummyProjectDirectory(); + } catch (e: any) { + if (e.code !== 'EEXIST') { + throw e; + } + } + }); + + afterEach(() => { + testHelper.deleteDummyProjectDirectory(); + }); + + test + .stderr() + .stdout() + .command(['new:template', '-n=test-project']) + .it('should throw error if name of the new project already exists', async (ctx,done) => { + expect(ctx.stderr).to.contains(`Error: ${errorMessages.alreadyExists('test-project')}`); + expect(ctx.stdout).to.equal(''); + done(); + }); + }); +}); +