SimenB / stylint

Improve your Stylus code with Stylint
https://simenb.github.io/stylint/
GNU General Public License v2.0
348 stars 61 forks source link

getConfig will assign default options to generated config #429

Open PalleZingmark opened 6 years ago

PalleZingmark commented 6 years ago

Fix for #409

PalleZingmark commented 6 years ago

Looking into writing tests for this, I actually get some weird output (on master) which to me looks a bit unintended within the test. Is this a bug or intended behaviour?

stylint-test-output
PalleZingmark commented 6 years ago

I need to update tests.

SimenB commented 6 years ago

@PalleZingmark not so much intended as known 🙂 Fixed in v2, FWIW

PalleZingmark commented 6 years ago

Updated tests according to the approach discussed in #409. Here's my thoughts on the tests:

describe( 'Set Config should:', function() {
    process.argv[2] = '-c'
    process.argv[3] = '.stylintrc'
    var testMethod = app.setConfig( '.stylintrc' )
    var testConfig = app.setConfig( process.cwd() + '/.stylintrc' )

    it( 'return complete config when not complete config is passed in', function() {
        assert.ok( testConfig.reporter )
    } )

    it( 'update config state if passed a valid path', function() {
        assert.equal( Object.keys( testConfig ).length, Object.keys( testMethod ).length )
    } )

    it( 'throw if passed invalid path', function() {
        assert.throws(
            app.setConfig,
            TypeError,
            'setConfig err. Expected string, but received: ' + typeof dir
        )
    } )
} )

testMethod: Contains a config generated based on the default config options. testConfig: Contains a config for test, generated on a .stylintrc that doesn't contain a full set of options.

Test 1

it( 'return complete config when not complete config is passed in', function() {
    assert.ok( testConfig.reporter )
} )

setConfig() should return a config with the reporter-option included even though it's not part of the actual .stylintrc file passed to the function.

Test 2

it( 'update config state if passed a valid path', function() {
    assert.equal( Object.keys( testConfig ).length, Object.keys( testMethod ).length )
} )

Make sure setConfig returns just as many options as testMethod even though the actual .stylintrc file passed to the function contains fever options.