"use strict";

var _fs = require("fs");
var _path = require("path");
var _rimraf = _interopRequireDefault(require("../../compiled/rimraf"));
var _generateFile = _interopRequireDefault(require("./generateFile"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const fixtures = (0, _path.join)(__dirname, './fixtures');
const cwd = (0, _path.join)(fixtures, 'generate');
const globKeepDotFile = (0, _path.join)(cwd, '*');
beforeEach(() => {
  _rimraf.default.sync(globKeepDotFile, {
    glob: {
      ignore: ['**/.gitkeep']
    }
  });
});
afterAll(() => {
  _rimraf.default.sync(globKeepDotFile, {
    glob: {
      ignore: ['**/.gitkeep']
    }
  });
});
test('generate tpl', async () => {
  await (0, _generateFile.default)({
    path: (0, _path.join)(fixtures, 'tpl'),
    target: (0, _path.join)(cwd, 'hello/', '')
  });
  expect((0, _fs.existsSync)((0, _path.join)(cwd, 'hello', 'index.tsx'))).toEqual(true);
});
test('generate tpl file', async () => {
  await (0, _generateFile.default)({
    path: (0, _path.join)(fixtures, 'tpl', 'index.tsx.tpl'),
    target: (0, _path.join)(cwd, 'file-tpl', 'index.tsx')
  });
  expect((0, _fs.existsSync)((0, _path.join)(cwd, 'file-tpl', 'index.tsx'))).toEqual(true);
});
test('generate by file', async () => {
  await (0, _generateFile.default)({
    path: (0, _path.join)(fixtures, 'tpl', 'a.tsx'),
    target: (0, _path.join)(cwd, 'file', 'a.tsx')
  });
  expect((0, _fs.existsSync)((0, _path.join)(cwd, 'file', 'a.tsx'))).toEqual(true);
});
test('generate tpl by data', async () => {
  await (0, _generateFile.default)({
    path: (0, _path.join)(fixtures, 'tpl'),
    target: (0, _path.join)(cwd, 'data'),
    data: {
      componentName: 'Home'
    }
  });
  expect((0, _fs.existsSync)((0, _path.join)(cwd, 'data', 'index.tsx'))).toEqual(true);
  expect((0, _fs.readFileSync)((0, _path.join)(cwd, 'data', 'index.tsx'), 'utf-8')).toContain('HomePage');
});