<commit_before>"use strict";

var chai = require("chai");
var expect = chai.expect;

var http = require("http");
var express = require("express");
var serveStatic = require("serve-static");
var app = express();

var sjs = require("scraperjs");

var BASE_URL = "http://localhost";
var PORT = 3000;
var SERVER_LISTENING = BASE_URL + ":" + PORT;
var ERROR_PAGE = "/404.html";

describe("server", function () {

  before(function (done) {
    app.use(serveStatic(__dirname));
    app.listen(PORT);
    console.log("server started.");
    done();
  });

  after(function (done) {
    // if the server still runs, we would get the statusCode.
    http.get(SERVER_LISTENING, function (res) {
      console.log("STATUS after: " + res.statusCode);
    });
    console.log("Server stopped");
    done();
  });

  it("Should match h1 from index.html", function (done) {

    sjs.StaticScraper.create(SERVER_LISTENING)
      .scrape(function ($) {
        return $("h1").text();
      })
      .then(function (data) {
        expect(data).to.eql("this is a test file");
        done();
      });
  });

  it("Should fetch index.html", function (done) {

    sjs.StaticScraper.create(SERVER_LISTENING + ERROR_PAGE)
      .scrape(function ($) {
        return $("h1").text();
      })
      .then(function (data) {
        expect(data).to.eql("Not found");
        done();
      });
  });

});<commit_msg>adding prevention for server to run twice<commit_after>"use strict";

var chai = require("chai");
var expect = chai.expect;

var http = require("http");
var express = require("express");
var serveStatic = require("serve-static");
var app = express();

var sjs = require("scraperjs");

var BASE_URL = "http://localhost";
var PORT = 3000;
var SERVER_LISTENING = BASE_URL + ":" + PORT;
var ERROR_PAGE = "/404.html";
var serverStarted = false;

describe("server", function () {

  before(function (done) {
    console.log(serverStarted);
    if (!serverStarted) {
      serverStarted = true;
      app.use(serveStatic(__dirname));
      console.log("server started.");
      app.listen(PORT);
    }
    done();
  });

  after(function (done) {
    // if the server still runs, we would get the statusCode.
    http.get(SERVER_LISTENING, function (res) {
      console.log("STATUS after: " + res.statusCode);
    });
    console.log("Server stopped");
    app.close();
    done();
  });

  it("Should match h1 from index.html", function (done) {

    sjs.StaticScraper.create(SERVER_LISTENING)
      .scrape(function ($) {
        return $("h1").text();
      })
      .then(function (data) {
        expect(data).to.eql("this is a test file");
        done();
      });
  });

  it("Should fetch index.html", function (done) {

    sjs.StaticScraper.create(SERVER_LISTENING + ERROR_PAGE)
      .scrape(function ($) {
        return $("h1").text();
      })
      .then(function (data) {
        expect(data).to.eql("Not found");
        done();
      });
  });

});
{'fraction_non_alphanumeric': 0.17242547425474256, 'fraction_numerical': 0.006775067750677507, 'mean_word_length': 2.9690860215053765, 'pattern_counts': {'":': 2, '<': 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': '3923655', 'n_tokens_mistral': 981, 'n_tokens_neox': 950, 'n_words': 215}