<commit_before>/*global describe, it*/
var unexpected = require('unexpected'),
    expressExtractHeaders = require('../lib/expressExtractHeaders'),
    express = require('express'),
    passError = require('passerror');

describe('expressExtractHeaders', function () {
    var expect = unexpected.clone()
        .installPlugin(require('unexpected-express'))
        .installPlugin(require('unexpected-sinon'));

    it('should specify response headers based on <meta> tags in the response body', function (done) {
        var responseHtml =
            '<!DOCTYPE html>\n<html><head><meta http-equiv="Foo" content="Bar"></head><body>foo</body></html>';
        expect(
            express()
                .use(expressExtractHeaders())
                .use(function (req, res) {
                    res.send(responseHtml);
                }),
            'to be middleware that processes', {
                request: '/',
                response: {
                    headers: {
                        'Content-Type': 'text/html; charset=utf-8',
                        Foo: 'Bar'
                    },
                    body: responseHtml
                }
            },<commit_msg>Added test.<commit_after>/*global describe, it*/
var unexpected = require('unexpected'),
    expressExtractHeaders = require('../lib/expressExtractHeaders'),
    express = require('express'),
    passError = require('passerror');

describe('expressExtractHeaders', function () {
    var expect = unexpected.clone()
        .installPlugin(require('unexpected-express'))
        .installPlugin(require('unexpected-sinon'));

    it('should leave a non-text/html response alone', function (done) {
        expect(
            express()
                .use(expressExtractHeaders())
                .use(function (req, res) {
                    res.setHeader('Foo', 'Quux');
                    res.setHeader('Content-Type', 'text/something-else');
                    res.send('<!DOCTYPE html>\n<html><head><meta http-equiv="Foo" content="Bar"></head><body>foo</body></html>');
                }),
            'to be middleware that processes', {
                request: '/',
                response: {
                    headers: {
                        'Content-Type': 'text/something-else; charset=utf-8',
                        Foo: 'Quux'
                    }
                }
            },
            done
        );
    });

    it('should specify response headers based on <meta> tags in the response body', function (done) {
        var responseHtml =
            '<!DOCTYPE html>\n<html><head><meta http-equiv="Foo" content="Bar"></head><body>foo</body></html>';
        expect(
            express()
                .use(expressExtractHeaders())
                .use(function (req, res) {
                    res.send(responseHtml);
                }),
            'to be middleware that processes', {
                request: '/',
                response: {
                    headers: {
                        'Content-Type': 'text/html; charset=utf-8',
                        Foo: 'Bar'
                    },
                    body: responseHtml
                }
            },
{'fraction_non_alphanumeric': 0.1366051891216005, 'fraction_numerical': 0.0009377930603313535, 'mean_word_length': 1.576489533011272, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, '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': '7223237', 'n_tokens_mistral': 806, 'n_tokens_neox': 754, 'n_words': 159}