Use mock-fs during createApp to prevent filesystem modifications

Signed-off-by: Colton Padden <colton.padden@fastmail.com>
This commit is contained in:
Colton Padden
2021-10-29 11:45:01 -04:00
parent bd90ded8b7
commit 1b3fab7193
+13
View File
@@ -15,12 +15,25 @@
*/
import inquirer from 'inquirer';
import mockFs from 'mock-fs';
import path from 'path';
import { Command } from 'commander';
import * as tasks from './lib/tasks';
import createApp from './createApp';
jest.mock('./lib/tasks');
beforeAll(() => {
mockFs({
'package.json': '', // required by `findPaths(__dirname)`
'templates/': mockFs.load(path.resolve(__dirname, '../templates/')),
});
});
afterAll(() => {
mockFs.restore();
});
const promptMock = jest.spyOn(inquirer, 'prompt');
const checkPathExistsMock = jest.spyOn(tasks, 'checkPathExistsTask');
const templatingMock = jest.spyOn(tasks, 'templatingTask');