"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const chai = __importStar(require("chai"));
const path = __importStar(require("path"));
const mocha_1 = require("mocha");
const feature_collector_1 = require("../../src/lib/feature-collector/feature-collector");
const chai_as_promised_1 = __importDefault(require("chai-as-promised"));
const sinon_chai_1 = __importDefault(require("sinon-chai"));
const expect = chai.expect;
chai.use(sinon_chai_1.default);
chai.use(chai_as_promised_1.default);
chai.use(sinon_chai_1.default);
mocha_1.describe('CollectFeatures.ts', () => {
    mocha_1.describe('Happy flows', () => {
        mocha_1.it('should return an output from  folder with features', async () => {
            // Given
            const userPropeties = {
                featuresFolder: path.resolve(process.cwd(), './test/unit/data/features/empty-and-nested-folders-without-errors'),
                jsonDir: ''
            };
            const collectFeatures = new feature_collector_1.CollectFeatureFiles(userPropeties);
            // When
            const collectedFeatures = await collectFeatures.collectFeatures();
            // Then
            expect(collectedFeatures?.length).to.be.equal(2);
        });
        mocha_1.it('should not return an output if it does not find features', async () => {
            // Given
            const userPropeties = {
                featuresFolder: path.resolve(process.cwd(), './test/unit/data/cucumber-report-jsons'),
                jsonDir: ''
            };
            const collectFeatures = new feature_collector_1.CollectFeatureFiles(userPropeties);
            // When
            const collectedFeatures = await collectFeatures.collectFeatures();
            // Then
            expect(collectedFeatures).to.be.equal(null);
        });
    });
    mocha_1.describe('failures', () => {
        mocha_1.it('should not return an output with a null folder', async () => {
            // Given
            const userPropeties = {
                jsonDir: ''
            };
            const collectFeatures = new feature_collector_1.CollectFeatureFiles(userPropeties);
            // When
            await collectFeatures.collectFeatures().catch((error) => {
                // Then
                expect(error.message).equal("ENOENT: no such file or directory, stat 'null'");
            });
        });
        mocha_1.it('should return a null with an undefined folder', async () => {
            // Given
            const userPropeties = {
                jsonDir: '',
            };
            const collectFeatures = new feature_collector_1.CollectFeatureFiles(userPropeties);
            // When
            const result = await collectFeatures.collectFeatures();
            // Then
            expect(result?.length).to.equal(0);
        });
        mocha_1.it('should return an error in console when a feature file cannot be parsed', async () => {
            // Given
            const userPropeties = {
                featuresFolder: path.resolve(process.cwd(), './test/unit/data/features/with-incorrect-table'),
                jsonDir: ''
            };
            const collectFeatures = new feature_collector_1.CollectFeatureFiles(userPropeties);
            // When
            const collectedFeatures = await collectFeatures.collectFeatures();
            // Then
            expect(collectedFeatures).to.equal(null);
        });
        mocha_1.it('should not return the features with the examples label written twice', async () => {
            // Given
            const userPropeties = {
                featuresFolder: path.resolve(process.cwd(), './test/unit/data/features/with-label-written-twice'),
                jsonDir: ''
            };
            const collectFeatures = new feature_collector_1.CollectFeatureFiles(userPropeties);
            // When
            const collectedFeatures = await collectFeatures.collectFeatures();
            // Then
            expect(collectedFeatures?.length).to.equal(1);
        });
    });
});
//# sourceMappingURL=CollectFeatures-spec.js.map