<commit_before>/*global describe, it, beforeEach, afterEach, __dirname*/
var express = require('express'),
    fs = require('fs'),
    http = require('http'),
    pathModule = require('path'),
    unexpected = require('unexpected'),
    sinon = require('sinon'),
    Stream = require('stream'),
    processImage = require('../lib/processImage'),
    root = pathModule.resolve(__dirname, '..', 'testdata') + '/',
    sharp = require('sharp');

describe('express-processimage', function () {
    var config;
    var sandbox;
    beforeEach(function () {
        config = { root: root, filters: {} };
        sandbox = sinon.sandbox.create();
    });

    afterEach(function () {
        sandbox.restore();
    });

    var expect = unexpected.clone()
        .use(require('unexpected-express'))
        .use(require('unexpected-http'))
        .use(require('unexpected-image'))
        .use(require('unexpected-resemble'))
        .use(require('unexpected-sinon'))
        .use(require('magicpen-prism'))
        .addAssertion('<string|object> to yield response <object|number>', function (expect, subject, value) {
            return expect(
                express()
                    .use(processImage(config))
                    .use(express.static(root)),
                'to yield exchange', {
                    request: subject,
                    response: value
                }
            );
        })
        .addAssertion('<Buffer> [when] converted to PNG <assertion>', function (expect, subject) {
            expect.errorMode = 'bubble';
            return sharp(subject).png().toBuffer().then(function (pngBuffer) {
                return expect.shift(pngBuffer);
            });
        });
<commit_msg>sinon.sandbox.create() => sinon.createSandbox() now that the former is deprecated<commit_after>/*global describe, it, beforeEach, afterEach, __dirname*/
var express = require('express'),
    fs = require('fs'),
    http = require('http'),
    pathModule = require('path'),
    unexpected = require('unexpected'),
    sinon = require('sinon'),
    Stream = require('stream'),
    processImage = require('../lib/processImage'),
    root = pathModule.resolve(__dirname, '..', 'testdata') + '/',
    sharp = require('sharp');

describe('express-processimage', function () {
    var config;
    var sandbox;
    beforeEach(function () {
        config = { root: root, filters: {} };
        sandbox = sinon.createSandbox();
    });

    afterEach(function () {
        sandbox.restore();
    });

    var expect = unexpected.clone()
        .use(require('unexpected-express'))
        .use(require('unexpected-http'))
        .use(require('unexpected-image'))
        .use(require('unexpected-resemble'))
        .use(require('unexpected-sinon'))
        .use(require('magicpen-prism'))
        .addAssertion('<string|object> to yield response <object|number>', function (expect, subject, value) {
            return expect(
                express()
                    .use(processImage(config))
                    .use(express.static(root)),
                'to yield exchange', {
                    request: subject,
                    response: value
                }
            );
        })
        .addAssertion('<Buffer> [when] converted to PNG <assertion>', function (expect, subject) {
            expect.errorMode = 'bubble';
            return sharp(subject).png().toBuffer().then(function (pngBuffer) {
                return expect.shift(pngBuffer);
            });
        });

{'fraction_non_alphanumeric': 0.1540210287013356, 'fraction_numerical': 0.0, 'mean_word_length': 2.238270469181233, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 12, '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': '1317008', 'n_tokens_mistral': 948, 'n_tokens_neox': 920, 'n_words': 185}