<commit_before>console.log("node basic test");

//check if we are not in browser or webview
if (typeof window === "undefined") {
  console.log("we are not in webview or browser");

  var EventEmitter = require('events').EventEmitter;
  var fs = require('fs');
  var request = require('superagent');
  var url = require('url');
  var StringDecoder = require('string_decoder').StringDecoder;

} else {
  console.log("we are in webview or browser");

}

//desktop
if (typeof cordova === "undefined" && typeof window === "undefined") {
  console.log("we are in the desktop");
  var assert = require('better-assert')
      , should = require('should');
}

//test if we are using mocha
if(typeof describe !== "undefined") {
  console.log("run mocha tests for test/node/basic.js!");

  describe('[node] request', function () {


    //on Cordova this fails with: result[{"crossDomain":true},null]
    //describe('with an object', function () {
    //  it('should format the url', function (done) {
    //      console.log("uri" + JSON.stringify(url.parse('http://localhost:5000/login') ));
    //    request
    //        .get(url.parse('http://localhost:5000/login'))
    //        .end(function (err, res) {
    //            console.log("result" + JSON.stringify([err,res]));
    //          assert(res.ok);
    //          done();
    //        })
    //  })
    //});

    //on Cordova this fails, plugin-cordova-whitelist may filter response
    //describe('without a schema', function () {
    //  it('should default to http', function (done) {
    //    request
    //        .get('localhost:5000/login')
    //        .end(function (err, res) {
    //          assert(res.status == 200);
    //          done();
    //        })
    //  })
    //});

    describe('req.toJSON()', function () {
      it('should describe the request', function (done) {
        request
            .post('http://localhost:5000/echo')
            .send({foo: 'baz'})
            .end(function (err, res) {
              var obj = res.request.toJSON();
              assert('POST' == obj.method);
              assert('http://localhost:5000/echo' == obj.url);
              assert('baz' == obj.data.foo);
              done();
            });
      })
    });

    describe('should allow the send shorthand', function () {
      it('with callback in the method call', function (done) {
        request
            .get('http://localhost:5000/login', function (err, res) {
              assert(res.status == 200);
              done();
            });
      });

      it('with data in the method call', function (done) {
        request
            .post('http://localhost:5000/echo', {foo: 'bar'})
            .end(function (err, res) {
              assert('{"foo":"bar"}' == res.text);<commit_msg>finish superagent tests<commit_after>console.log("node basic test");

//check if we are not in browser or webview
if (typeof window === "undefined") {
  console.log("we are not in webview or browser");

  var EventEmitter = require('events').EventEmitter;
  var fs = require('fs');
  var request = require('superagent');
  var url = require('url');
  var StringDecoder = require('string_decoder').StringDecoder;

} else {
  console.log("we are in webview or browser");

}

//desktop
if (typeof cordova === "undefined" && typeof window === "undefined") {
  console.log("we are in the desktop");
  var assert = require('better-assert')
      , should = require('should');
}

//test if we are using mocha
if(typeof describe !== "undefined") {
  console.log("run mocha tests for test/node/basic.js!");

  describe('[node] request', function () {


    //on Cordova this fails with: result[{"crossDomain":true},null]
    //describe('with an object', function () {
    //  it('should format the url', function (done) {
    //      console.log("uri" + JSON.stringify(url.parse('http://localhost:5000/login') ));
    //    request
    //        .get(url.parse('http://localhost:5000/login'))
    //        .end(function (err, res) {
    //            console.log("result" + JSON.stringify([err,res]));
    //          assert(res.ok);
    //          done();
    //        })
    //  })
    //});

    //on Cordova this fails, plugin-cordova-whitelist may filter response
    //describe('without a schema', function () {
    //  it('should default to http', function (done) {
    //    request
    //        .get('localhost:5000/login')
    //        .end(function (err, res) {
    //          assert(res.status == 200);
    //          done();
    //        })
    //  })
    //});

    describe('req.toJSON()', function () {
      it('should describe the request', function (done) {
        request
            .post('http://localhost:5000/echo')
            .send({foo: 'baz'})
            .end(function (err, res) {
              if(err){console.log("error" + JSON.stringify([err,res]))}
              var obj = res.request.toJSON();
              assert('POST' == obj.method);
              assert('http://localhost:5000/echo' == obj.url);
              assert('baz' == obj.data.foo);
              done();
            });
      })
    });

    describe('should allow the send shorthand', function () {
      it('with callback in the method call', function (done) {
        request
            .get('http://localhost:5000/login', function (err, res) {
              assert(res.status == 200);
              done();
            });
      });

      it('with data in the method call', function (done) {
        request
            .post('http://localhost:5000/echo', {foo: 'bar'})
            .end(function (err, res) {
              assert('{"foo":"bar"}' == res.text);
{'fraction_non_alphanumeric': 0.17640807651434645, 'fraction_numerical': 0.012043924902585901, 'mean_word_length': 2.089168490153173, 'pattern_counts': {'":': 4, '<': 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': '1971768', 'n_tokens_mistral': 1684, 'n_tokens_neox': 1601, 'n_words': 397}