Skip to content

Commit

Permalink
Fix issue and added template
Browse files Browse the repository at this point in the history
  • Loading branch information
AayushSaini101 committed Jul 4, 2024
1 parent 22d5325 commit f5d48f8
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 3 deletions.
3 changes: 2 additions & 1 deletion assets/create-template/templates/default/template/index.js
Original file line number Diff line number Diff line change
@@ -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 (
<File name="asyncapi.md">
<Text>My application's markdown file.</Text>
Expand Down
2 changes: 0 additions & 2 deletions src/commands/new/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
67 changes: 67 additions & 0 deletions test/integration/new/template.test.ts
Original file line number Diff line number Diff line change
@@ -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();
});
});
});

0 comments on commit f5d48f8

Please sign in to comment.