{"size": 1996, "ext": "js", "max_stars_repo_path": "src/index.spec.js", "max_stars_repo_name": "FBerthelot/nuxt-cname-module", "max_stars_repo_stars_event_min_datetime": "2018-02-13T14:58:44.000Z", "max_stars_repo_stars_event_max_datetime": "2019-03-08T15:29:20.000Z", "max_issues_repo_path": "src/index.spec.js", "max_issues_repo_name": "FBerthelot/nuxt-cname-module", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/index.spec.js", "max_forks_repo_name": "FBerthelot/nuxt-cname-module", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 9, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 21.4623655914, "max_line_length": 79, "alphanum_fraction": 0.5716432866}
'use strict';

const proxyquire = require('proxyquire');
const expect = require('chai').expect;

let writeFileErr;
let unlinkErr;
let unlinkCalled;
let writeFileCalles;

const nuxtModule = proxyquire('./index', {
  fs: {
    writeFile(path, content, cb) {
      writeFileCalles = true;
      cb(writeFileErr, {path, content});
    },
    unlink(path, cb) {
      unlinkCalled = true;
      cb(unlinkErr, path);
    }
  }
});

describe('cname module', () => {
  const baseOptions = {
    srcDir: '/tmp/toto',
    generateCNAME: true,
    dev: false,
    generate: true
  };

  let nuxt;

  beforeEach(() => {
    nuxt = {
      options: baseOptions,
      nuxtModule
    };

    unlinkCalled = false;
    writeFileCalles = false;
    writeFileErr = null;
    unlinkErr = null;
  });

  it('should write CNAME file when in generate mode', () => {
    return nuxt.nuxtModule({baseUrl: 'github.com'})
      .then(() => {
        expect(writeFileCalles).to.be.true;
      });
  });

  it('should not write any file when it\'s not nuxt generate mode', () => {
    return nuxt.nuxtModule({
      generate: false
    })
      .then(() => {
        expect(unlinkCalled).to.be.false;
        expect(writeFileCalles).to.be.false;
      });
  });

  it('should not write any file when nuxt is in dev mode', () => {
    return nuxt.nuxtModule({
      dev: true
    })
      .then(() => {
        expect(unlinkCalled).to.be.false;
        expect(writeFileCalles).to.be.false;
      });
  });

  it('should not write any file when generateCNAME option is at false', () => {
    return nuxt.nuxtModule({
      generateCNAME: false
    })
      .then(() => {
        expect(unlinkCalled).to.be.false;
        expect(writeFileCalles).to.be.false;
      });
  });

  it('should not write any file when there is no baseUrl', () => {
    return nuxt.nuxtModule({
      baseUrl: null
    })
      .then(() => {
        expect(unlinkCalled).to.be.false;
        expect(writeFileCalles).to.be.false;
      });
  });
});
