<commit_before>const Quagga = require('../../src/quagga').default;
const async = require('async');

describe('decodeSingle', function () {
    var baseFolder = "base/test/fixtures/";

    function generateConfig() {
        return {
            inputStream: {
                size: 640
            },
            locator: {
                patchSize: "medium",
                halfSample: true
            },
            numOfWorkers: 0,
            decoder: {
                readers: ["ean_reader"]
            },
            locate: true,
            src: null
        };
    }

    this.timeout(10000);

    function _runTestSet(testSet, config) {
        var readers = config.decoder.readers.slice(),
            format,
            folder,
            suffix;

        if (typeof readers[0] === 'string'){
            format = readers[0];
        } else {
            if (readers[0].config && readers[0].config.supplements && readers[0].config.supplements.length) {
                suffix = "extended";
            }
            format = readers[0].format;
        }

        folder = baseFolder + format.split('_').slice(0, -1).concat(suffix ? [suffix] : []).join('_') + "/";

        it('should decode ' + folder + " correctly", function(done) {
            async.eachSeries(testSet, function (sample, callback) {
                config.src = folder + sample.name;
                config.readers = readers;
                Quagga.decodeSingle(config, function(result) {
                    console.log(sample.name);
                    expect(result.codeResult.code).to.equal(sample.result);
                    expect(result.codeResult.format).to.equal(sample.format);
                    callback();
                });
            }, function() {
                done();
            });
        });
    }

    describe("EAN", function() {
        var config = generateConfig(),
            testSet = [
                {"name": "image-001.jpg", "result": "3574660239843"},
                {"name": "image-002.jpg", "result": "8032754490297"},
                {"name": "image-003.jpg", "result": "4006209700068"},
                /* {"name": "image-004.jpg", "result": "9002233139084"}, */
                /* {"name": "image-005.jpg", "result": "8004030044005"}, */
                {"name": "image-006.jpg", "result": "4003626011159"},
                {"name": "image-007.jpg", "result": "2111220009686"},
                {"name": "image-008.jpg", "result": "9000275609022"},
                {"name": "image-009.jpg", "result": "9004593978587"},
                {"name": "image-010.jpg", "result": "9002244845578"}
            ];

        testSet.forEach(function(sample) {
            sample.format = "ean_13";
        });
<commit_msg>fix access undefined in decodeSingle test<commit_after>const Quagga = require('../../src/quagga').default;
const async = require('async');

describe('decodeSingle', function () {
    var baseFolder = "base/test/fixtures/";

    function generateConfig() {
        return {
            inputStream: {
                size: 640
            },
            locator: {
                patchSize: "medium",
                halfSample: true
            },
            numOfWorkers: 0,
            decoder: {
                readers: ["ean_reader"]
            },
            locate: true,
            src: null
        };
    }

    this.timeout(10000);

    function _runTestSet(testSet, config) {
        var readers = config.decoder.readers.slice(),
            format,
            folder,
            suffix;

        if (typeof readers[0] === 'string'){
            format = readers[0];
        } else {
            if (readers[0].config && readers[0].config.supplements && readers[0].config.supplements.length) {
                suffix = "extended";
            }
            format = readers[0].format;
        }

        folder = baseFolder + format.split('_').slice(0, -1).concat(suffix ? [suffix] : []).join('_') + "/";

        it('should decode ' + folder + " correctly", function(done) {
            async.eachSeries(testSet, function (sample, callback) {
                config.src = folder + sample.name;
                config.readers = readers;
                console.log(sample.name);
                Quagga.decodeSingle(config, function(result) {
                    expect(result).to.be.an('Object');
                    expect(result.codeResult).to.be.an('Object');
                    expect(result.codeResult.code).to.equal(sample.result);
                    expect(result.codeResult.format).to.equal(sample.format);
                    callback();
                });
            }, function() {
                done();
            });
        });
    }

    describe("EAN", function() {
        var config = generateConfig(),
            testSet = [
                {"name": "image-001.jpg", "result": "3574660239843"},
                {"name": "image-002.jpg", "result": "8032754490297"},
                {"name": "image-003.jpg", "result": "4006209700068"},
                /* {"name": "image-004.jpg", "result": "9002233139084"}, */
                /* {"name": "image-005.jpg", "result": "8004030044005"}, */
                {"name": "image-006.jpg", "result": "4003626011159"},
                {"name": "image-007.jpg", "result": "2111220009686"},
                {"name": "image-008.jpg", "result": "9000275609022"},
                {"name": "image-009.jpg", "result": "9004593978587"},
                {"name": "image-010.jpg", "result": "9002244845578"}
            ];

        testSet.forEach(function(sample) {
            sample.format = "ean_13";
        });

{'fraction_non_alphanumeric': 0.15989352262644188, 'fraction_numerical': 0.06353149955634428, 'mean_word_length': 1.5888837850252642, 'pattern_counts': {'":': 40, '<': 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': '4806969', 'n_tokens_mistral': 1820, 'n_tokens_neox': 1531, 'n_words': 273}