<commit_before>fs = require 'fs'
path = require 'path'

polvo = require '../../lib/polvo'


base = path.join __dirname, '..', 'mocks', 'basic'
files = 
  pack: path.join base, 'package.json'
  config: path.join base, 'polvo.yml'
  js: path.join base, 'public', 'app.js'
  css: path.join base, 'public', 'app.css'

config = """
input:
  - src

output:
  js: public/app.js
  css: public/app.css

virtual:
  mapped: mapped/src

boot: src/app/app
"""

pack = '{"name": "basic"}'

clear_cache = ->
  mod = require.resolve '../../lib/utils/plugins'
  delete require.cache[mod]

describe '[polvo]', ->

  before ->
    fs.unlinkSync files.config if fs.existsSync files.config
    fs.unlinkSync files.pack if fs.existsSync files.pack
    fs.unlinkSync files.js if fs.existsSync files.js
    fs.unlinkSync files.css if fs.existsSync files.css

    fs.writeFileSync files.config, config

  afterEach ->

  after ->
    fs.unlinkSync files.config if fs.existsSync files.config
    fs.unlinkSync files.pack if fs.existsSync files.pack
    fs.unlinkSync files.js if fs.existsSync files.js
    fs.unlinkSync files.css if fs.existsSync files.css


  it 'should alert about no `package.json` file plugins during compile', ->
    errors = outs = 0
    checker = /^info app doesn't have a `package.json`/m

    options = compile: true, base: base
    stdio = 
      nocolor: true
      err:(msg)-> errors++
      out:(msg)->
        if outs is 0
          checker.test(msg).should.be.true
          outs++

    clear_cache()
    compile = polvo options, stdio
    
    outs.should.equal 1
    errors.should.equal 0


  it 'should compile project without any surprises', ->
    errors = outs = 0
    checker = /✓ public\/app\.(js|css).+$/m

    options = compile: true, base: base
    stdio = 
      nocolor: true
      err:(msg) -> errors++
      out:(msg) ->
        outs++
        checker.test(msg).should.be.true

    console.log 'WROTE!', files.pack
    clear_cache()
    fs.writeFileSync files.pack, pack
    compile = polvo options, stdio

    outs.should.equal 2
    errors.should.equal 0


  it 'should release project without any surprises', ->
    errors = outs = 0
    checker = /✓ public\/app\.(js|css).+$/m

    options = release: true, base: base
    stdio = 
      out:(msg) -> checker.test(msg).should.be.true
      err:(msg) -> errors++
      nocolor: true

    compile = polvo options, stdio<commit_msg>Removing log call<commit_after>fs = require 'fs'
path = require 'path'

polvo = require '../../lib/polvo'


base = path.join __dirname, '..', 'mocks', 'basic'
files = 
  pack: path.join base, 'package.json'
  config: path.join base, 'polvo.yml'
  js: path.join base, 'public', 'app.js'
  css: path.join base, 'public', 'app.css'

config = """
input:
  - src

output:
  js: public/app.js
  css: public/app.css

virtual:
  mapped: mapped/src

boot: src/app/app
"""

pack = '{"name": "basic"}'

clear_cache = ->
  mod = require.resolve '../../lib/utils/plugins'
  delete require.cache[mod]

describe '[polvo]', ->

  before ->
    fs.unlinkSync files.config if fs.existsSync files.config
    fs.unlinkSync files.pack if fs.existsSync files.pack
    fs.unlinkSync files.js if fs.existsSync files.js
    fs.unlinkSync files.css if fs.existsSync files.css

    fs.writeFileSync files.config, config

  afterEach ->

  after ->
    fs.unlinkSync files.config if fs.existsSync files.config
    fs.unlinkSync files.pack if fs.existsSync files.pack
    fs.unlinkSync files.js if fs.existsSync files.js
    fs.unlinkSync files.css if fs.existsSync files.css


  it 'should alert about no `package.json` file plugins during compile', ->
    errors = outs = 0
    checker = /^info app doesn't have a `package.json`/m

    options = compile: true, base: base
    stdio = 
      nocolor: true
      err:(msg)-> errors++
      out:(msg)->
        if outs is 0
          checker.test(msg).should.be.true
          outs++

    clear_cache()
    compile = polvo options, stdio
    
    outs.should.equal 1
    errors.should.equal 0


  it 'should compile project without any surprises', ->
    errors = outs = 0
    checker = /✓ public\/app\.(js|css).+$/m

    options = compile: true, base: base
    stdio = 
      nocolor: true
      err:(msg) -> errors++
      out:(msg) ->
        outs++
        checker.test(msg).should.be.true

    clear_cache()
    fs.writeFileSync files.pack, pack
    compile = polvo options, stdio

    outs.should.equal 2
    errors.should.equal 0


  it 'should release project without any surprises', ->
    errors = outs = 0
    checker = /✓ public\/app\.(js|css).+$/m

    options = release: true, base: base
    stdio = 
      out:(msg) -> checker.test(msg).should.be.true
      err:(msg) -> errors++
      nocolor: true

    compile = polvo options, stdio
{'fraction_non_alphanumeric': 0.1345065996228787, 'fraction_numerical': 0.0033521893987010264, 'mean_word_length': 2.5206489675516224, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 31, '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': '1324410', 'n_tokens_mistral': 1652, 'n_tokens_neox': 1568, 'n_words': 436}