<commit_before>fs = require 'fs'

{CWebp} = require '../src'
data = require './utils/data'

describe 'cwebp', ->

  describe 'cwebp', ->

    it 'should encode images', ->
      webp = new CWebp data.jpeg
      webp.toBuffer().then (buffer) ->
        buffer.toString('utf8', 0, 4).should.be.equal 'RIFF'
        buffer.toString('utf8', 8, 12).should.be.equal 'WEBP'

    it 'should work without new', ->
      webp = CWebp data.jpeg
      webp.toBuffer().then (buffer) ->
        buffer.toString('utf8', 0, 4).should.be.equal 'RIFF'
        buffer.toString('utf8', 8, 12).should.be.equal 'WEBP'

    it 'should report verbose errors', ->
      webp = new CWebp data.corrupt
      webp.verbose().toBuffer().then ->
        throw new Error 'Should not be fulfilled'
      , (err) ->
        err.should.be.Error
        err.message.should.match /Premature end of JPEG file/
        err.message.should.match /JPEG datastream contains no image/

    it 'should allow default verbose rewriting', ->
      class Webp3 extends CWebp
        @verbose: true
      webp = new Webp3 data.corrupt
      webp.toBuffer().then ->
        throw new Error 'Should not be fulfilled'
      , (err) ->
        err.should.be.Error
        err.message.should.match /Premature end of JPEG file/
        err.message.should.match /JPEG datastream contains no image/

    it 'should cleanup tmp files on error', ->
      filename = ''
      webp = new CWebp data.corrupt
      promise = webp.toBuffer()
      webp._tmpFilename.then (tmpFilename) ->
        filename = tmpFilename
        filename.should.not.be.empty
        fs.existsSync(filename).should.be.true
        promise
      .delay(1).then ->
        throw new Error 'Should not be fulfilled'
      , (err) ->
        err.should.be.Error
        filename.should.not.be.empty
        fs.existsSync(filename).should.be.false<commit_msg>Removed delay<commit_after>fs = require 'fs'

{CWebp} = require '../src'
data = require './utils/data'

describe 'cwebp', ->

  describe 'cwebp', ->

    it 'should encode images', ->
      webp = new CWebp data.jpeg
      webp.toBuffer().then (buffer) ->
        buffer.toString('utf8', 0, 4).should.be.equal 'RIFF'
        buffer.toString('utf8', 8, 12).should.be.equal 'WEBP'

    it 'should work without new', ->
      webp = CWebp data.jpeg
      webp.toBuffer().then (buffer) ->
        buffer.toString('utf8', 0, 4).should.be.equal 'RIFF'
        buffer.toString('utf8', 8, 12).should.be.equal 'WEBP'

    it 'should report verbose errors', ->
      webp = new CWebp data.corrupt
      webp.verbose().toBuffer().then ->
        throw new Error 'Should not be fulfilled'
      , (err) ->
        err.should.be.Error
        err.message.should.match /Premature end of JPEG file/
        err.message.should.match /JPEG datastream contains no image/

    it 'should allow default verbose rewriting', ->
      class Webp3 extends CWebp
        @verbose: true
      webp = new Webp3 data.corrupt
      webp.toBuffer().then ->
        throw new Error 'Should not be fulfilled'
      , (err) ->
        err.should.be.Error
        err.message.should.match /Premature end of JPEG file/
        err.message.should.match /JPEG datastream contains no image/

    it 'should cleanup tmp files on error', ->
      filename = ''
      webp = new CWebp data.corrupt
      promise = webp.toBuffer()
      webp._tmpFilename.then (tmpFilename) ->
        filename = tmpFilename
        filename.should.not.be.empty
        fs.existsSync(filename).should.be.true
        promise
      .then ->
        throw new Error 'Should not be fulfilled'
      , (err) ->
        err.should.be.Error
        filename.should.not.be.empty
        fs.existsSync(filename).should.be.false
{'fraction_non_alphanumeric': 0.12577098417806382, 'fraction_numerical': 0.008849557522123894, 'mean_word_length': 2.196229648671808, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 35, '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': '5586005', 'n_tokens_mistral': 1195, 'n_tokens_neox': 1146, 'n_words': 302}