<commit_before>// Copyright (c) 2012 Titanium I.T. LLC. All rights reserved. See LICENSE.txt for details.
(function() {
	"use strict";

	var server = require("./server.js");
	var http = require("http");
	var fs = require("fs");
	var async = require("async");
	var assert = require("../shared/_assert.js");

	var CONTENT_DIR = "generated/test";

	var INDEX_PAGE = "index.html";
	var OTHER_PAGE = "other.html";
	var NOT_FOUND_PAGE = "test404.html";

	var INDEX_PAGE_DATA = "This is index page file";
	var OTHER_PAGE_DATA = "This is another page";
	var NOT_FOUND_DATA = "This is 404 page file";

	var PORT = 5020;
	var BASE_URL = "http://localhost:" + PORT;

	var TEST_FILES = [
		[ CONTENT_DIR + "/" + INDEX_PAGE, INDEX_PAGE_DATA],
		[ CONTENT_DIR + "/" + OTHER_PAGE, OTHER_PAGE_DATA],
		[ CONTENT_DIR + "/" + NOT_FOUND_PAGE, NOT_FOUND_DATA]
	];

	describe("Server", function() {

		beforeEach(function(done) {
			async.each(TEST_FILES, createTestFile, done);
		});

		afterEach(function(done) {
			async.each(TEST_FILES, deleteTestFile, done);
		});

		it("serves files from directory", function(done) {
			httpGet(BASE_URL + "/" + INDEX_PAGE, function(response, responseData) {
				assert.equal(200, response.statusCode, "status code");
				assert.equal(INDEX_PAGE_DATA, responseData, "response text");
				done();
			});
		});

		it("supports multiple files", function(done) {
			httpGet(BASE_URL + "/" + OTHER_PAGE, function(response, responseData) {
				assert.equal(200, response.statusCode, "status code");
				assert.equal(OTHER_PAGE_DATA, responseData, "response text");
				done();
			});
		});

		it("supports multiple files", function(done) {
			httpGet(BASE_URL + "/" + OTHER_PAGE, function(response, responseData) {
				assert.equal(200, response.statusCode, "status code");
				assert.equal(OTHER_PAGE_DATA, responseData, "response text");
				done();
			});
		});

		it("serves index.html when asked for home page", function(done) {
			httpGet(BASE_URL, function(response, responseData) {
				assert.equal(200, response.statusCode, "status code");
				assert.equal(INDEX_PAGE_DATA, responseData, "response text");
				done();
			});
		});

		it("returns 404 when file doesn't exist", function(done) {
			httpGet(BASE_URL + "/bargle", function(response, responseData) {
				assert.equal(404, response.statusCode, "status code");
				assert.equal(NOT_FOUND_DATA, responseData, "404 text");
				done();
			});
		});

		it("requires home page parameter", function() {
			assert.throws(function() {
				server.start();
			});
		});

		it("requires 404 page parameter", function() {
			assert.throws(function() {
				server.start(CONTENT_DIR);
			});
		});

		it("requires port parameter", function() {
			assert.throws(function() {
				server.start(CONTENT_DIR, NOT_FOUND_PAGE);
			});
		});

		it("runs callback when stop completes", function(done) {
			server.start(CONTENT_DIR, NOT_FOUND_PAGE, PORT);
			server.stop(function() {
				done();
			});
		});

		it("stop throws exception when not running", function() {
			assert.throws(function() {
				server.stop();
			});
		});

	});

	function httpGet(url, callback) {
		server.start(CONTENT_DIR, NOT_FOUND_PAGE, PORT, function() {
			http.get(url, function(response) {
				var receivedData = "";
				response.setEncoding("utf8");
<commit_msg>Modified server test to reflect 0.12 behavior<commit_after>// Copyright (c) 2012 Titanium I.T. LLC. All rights reserved. See LICENSE.txt for details.
(function() {
	"use strict";

	var server = require("./server.js");
	var http = require("http");
	var fs = require("fs");
	var async = require("async");
	var assert = require("../shared/_assert.js");

	var CONTENT_DIR = "generated/test";

	var INDEX_PAGE = "index.html";
	var OTHER_PAGE = "other.html";
	var NOT_FOUND_PAGE = "test404.html";

	var INDEX_PAGE_DATA = "This is index page file";
	var OTHER_PAGE_DATA = "This is another page";
	var NOT_FOUND_DATA = "This is 404 page file";

	var PORT = 5020;
	var BASE_URL = "http://localhost:" + PORT;

	var TEST_FILES = [
		[ CONTENT_DIR + "/" + INDEX_PAGE, INDEX_PAGE_DATA],
		[ CONTENT_DIR + "/" + OTHER_PAGE, OTHER_PAGE_DATA],
		[ CONTENT_DIR + "/" + NOT_FOUND_PAGE, NOT_FOUND_DATA]
	];

	describe("Server", function() {

		beforeEach(function(done) {
			async.each(TEST_FILES, createTestFile, done);
		});

		afterEach(function(done) {
			async.each(TEST_FILES, deleteTestFile, done);
		});

		it("serves files from directory", function(done) {
			httpGet(BASE_URL + "/" + INDEX_PAGE, function(response, responseData) {
				assert.equal(200, response.statusCode, "status code");
				assert.equal(INDEX_PAGE_DATA, responseData, "response text");
				done();
			});
		});

		it("supports multiple files", function(done) {
			httpGet(BASE_URL + "/" + OTHER_PAGE, function(response, responseData) {
				assert.equal(200, response.statusCode, "status code");
				assert.equal(OTHER_PAGE_DATA, responseData, "response text");
				done();
			});
		});

		it("supports multiple files", function(done) {
			httpGet(BASE_URL + "/" + OTHER_PAGE, function(response, responseData) {
				assert.equal(200, response.statusCode, "status code");
				assert.equal(OTHER_PAGE_DATA, responseData, "response text");
				done();
			});
		});

		it("serves index.html when asked for home page", function(done) {
			httpGet(BASE_URL, function(response, responseData) {
				assert.equal(200, response.statusCode, "status code");
				assert.equal(INDEX_PAGE_DATA, responseData, "response text");
				done();
			});
		});

		it("returns 404 when file doesn't exist", function(done) {
			httpGet(BASE_URL + "/bargle", function(response, responseData) {
				assert.equal(404, response.statusCode, "status code");
				assert.equal(NOT_FOUND_DATA, responseData, "404 text");
				done();
			});
		});

		it("requires home page parameter", function() {
			assert.throws(function() {
				server.start();
			});
		});

		it("requires 404 page parameter", function() {
			assert.throws(function() {
				server.start(CONTENT_DIR);
			});
		});

		it("requires port parameter", function() {
			assert.throws(function() {
				server.start(CONTENT_DIR, NOT_FOUND_PAGE);
			});
		});

		it("runs callback when stop completes", function(done) {
			server.start(CONTENT_DIR, NOT_FOUND_PAGE, PORT);
			server.stop(function() {
				done();
			});
		});

		it("stop() provides error parameter if the server isn't running", function(done) {
			server.stop(function(err) {
				assert.defined(err);
				done();
			});
		});

	});

	function httpGet(url, callback) {
		server.start(CONTENT_DIR, NOT_FOUND_PAGE, PORT, function() {
			http.get(url, function(response) {
				var receivedData = "";
				response.setEncoding("utf8");

{'fraction_non_alphanumeric': 0.15868979958121449, 'fraction_numerical': 0.012114866886030511, 'mean_word_length': 4.112385321100917, 'pattern_counts': {'":': 0, '<': 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': '5870427', 'n_tokens_mistral': 2582, 'n_tokens_neox': 2157, 'n_words': 484}