@naoufal/create-react-component
Version:
The fastest way to create React Components
73 lines (59 loc) • 2.06 kB
JavaScript
;
jest.mock('fs-extra');
const path = require('path');
const fs = require('fs-extra');
const {
copyDirectory,
copyFileAsync,
buildTemplatePath,
replaceComponentName
} = require('../execution');
describe('execution.js', () => {
describe('copyDirectory', () => {
it('it should call the mkdir function', async () => {
const directoryPath = path.join(__dirname, 'COMPONENT_NAME');
const destinationPath = path.join(__dirname, '/some/path/COMPONENT_NAME');
copyDirectory(
directoryPath,
destinationPath,
'Foo'
);
await expect(fs.mkdir.mock.calls.length).toBe(1);
});
});
describe('copyFile', () => {
it('should call the readFile function', async () => {
const filePath = path.join(__dirname, 'COMPONENT_NAME.js')
const destinationPath = path.join(__dirname, '/some/path/Foo.js');
copyFileAsync(
filePath,
destinationPath,
'Foo'
);
await expect(fs.readFile.mock.calls.length).toBe(1);
});
// it('should call the writeFile function', async () => {
// // TODO:
// // - Write an fs-extra mock to property test this function
// });
});
describe('buildTemplatePath', () => {
it('should build path to the default function template', () => {
expect(buildTemplatePath('default', 'function')).toBe(
path.join(__dirname + '/../../../crc-template-default/templates/function')
);
});
});
describe('replaceComponentName', () => {
it('should replace `COMPONENT_NAME` with componentName', () => {
expect(replaceComponentName('COMPONENT_NAME', 'Foo')).toBe('Foo');
});
it('should replace multiple instances of `COMPONENT_NAME` with componentName', () => {
expect(replaceComponentName('COMPONENT_NAME COMPONENT_NAME', 'Foo'))
.toBe('Foo Foo');
});
it('should return input text when `COMPONENT_NAME` is not present', () => {
expect(replaceComponentName('some string', 'Foo')).toBe('some string');
});
});
});