feat: refactor and test tools steps utilities (#42693)

This commit is contained in:
Victor Duarte
2021-07-06 19:22:12 -05:00
committed by GitHub
parent 9e883e49ba
commit 82d09bd593
36 changed files with 855 additions and 207 deletions

View File

@ -0,0 +1,31 @@
jest.mock('fs', () => {
return {
readFileSync: jest.fn()
};
});
const mockPath = '/mock/path';
const { readFileSync } = require('fs');
const { getMetaData } = require('./get-project-path-metadata');
describe('getMetaData helper', () => {
it('should process requested file', () => {
readFileSync.mockImplementation(() => '{"name": "Test Project"}');
const expected = {
name: 'Test Project'
};
expect(getMetaData(mockPath)).toEqual(expected);
});
it('should throw if file is not found', () => {
readFileSync.mockImplementation(() => {
throw new Error();
});
expect(() => {
getMetaData(mockPath);
}).toThrowError(new Error(`No _meta.json file exists at ${mockPath}`));
});
});