Skip to content

test-exclude should supply nocase to minimatch and glob when running on win32. #43

Open

Description

@j03m

See description here: bcoe/c8#183

Capital vs lowercase driver letters can throw this check off as it is currently written.

CC: @bcoe

Activity

  1. coreyfarrell commented on Dec 30, 2019

    @coreyfarrell
    Member

    What about the other uses of minimatch and glob from index.js? Should they also provide nocase: true under Windows?

  2. j03m commented on Dec 31, 2019

    @j03m
    Author

    That is a good question. This is the one place I saw it become an issue in my project on windows, but let me examine the others. Windows paths are case insenstive so where we do comparisons on paths it seems prudent we do the same. But I don't know this lib that well. Let me examine the usages.

  3. coreyfarrell commented on Dec 31, 2019

    @coreyfarrell
    Member

    For an example by default test/** is excluded from coverage (ignored). Currently Test/file.js will not be excluded, even on Windows. I'm not sure if this is correct behavior. I'm also unsure what happens if we end up with inconsistent casing of process.cwd() vs the cwd option of test-exclude. Like what if test-exclude is created with cwd of c:\project but then we try to check if C:\Project\index.js should be instrumented.

  4. JaKXz commented on Jan 1, 2020

    @JaKXz
    Collaborator

    Can we just take an optional minimatch key and pass on the options to minimatch? Would that be overkill?

  5. coreyfarrell commented on Jan 1, 2020

    @coreyfarrell
    Member

    I'd prefer not to as we'd then need to expose the option to nyc. I'm leaning towards thinking it would be better to set the option per platform.

  6. j03m commented on Jan 3, 2020

    @j03m
    Author

    Finally had a chance to look over the code I think you're correct that nocase should probably be supplied to glob and minimatch anywhere we use it when running on windows. I wrote up a PR where these two tests will pass, but I can't submit until I get approval from my company (should be soon tho).

    Basically the tests below will pass, where as they will fail on current master. To be able to test on mac I also supplied a forceWin32 option that will toggle the nocase flag.

    t.test('should handle case insensitive paths on win32', t =>
        testHelper(t, {
            options: {
                exclude: undefined,
                include: ["boo.js"],
                forceWin32: true
            },
            no: [],
            yes: ['BOO.js']
        })
    );
    
    t.test('should handle case insensitive drives on win32', t =>
        testHelper(t, {
            options: {
                cwd: 'C:\\project',
                forceWin32: true
            },
            yes: ['c:\\project\\foo.js']
        })
    );
    

    ***Edited test

  7. changed the title [-]outside-dir-win32 should supply `nocase` to `minimatch` options.[/-] [+]test-exclude should supply `nocase` to `minimatch` and `glob` when running on win32.[/+] on Jan 4, 2020
  8. j03m commented on Jan 4, 2020

    @j03m
    Author

    Changed title to reflect additional scope

  9. j03m commented on Jan 4, 2020

    @j03m
    Author

    I ended up removing that bit on forceWin32 and kept with checking the platform in the tap tests. Running something like path.resolve("c:\projects", "c:\projects\foo.js") on osx resolves to something like/Users/..../C:\projects/c:/projects/foo.js :/ but I ran the tests on windows and they pass.

    That said, if we don't run win32 as part of CI then there is always going to be a risk of breaking this there. Any ideas how we could test both on a posix os?

  10. coreyfarrell commented on Jan 4, 2020

    @coreyfarrell
    Member

    Maintaining CI for both Win32 and POSIX is definitely a priority for this module. If Travis-CI were to drop support for Win32 we would immediately investigate other options and implement one of them. I think creating a forceWin32 option is unnecessary and my vote is to avoid adding test options to the production code.

    My suggestion would be to make is-outside-dir-*.js provide named exports:

    module.exports = {
      isOutsideDir(...) {
        // code clipped
      },
      minimatchOptions: {
        dot: true,
        nocase: true // in is-outside-dir-win32.js only
      }
    }

    This will avoid adding a platform dependent conditional to index.js so we will maintain 100% coverage without adding any istanbul ignore hints.

    Then add platform dependent testing:

    if (process.platform === 'win32') {
      // verify that some Win32 paths with different case match
      t.test('uses case insensitive matching', t => { ... });
    } else {
      // verify that some POSIX paths with different case do not match
      t.test('uses case sensitive matching', t => { ... });
    }

    We will need testing for both shouldInstrument and glob methods.

  11. j03m commented on Jan 14, 2020

    @j03m
    Author

    Checking in: I made your suggested changes locally, still just waiting on legal approval to submit. :/

  12. j03m commented on Jan 17, 2020

    @j03m
    Author
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions