Skip to content

Commit

Permalink
test: add few unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
thecodexhub committed Oct 12, 2023
1 parent 18a3d71 commit df2d556
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 1 deletion.
10 changes: 10 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
"jest": "^29.7.0",
"lint-staged": "^14.0.1",
"prettier": "^3.0.3",
"stream-mock": "^2.0.5",
"ts-jest": "^29.1.1",
"typescript": "^5.2.2"
}
Expand Down
2 changes: 1 addition & 1 deletion src/tasks/create-express-task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const copyAsync = promisify(ncp);
* @param {string} projectDescription - The description of the xarvis project.
* @returns {stream.Transform} A transform stream that replaces placeholders with provided values.
*/
const transformTemplateWithConfig = (projectName: string, projectDescription: string): stream.Transform => {
export const transformTemplateWithConfig = (projectName: string, projectDescription: string): stream.Transform => {
return new stream.Transform({
transform(chunk, _, callback) {
let modifiedChunk = chunk.toString('utf8');
Expand Down
29 changes: 29 additions & 0 deletions tests/tasks/create-express-task.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { transformTemplateWithConfig } from '../../src/tasks/create-express-task';
import { ObjectWritableMock } from 'stream-mock';

describe('CreateExpressTask', () => {
describe('transformTemplateWithConfig', () => {
it('should replace project name and description in the stream', (done) => {
const projectName = 'xarvis';
const description = 'a CLI tool to generate production ready apps';

const input = 'Project name: {{project_name}}, and this is {{project_description}}';
const expectedOutput = `Project name: ${projectName}, and this is ${description}`;

const transformStream = transformTemplateWithConfig(projectName, description);
const writableStream = new ObjectWritableMock();

transformStream.write(input, 'utf-8', () => {
transformStream.end();
});

transformStream.pipe(writableStream);

writableStream.on('finish', () => {
const transformedData = writableStream.data.toString();
expect(transformedData).toEqual(expectedOutput);
done();
});
});
});
});

0 comments on commit df2d556

Please sign in to comment.