add tests and apireport

Signed-off-by: pitwegner <pit.wegner@student.hpi.de>
This commit is contained in:
pitwegner
2023-01-17 15:55:47 +01:00
parent 6d435e5199
commit c5b529ed16
2 changed files with 78 additions and 0 deletions
+1
View File
@@ -127,6 +127,7 @@ export function createFetchTemplateAction(options: {
copyWithoutRender?: string[] | undefined;
copyWithoutTemplating?: string[] | undefined;
cookiecutterCompat?: boolean | undefined;
replace?: boolean | undefined;
}>;
// @public
@@ -669,4 +669,81 @@ describe('fetch:template', () => {
).resolves.toEqual('test-project: 1234');
});
});
describe('with replacement of existing files', () => {
let context: ActionContext<FetchTemplateInput>;
beforeEach(async () => {
context = mockContext({
values: {
name: 'test-project',
count: 1234,
},
replace: true,
});
mockFetchContents.mockImplementation(({ outputPath }) => {
mockFs({
...realFiles,
[joinPath(workspacePath, 'target')]: {
'static-content.txt': 'static-content',
},
[outputPath]: {
'static-content.txt': '${{ values.name }}: ${{ values.count }}',
},
});
return Promise.resolve();
});
await action.handler(context);
});
afterEach(() => {
mockFs.restore();
});
it('overwrites existing file', async () => {
await expect(
fs.readFile(`${workspacePath}/target/static-content.txt`, 'utf-8'),
).resolves.toEqual('test-project: 1234');
});
});
describe('without replacement of existing files', () => {
let context: ActionContext<FetchTemplateInput>;
beforeEach(async () => {
context = mockContext({
values: {
name: 'test-project',
count: 1234,
},
targetPath: './target',
replace: false,
});
mockFetchContents.mockImplementation(({ outputPath }) => {
mockFs({
...realFiles,
[joinPath(workspacePath, 'target')]: {
'static-content.txt': 'static-content',
},
[outputPath]: {
'static-content.txt': '${{ values.name }}: ${{ values.count }}',
},
});
return Promise.resolve();
});
await action.handler(context);
});
it('keeps existing file', async () => {
await expect(
fs.readFile(`${workspacePath}/target/static-content.txt`, 'utf-8'),
).resolves.toEqual('static-content');
});
});
});