Skip to content

Commit

Permalink
chore: update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Shurtu-gal committed Apr 30, 2024
1 parent 471f602 commit ffcba6c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
5 changes: 2 additions & 3 deletions src/commands/new/glee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { prompt } from 'inquirer';
import Generator from '@asyncapi/generator';
import { green, gray } from 'picocolors';

const successMessage = (projectName: string) =>
export const successMessage = (projectName: string) =>
`🎉 Your glee project "${green(projectName)}" has been successfully created!
⏩ Next steps: follow the instructions ${green('below')} to manage your project:
Expand All @@ -27,8 +27,7 @@ const errorMessages = {
`Unable to create the project because the directory "${green(projectName)}" already exists at "${process.cwd()}/${projectName}".
To specify a different name for the new project, please run the command ${green('below')} with a unique project name:
${gray('asyncapi new glee --name ${projectName}-1')}
`,
${gray('asyncapi new glee --name ') + gray(projectName) + gray('-1')}`,
};

export default class NewGlee extends Command {
Expand Down
6 changes: 3 additions & 3 deletions test/integration/new/file.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('new', () => {
.command(['new', '--no-tty', '-n=specification.yaml'])
.it('runs new command', async (ctx,done) => {
expect(ctx.stderr).to.equal('');
expect(ctx.stdout).to.equal('Created file specification.yaml...\n');
expect(ctx.stdout).to.equal('The specification.yaml has been successfully created.\n');
done();
});

Expand All @@ -36,7 +36,7 @@ describe('new', () => {
.command(['new:file', '--no-tty', '-n=specification.yaml'])
.it('runs new file command', async (ctx,done) => {
expect(ctx.stderr).to.equal('');
expect(ctx.stdout).to.equal('Created file specification.yaml...\n');
expect(ctx.stdout).to.equal('The specification.yaml has been successfully created.\n');
done();
});
});
Expand All @@ -62,7 +62,7 @@ describe('new', () => {
.command(['new:file', '--no-tty', '-n=specification.yaml'])
.it('should inform about the existing file and finish the process', async (ctx,done) => {
expect(ctx.stderr).to.equal('');
expect(ctx.stdout).to.equal('File specification.yaml already exists. Ignoring...\n');
expect(ctx.stdout).to.equal('A file named specification.yaml already exists. Please choose a different name.\n');
done();
});
});
Expand Down
15 changes: 13 additions & 2 deletions test/integration/new/glee.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@ import { PROJECT_DIRECTORY_PATH } from '../../helpers';
import { expect } from '@oclif/test';

const testHelper = new TestHelper();
const successMessage = (projectName: string) =>
`🎉 Your glee project "${projectName}" has been successfully 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:
asyncapi new glee --name ${projectName}-1`,
};

describe('new glee', () => {
before(() => {
Expand All @@ -27,7 +38,7 @@ describe('new glee', () => {
.command(['new:glee', '-n=test-project'])
.it('runs new glee command with name flag', async (ctx,done) => {
expect(ctx.stderr).to.equal('');
expect(ctx.stdout).to.equal('Your project "test-project" has been created successfully!\n\nNext steps:\n\n cd test-project\n npm install\n npm run dev\n\nAlso, you can already open the project in your favorite editor and start tweaking it.\n');
expect(ctx.stdout).to.contain(successMessage('test-project'));
done();
});
});
Expand All @@ -52,7 +63,7 @@ describe('new glee', () => {
.stdout()
.command(['new:glee', '-n=test-project'])
.it('should throw error if name of the new project already exists', async (ctx,done) => {
expect(ctx.stderr).to.equal(`Error: Unable to create the project. We tried to use "test-project" as the directory of your new project but it already exists (${PROJECT_DIRECTORY_PATH}). Please specify a different name for the new project. For example, run the following command instead:\n\n asyncapi new glee --name test-project-1\n\n`);
expect(ctx.stderr).to.contains(`Error: ${errorMessages.alreadyExists('test-project')}`);
expect(ctx.stdout).to.equal('');
done();
});
Expand Down

0 comments on commit ffcba6c

Please sign in to comment.