Skip to content

Commit

Permalink
fix(file resolving): ignore dirs from git submodules (#1195)
Browse files Browse the repository at this point in the history
  • Loading branch information
roelandvanbatenburg authored and nicojs committed Oct 20, 2018
1 parent bbc05cc commit 7806083
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
4 changes: 2 additions & 2 deletions packages/stryker/src/input/InputFileResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ export default class InputFileResolver {
this.reportSourceFilesRead(file);
return file;
}).catch(error => {
if (isErrnoException(error) && error.code === 'ENOENT') {
return null; // file is deleted. This can be a valid result of the git command
if (isErrnoException(error) && error.code === 'ENOENT' || error.code === 'EISDIR') {
return null; // file is deleted or a directory. This can be a valid result of the git command
} else {
// Rethrow
throw error;
Expand Down
4 changes: 4 additions & 0 deletions packages/stryker/test/helpers/producers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,10 @@ export function createFileAlreadyExistsError(): NodeJS.ErrnoException {
return createErrnoException('EEXIST');
}

export function createIsDirError(): NodeJS.ErrnoException {
return createErrnoException('EISDIR');
}

function createErrnoException(errorCode: string) {
const fileNotFoundError: NodeJS.ErrnoException = new Error('');
fileNotFoundError.code = errorCode;
Expand Down
17 changes: 15 additions & 2 deletions packages/stryker/test/unit/input/InputFileResolverSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import * as sinon from 'sinon';
import * as fileUtils from '../../../src/utils/fileUtils';
import currentLogMock from '../../helpers/logMock';
import BroadcastReporter from '../../../src/reporters/BroadcastReporter';
import { Mock, mock, createFileNotFoundError } from '../../helpers/producers';
import { Mock, mock, createFileNotFoundError, createIsDirError } from '../../helpers/producers';
import { errorToString, normalizeWhiteSpaces } from '../../../src/utils/objectUtils';
import { fsAsPromised } from '@stryker-mutator/util';

Expand Down Expand Up @@ -81,7 +81,7 @@ describe('InputFileResolver', () => {
expect(log.warn).calledWith(sinon.match('or specify the \`files\` property in your stryker config'));
});

it('should be able to handled deleted files reported by `git ls-files`', async () => {
it('should be able to handle deleted files reported by `git ls-files`', async () => {
sut = new InputFileResolver([], undefined, reporter);
childProcessExecStub.resolves({
stdout: Buffer.from(`
Expand All @@ -94,6 +94,19 @@ describe('InputFileResolver', () => {
expect(result.files).lengthOf(0);
});

it('should be able to handle directories reported by `git ls-files` (submodules)', async () => {
sut = new InputFileResolver([], undefined, reporter);
childProcessExecStub.resolves({
stdout: Buffer.from(`
submoduleDir
`)
});
const fileIsDirError = createIsDirError();
readFileStub.withArgs('submoduleDir').rejects(fileIsDirError);
const result = await sut.resolve();
expect(result.files).lengthOf(0);
});

describe('with mutate file expressions', () => {

it('should result in the expected mutate files', async () => {
Expand Down

0 comments on commit 7806083

Please sign in to comment.