<commit_before>'use strict';

var assert = require('assert'),
    api = require('../api/api'),
    crawler = require('./crawler'),
    promiseIt = require('../testHelpers').promiseIt;

function expectedContentType (contentType) {
    if (!contentType) {
        return true;
    }
    return ['text/html', 'application/atom+xml'].some(function (type) {
        return contentType.indexOf(type) >= 0;
    });
}

function expectedStatusCode (statusCode) {
    return [200, 301, 302].indexOf(statusCode) >= 0;
}

if (process.env.MB_AIRPLANE_MODE !== 'true' && process.env.MB_RUN_WEB_TESTS === 'true') {
    describe('The mountebank website', function () {
        this.timeout(30000);

        promiseIt('should have no dead links and a valid sitemap', function () {
            var crawlResults;
            return crawler.create().crawl(api.url + '/', '').then(function (result) {
                // Validate no broken links
                var errors = {misses: {}};
                errors.errors = result.errors;
                Object.keys(result.hits).forEach(function (link) {
                    if (!expectedStatusCode(result.hits[link].statusCode) || !expectedContentType(result.hits[link].contentType)) {
                        errors.misses[link] = result.hits[link];
                    }
                });

                assert.deepEqual(errors, {errors: [], misses: {}}, JSON.stringify(errors, null, 4));

                crawlResults = result;
                return api.get('/sitemap');
            }).then(function (response) {
                var siteLinks = Object.keys(crawlResults.hits).filter(function (link) {
                        return link.indexOf(api.url) === 0 && link.indexOf('#') < 0 && link.indexOf('?') < 0;
                    }).map(function (link) {
                        return link.replace(api.url, 'http://www.mbtest.org');
                    }),
                    linksNotInSitemap = siteLinks.filter(function (link) {<commit_msg>Moving if block up to work around Appveyor jsdom failure<commit_after>'use strict';

if (process.env.MB_AIRPLANE_MODE !== 'true' && process.env.MB_RUN_WEB_TESTS === 'true') {
    var assert = require('assert'),
        api = require('../api/api'),
        crawler = require('./crawler'),
        promiseIt = require('../testHelpers').promiseIt;

    function expectedContentType (contentType) {
        if (!contentType) {
            return true;
        }
        return ['text/html', 'application/atom+xml'].some(function (type) {
            return contentType.indexOf(type) >= 0;
        });
    }

    function expectedStatusCode (statusCode) {
        return [200, 301, 302].indexOf(statusCode) >= 0;
    }

    describe('The mountebank website', function () {
        this.timeout(30000);

        promiseIt('should have no dead links and a valid sitemap', function () {
            var crawlResults;
            return crawler.create().crawl(api.url + '/', '').then(function (result) {
                // Validate no broken links
                var errors = {misses: {}};
                errors.errors = result.errors;
                Object.keys(result.hits).forEach(function (link) {
                    if (!expectedStatusCode(result.hits[link].statusCode) || !expectedContentType(result.hits[link].contentType)) {
                        errors.misses[link] = result.hits[link];
                    }
                });

                assert.deepEqual(errors, {errors: [], misses: {}}, JSON.stringify(errors, null, 4));

                crawlResults = result;
                return api.get('/sitemap');
            }).then(function (response) {
                var siteLinks = Object.keys(crawlResults.hits).filter(function (link) {
                        return link.indexOf(api.url) === 0 && link.indexOf('#') < 0 && link.indexOf('?') < 0;
                    }).map(function (link) {
                        return link.replace(api.url, 'http://www.mbtest.org');
                    }),
                    linksNotInSitemap = siteLinks.filter(function (link) {
{'fraction_non_alphanumeric': 0.14718188530642382, 'fraction_numerical': 0.009844942160964805, 'mean_word_length': 2.0103703703703704, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, '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': '3811391', 'n_tokens_mistral': 1175, 'n_tokens_neox': 1100, 'n_words': 221}