'use strict';

let mocha = require('mocha');
let expect = require("chai").expect;
let fs = require('fs');
let cpen = require('../src/cpen');
let ProgressBar = require('progress');

let fakeProgress = new ProgressBar(`Downloading ( :percent )[:bar]`, {
  complete: '',
  incomplete: '',
  width: 1,
  total: 6
});

describe('cpen test', () => {

  beforeEach(done => {
    fs.mkdirSync('example');
    done();
  });

  afterEach(done => {
    fs.unlinkSync('example/index.html');
    fs.unlinkSync('example/style.css');
    fs.unlinkSync('example/main.js');
    fs.rmdirSync('example');
    done();
  });

  it('should create files', done => {
    cpen.create({
      html : 'html file',
      css : 'css file',
      js : 'js file'
    }, 'example', (e) => {
      expect(fs.statSync('example/index.html').isFile());
      expect(fs.statSync('example/style.css').isFile());
      expect(fs.statSync('example/main.js').isFile());

      done();
    });
  });

  it('should overwrite existing file data', done => {
    fs.appendFileSync('example/index.html', 'dummy');
    fs.appendFileSync('example/main.js', 'dummy');
    fs.appendFileSync('example/style.css', 'dummy');

    cpen.create({
      html : 'html file',
      css : 'css file',
      js : 'js file'
    }, 'example', (e) => {
      expect(fs.readFileSync('example/index.html', 'utf8')).to.not.contain('dummy');
      expect(fs.readFileSync('example/style.css', 'utf8')).to.not.contain('dummy');
      expect(fs.readFileSync('example/main.js', 'utf8')).to.not.contain('dummy');
      done();
    });

  });

})

'use strict';

let mocha = require('mocha');
let expect = require("chai").expect;
let fs = require('fs');
let cpen = require('../src/cpen');
let ProgressBar = require('progress');

let fakeProgress = new ProgressBar(`Downloading ( :percent )[:bar]`, {
  complete: '',
  incomplete: '',
  width: 1,
  total: 6
});

describe('folder creation test', () => {

  it('should create folder if not existing', done => {
    cpen.create({
      html : 'html file',
      css : 'css file',
      js : 'js file'
    }, 'example', (e) => {
      expect(fs.statSync('example/index.html').isFile());
      expect(fs.statSync('example/style.css').isFile());
      expect(fs.statSync('example/main.js').isFile());
      done();
    });
  });

  afterEach(done => {
    fs.unlinkSync('example/index.html');
    fs.unlinkSync('example/style.css');
    fs.unlinkSync('example/main.js');
    fs.rmdirSync('example');
    done();
  });
  
});

describe('file creation test', () => {

  beforeEach(done => {
    fs.mkdirSync('example');
    done();
  });

  afterEach(done => {
    fs.unlinkSync('example/index.html');
    fs.unlinkSync('example/style.css');
    fs.unlinkSync('example/main.js');
    fs.rmdirSync('example');
    done();
  });

  it('should create files', done => {
    cpen.create({
      html : 'html file',
      css : 'css file',
      js : 'js file'
    }, 'example', (e) => {
      expect(fs.statSync('example/index.html').isFile());
      expect(fs.statSync('example/style.css').isFile());
      expect(fs.statSync('example/main.js').isFile());

      done();
    });
  });

  it('should overwrite existing file data', done => {
    fs.appendFileSync('example/index.html', 'dummy');
    fs.appendFileSync('example/main.js', 'dummy');
    fs.appendFileSync('example/style.css', 'dummy');

    cpen.create({
      html : 'html file',
      css : 'css file',
      js : 'js file'
    }, 'example', (e) => {
      expect(fs.readFileSync('example/index.html', 'utf8')).to.not.contain('dummy');
      expect(fs.readFileSync('example/style.css', 'utf8')).to.not.contain('dummy');
      expect(fs.readFileSync('example/main.js', 'utf8')).to.not.contain('dummy');
      done();
    });

  });

})

add new tests