<commit_before>const chai = require('chai')
const expect = chai.expect
const path = require('path')
const fs = require('fs')
const os = require('os')
const YAML = require('yamljs')
const Promise = require('bluebird')
const pkg = require('../package')

describe('grql', function() {
  let config, grql, sampleServer

  this.timeout(10000)

  before(() => {
    process.env['NODE_ENV'] = 'test'
    config = require('../lib/config')
    config.configFile = path.join(os.tmpdir(), `.${pkg.name}.yml`)
    grql = require('../lib/grql')
    sampleServer = require('./sample-server')
  })

  after(() => Promise.resolve()
    .then(() => {
      if (!config.configFile) {
        return
      }
      return Promise.fromCallback(cb => fs.unlink(config.configFile, cb))
    })
  )

  it('should return an error if no argument', () => grql()
    .then(
      result => {
        throw new Error('should no return a result')
      },
      err => {
        expect(err).to.be.an('error')
        expect(err).to.have.property('message', grql.__('Error : missing argument'))
      }
    )
  )

  it('should show help', () => grql('--help')
    .then(result => {
      expect(result).to.have.property('stderr').that.is.a('string')
    })
  )

  describe('sample server', () => {

    before(() => sampleServer.start()
      .then(() => {
        const port = sampleServer.getPort()
        return grql(
          '-e', 'test',
          '-b', `http://localhost:${port}/graphql`,
          '-s'
        )
      })
    )

    after(() => sampleServer.stop())

    it('should return schema', () => grql('--schema')
      .then(result => {
        expect(result).to.have.property('stdout')
        const out = JSON.parse(result.stdout)
        expect(Object.keys(out)).to.eql(['queryType',
          'mutationType',
          'subscriptionType',
          'types',
          'directives'
        ])
      })
    )

    it('should return hello', () => grql('{ hello }')
      .then(result => {
        expect(result).to.have.property('stdout')
        const out = JSON.parse(result.stdout)
        expect(out).to.eql({hello: 'world'})
      })
    )

    it('should return hello in yaml format', () => grql('-y', '{ hello }')
      .then(result => {
        expect(result).to.have.property('stdout')
        const out = YAML.parse(result.stdout)
        expect(out).to.eql({hello: 'world'})
      })
    )

  })

})<commit_msg>tests<commit_after>const chai = require('chai')
const expect = chai.expect
const path = require('path')
const fs = require('fs')
const os = require('os')
const YAML = require('yamljs')
const Promise = require('bluebird')
const pkg = require('../package')

describe('grql', function() {
  let config, grql, sampleServer

  this.timeout(10000)

  before(() => {
    process.env['NODE_ENV'] = 'test'
    config = require('../lib/config')
    config.configFile = path.join(os.tmpdir(), `.${pkg.name}.yml`)
    grql = require('../lib/grql')
    sampleServer = require('./sample-server')
  })

  after(() => Promise.resolve()
    .then(() => {
      if (!config.configFile) {
        return
      }
      return Promise.fromCallback(cb => fs.unlink(config.configFile, cb))
    })
  )

  it('should return an error if no argument', () => grql()
    .then(
      result => {
        throw new Error('should no return a result')
      },
      err => {
        expect(err).to.be.an('error')
        expect(err).to.have.property('message', grql.__('Error : missing argument'))
      }
    )
  )

  it('should show help', () => grql('--nocolor', '--help')
    .then(result => {
      expect(result).to.have.property('stderr').that.is.a('string')
    })
  )

  describe('sample server', () => {

    before(() => sampleServer.start()
      .then(() => {
        const port = sampleServer.getPort()
        return grql(
          '--nocolor',
          '-e', 'test',
          '-b', `http://localhost:${port}/graphql`,
          '-s'
        )
      })
    )

    after(() => sampleServer.stop())

    it('should return schema', () => grql('--nocolor', '--schema')
      .then(result => {
        expect(result).to.have.property('stdout')
        const out = JSON.parse(result.stdout)
        expect(Object.keys(out)).to.eql(['queryType',
          'mutationType',
          'subscriptionType',
          'types',
          'directives'
        ])
      })
    )

    it('should return hello', () => grql('--nocolor', '{ hello }')
      .then(result => {
        expect(result).to.have.property('stdout')
        const out = JSON.parse(result.stdout)
        expect(out).to.eql({hello: 'world'})
      })
    )

    it('should return hello in yaml format', () => grql('--nocolor', '-y', '{ hello }')
      .then(result => {
        expect(result).to.have.property('stdout')
        const out = YAML.parse(result.stdout)
        expect(out).to.eql({hello: 'world'})
      })
    )

  })

})
{'fraction_non_alphanumeric': 0.19672466734902763, 'fraction_numerical': 0.0020470829068577278, 'mean_word_length': 2.3192934782608696, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 41, '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': '610361', 'n_tokens_mistral': 1583, 'n_tokens_neox': 1532, 'n_words': 284}