# All files / core/use-cases handle-tsconfig-file.spec.ts

100% Statements 50/50
100% Branches 0/0
100% Functions 7/7
100% Lines 42/42

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    961x
    1x

    1x

    1x

    1x

    1x

    1x

    1x
    4x
    4x

    4x

    4x

    1x
    1x

    1x
    1x

    1x
    4x
    4x

    1x
    1x
    1x

    2x
    1x

    1x
    1x
    1x

    2x

    1x

    1x
    1x

    1x

    1x
    1x

    1x

    1x

    1x
    1x

    1x

    1x

    1x
    1x

     const expect = require('chai').expect;
    const sinon = require('sinon');

    import { CLIProgram } from '../../core/entities/cli-program';
    import ConfigurationRepository from '../../core/repositories/config.repository';

    import Logger from '../../infrastructure/logging/logger';

    import SetupFlags from './setup-flags';

    import HandleTsconfigFile from './handle-tsconfig-file';

    describe('Use-cases - Should find tsconfig file', () => {
        let loggerStubInfo;
        let loggerStubError;

        beforeEach(() => {
            loggerStubInfo = sinon.stub(Logger, 'info');
            loggerStubError = sinon.stub(Logger, 'error');

            const currentProgram: CLIProgram = SetupFlags.setup({
                version: '0.0.1'
            });

            ConfigurationRepository.init(currentProgram);
        });

        it('with file provided with -p flag, handle it', async () => {
            ConfigurationRepository.internalConfiguration.tsconfig =
                'test/fixtures/sample-files/tsconfig.exclude.json';

            const tsconfigExplorerResult = await HandleTsconfigFile.handle();
            expect(tsconfigExplorerResult).to.be.an('object');
        });

        afterEach(() => {
            loggerStubInfo.restore();
            loggerStubError.restore();
        });

        it('with file provided with -p flag, handle it, and log with found it', async () => {
            const testfilePath = 'test/fixtures/sample-files/tsconfig.exclude.json';
            ConfigurationRepository.internalConfiguration.tsconfig = testfilePath;

            await HandleTsconfigFile.handle();
            sinon.assert.calledWithExactly(
                Logger.info,
                sinon.match(`Using tsconfig file : ${testfilePath}`)
            );
        });

        it('with bad path for file provided with -p flag, log we did not found it', async () => {
            const testfilePath = 'test/fixtures/sample-files/notsconfig.json';
            ConfigurationRepository.internalConfiguration.tsconfig = testfilePath;

            try {
                await HandleTsconfigFile.handle();
            } catch (e) {
                expect(e).equal(`${testfilePath} file was not found in the current directory`);
            }
        });

        it('with one tsconfig file, find exclude, include and files', async () => {
            ConfigurationRepository.internalConfiguration.tsconfig =
                'test/fixtures/sample-files/tsconfig.exclude.json';

            let tsconfigExplorerResult = await HandleTsconfigFile.handle();

            expect(tsconfigExplorerResult).to.have.property('exclude');
            expect(tsconfigExplorerResult['exclude']).to.have.members([
                'bar.component.ts',
                '*.module.ts'
            ]);

            ConfigurationRepository.internalConfiguration.tsconfig =
                'test/fixtures/sample-files/tsconfig.include-file.json';

            tsconfigExplorerResult = await HandleTsconfigFile.handle();

            expect(tsconfigExplorerResult).to.have.property('include');
            expect(tsconfigExplorerResult['include']).to.have.members(['bar.component.ts']);

            ConfigurationRepository.internalConfiguration.tsconfig =
                'test/fixtures/sample-files/tsconfig.entry.json';

            tsconfigExplorerResult = await HandleTsconfigFile.handle();

            expect(tsconfigExplorerResult).to.have.property('files');
            expect(tsconfigExplorerResult['files']).to.have.members([
                'app.module.ts',
                'foo.component.ts',
                'foo.module.ts'
            ]);
        });
    });