<commit_before>'use strict';

var gutil = require('gulp-util');
var should = require('should');
var bump = require('..');

require('mocha');

describe('gulp-bump: JSON comparison fixtures', function() {

  it('should bump patch version by default', function(done) {
    var fakeFile = new gutil.File({
      contents: new Buffer('{ "version": "0.0.9" }'),
      path: 'test/fixtures/test.json'
    });

    var bumpS = bump();

    bumpS.once('data', function(newFile) {
      should.exist(newFile);
      should.exist(newFile.contents);
      JSON.parse(newFile.contents.toString()).version.should.equal('0.0.10');
      return done();
    });
    bumpS.write(fakeFile);
    bumpS.end();
  });

  it('should bump patch version as default and a key=appversion', function(done) {
    var fakeFile = new gutil.File({
      contents: new Buffer('{ "appversion": "0.0.1" }'),
      path: 'test/fixtures/test.json'
    });

    var bumpS = bump({key: 'appversion'});

    bumpS.once('data', function(newFile) {
      should.exist(newFile);
      should.exist(newFile.contents);
      JSON.parse(newFile.contents.toString()).appversion.should.equal('0.0.2');
      return done();
    });
    bumpS.write(fakeFile);
    bumpS.end();
  });

  it('should ignore invalid type and use type=patch', function(done) {
    var fakeFile = new gutil.File({
      contents: new Buffer('{ "version": "0.0.1" }'),
      path: 'test/fixtures/test.json'
    });

    var bumpS = bump({type: 'invalidType'});

    bumpS.once('data', function(newFile) {
      should.exist(newFile);
      should.exist(newFile.contents);
      JSON.parse(newFile.contents.toString()).version.should.equal('0.0.2');
      return done();
    });

    bumpS.write(fakeFile);
    bumpS.end();
  });

  it('should set the correct version when supplied', function(done) {
    var fakeFile = new gutil.File({
      contents: new Buffer('{ "version": "0.0.1" }'),
      path: 'test/fixtures/test.json'
    });

    var bumpS = bump({version: '0.0.2'});

    bumpS.once('data', function(newFile) {
      should.exist(newFile);
      should.exist(newFile.contents);
      JSON.parse(newFile.contents.toString()).version.should.equal('0.0.2');
      return done();
    });
    bumpS.write(fakeFile);
    bumpS.end();
  });

  it('should set the correct version when supplied even if key did not exist', function(done) {
    var fakeFile = new gutil.File({
      contents: new Buffer('{}'),
      path: 'test/fixtures/test.json'
    });

    var bumpS = bump({version: '0.0.2'});

    bumpS.once('data', function(newFile) {
      should.exist(newFile);
      should.exist(newFile.contents);
      JSON.parse(newFile.contents.toString()).version.should.equal('0.0.2');
      return done();
    });
    bumpS.write(fakeFile);
    bumpS.end();
  });

  it('should bump prerelease version', function(done) {
    var fakeFile = new gutil.File({
      contents: new Buffer('{ "version": "0.0.1-0"}'),
      path: 'test/fixtures/test.json'
    });

    var bumpS = bump({type: 'prerelease'});

    bumpS.once('data', function(newFile) {
      should.exist(newFile);
      should.exist(newFile.contents);
      JSON.parse(newFile.contents.toString()).version.should.equal('0.0.1-1');
      return done();
    });
    bumpS.write(fakeFile);
    bumpS.end();
  });
});<commit_msg>add test for preid<commit_after>'use strict';

var gutil = require('gulp-util');
var should = require('should');
var bump = require('..');

require('mocha');

describe('gulp-bump: JSON comparison fixtures', function() {

  it('should bump patch version by default', function(done) {
    var fakeFile = new gutil.File({
      contents: new Buffer('{ "version": "0.0.9" }'),
      path: 'test/fixtures/test.json'
    });

    var bumpS = bump();

    bumpS.once('data', function(newFile) {
      should.exist(newFile);
      should.exist(newFile.contents);
      JSON.parse(newFile.contents.toString()).version.should.equal('0.0.10');
      return done();
    });
    bumpS.write(fakeFile);
    bumpS.end();
  });

  it('should bump patch version as default and a key=appversion', function(done) {
    var fakeFile = new gutil.File({
      contents: new Buffer('{ "appversion": "0.0.1" }'),
      path: 'test/fixtures/test.json'
    });

    var bumpS = bump({key: 'appversion'});

    bumpS.once('data', function(newFile) {
      should.exist(newFile);
      should.exist(newFile.contents);
      JSON.parse(newFile.contents.toString()).appversion.should.equal('0.0.2');
      return done();
    });
    bumpS.write(fakeFile);
    bumpS.end();
  });

  it('should ignore invalid type and use type=patch', function(done) {
    var fakeFile = new gutil.File({
      contents: new Buffer('{ "version": "0.0.1" }'),
      path: 'test/fixtures/test.json'
    });

    var bumpS = bump({type: 'invalidType'});

    bumpS.once('data', function(newFile) {
      should.exist(newFile);
      should.exist(newFile.contents);
      JSON.parse(newFile.contents.toString()).version.should.equal('0.0.2');
      return done();
    });

    bumpS.write(fakeFile);
    bumpS.end();
  });

  it('should set the correct version when supplied', function(done) {
    var fakeFile = new gutil.File({
      contents: new Buffer('{ "version": "0.0.1" }'),
      path: 'test/fixtures/test.json'
    });

    var bumpS = bump({version: '0.0.2'});

    bumpS.once('data', function(newFile) {
      should.exist(newFile);
      should.exist(newFile.contents);
      JSON.parse(newFile.contents.toString()).version.should.equal('0.0.2');
      return done();
    });
    bumpS.write(fakeFile);
    bumpS.end();
  });

  it('should set the correct version when supplied even if key did not exist', function(done) {
    var fakeFile = new gutil.File({
      contents: new Buffer('{}'),
      path: 'test/fixtures/test.json'
    });

    var bumpS = bump({version: '0.0.2'});

    bumpS.once('data', function(newFile) {
      should.exist(newFile);
      should.exist(newFile.contents);
      JSON.parse(newFile.contents.toString()).version.should.equal('0.0.2');
      return done();
    });
    bumpS.write(fakeFile);
    bumpS.end();
  });

  it('should bump prerelease version', function(done) {
    var fakeFile = new gutil.File({
      contents: new Buffer('{ "version": "0.0.1-0"}'),
      path: 'test/fixtures/test.json'
    });

    var bumpS = bump({type: 'prerelease'});

    bumpS.once('data', function(newFile) {
      should.exist(newFile);
      should.exist(newFile.contents);
      JSON.parse(newFile.contents.toString()).version.should.equal('0.0.1-1');
      return done();
    });
    bumpS.write(fakeFile);
    bumpS.end();
  });

  it('should add and bump preid version', function(done) {
    var fakeFile = new gutil.File({
      contents: new Buffer('{ "version": "0.1.0"}'),
      path: 'test/fixtures/test.json'
    });

    var bumpS = bump({type: 'prerelease', preid: 'beta'});

    bumpS.once('data', function(newFile) {
      should.exist(newFile);
      should.exist(newFile.contents);
      console.log(String(newFile.contents));
      JSON.parse(newFile.contents.toString()).version.should.equal('0.1.1-beta.0');
      return done();
    });
    bumpS.write(fakeFile);
    bumpS.end();
  });

  it('should bump preid version', function(done) {
    var fakeFile = new gutil.File({
      contents: new Buffer('{ "version": "0.1.0-zeta.1"}'),
      path: 'test/fixtures/test.json'
    });

    var bumpS = bump({type: 'prerelease', preid: 'zeta'});

    bumpS.once('data', function(newFile) {
      should.exist(newFile);
      should.exist(newFile.contents);
      console.log(String(newFile.contents));
      JSON.parse(newFile.contents.toString()).version.should.equal('0.1.0-zeta.2');
      return done();
    });
    bumpS.write(fakeFile);
    bumpS.end();
  });
});
{'fraction_non_alphanumeric': 0.18469047007449269, 'fraction_numerical': 0.012715129720010274, 'mean_word_length': 3.0472972972972974, 'pattern_counts': {'":': 12, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1145608', 'n_tokens_mistral': 2613, 'n_tokens_neox': 2596, 'n_words': 489}