Skip to content

Commit

Permalink
feat(InputFileResolver): remove InputFileDescriptor support (#1390)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: removed InputFileDescriptor support. Entries of the `files` and `mutate` array should only contain strings, not objects. The `files` array can be removed in most cases as it can be generated using Git.
  • Loading branch information
simondel authored and nicojs committed Feb 12, 2019
1 parent 4ee27a2 commit d307961
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 69 deletions.
33 changes: 2 additions & 31 deletions packages/stryker/src/input/InputFileResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ export default class InputFileResolver {
{ mutate, files }: StrykerOptions,
private readonly reporter: StrictReporter
) {
this.mutatePatterns = this.normalize(mutate || []);
this.mutatePatterns = mutate || [];
if (files) {
this.filePatterns = this.normalize(files);
this.filePatterns = files;
}
}

Expand Down Expand Up @@ -140,35 +140,6 @@ export default class InputFileResolver {
);
}

private normalize(
inputFileExpressions: (string | { pattern: string })[]
): string[] {
const inputFileDescriptorObjects: { pattern: string }[] = [];
const globExpressions = inputFileExpressions.map(expression => {
if (typeof expression === 'string') {
return expression;
} else {
inputFileDescriptorObjects.push(expression);
return expression.pattern;
}
});
if (inputFileDescriptorObjects.length) {
this.log.warn(
normalizeWhiteSpaces(`
DEPRECATED: Using the \`InputFileDescriptor\` syntax to
select files is no longer supported. We'll assume: ${JSON.stringify(inputFileDescriptorObjects)}
can be migrated to ${JSON.stringify(inputFileDescriptorObjects.map(_ => _.pattern))} for this
mutation run. Please move any files to mutate into the \`mutate\` array (top level stryker option).
You can fix this warning in 2 ways:
1) If your project is under git version control, you can remove the "files" patterns all together.
Stryker can figure it out for you.
2) If your project is not under git version control or you need ignored files in your sandbox, you can replace the
\`InputFileDescriptor\` syntax with strings (as done for this test run).`)
);
}
return globExpressions;
}

private readFile(fileName: string): Promise<File | null> {
return fsAsPromised
.readFile(fileName)
Expand Down
38 changes: 0 additions & 38 deletions packages/stryker/test/unit/input/InputFileResolverSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import * as sinon from 'sinon';
import * as fileUtils from '../../../src/utils/fileUtils';
import BroadcastReporter from '../../../src/reporters/BroadcastReporter';
import { Mock, mock, createFileNotFoundError, createIsDirError } from '../../helpers/producers';
import { normalizeWhiteSpaces } from '../../../src/utils/objectUtils';
import { fsAsPromised } from '@stryker-mutator/util';
import { testInjector } from '@stryker-mutator/test-helpers';
import { coreTokens } from '../../../src/di';
Expand Down Expand Up @@ -197,43 +196,6 @@ describe(InputFileResolver.name, () => {
});
});

describe('with file expressions in the old `InputFileDescriptor` syntax', () => {
let patternFile1: any;
let patternFile3: any;

beforeEach(() => {
patternFile1 = { pattern: 'file1' };
patternFile3 = { pattern: 'file3' };

testInjector.options.files = [patternFile1, 'file2', patternFile3];
sut = createSut();
});

it('it should log a warning', async () => {

await sut.resolve();
const inputFileDescriptors = JSON.stringify([patternFile1, patternFile3]);
const patternNames = JSON.stringify([patternFile1.pattern, patternFile3.pattern]);
expect(testInjector.logger.warn).calledWith(normalizeWhiteSpaces(`
DEPRECATED: Using the \`InputFileDescriptor\` syntax to
select files is no longer supported. We'll assume: ${inputFileDescriptors} can be migrated
to ${patternNames} for this mutation run. Please move any files to mutate into the \`mutate\`
array (top level stryker option).
You can fix this warning in 2 ways:
1) If your project is under git version control, you can remove the "files" patterns all together.
Stryker can figure it out for you.
2) If your project is not under git version control or you need ignored files in your sandbox, you can replace the
\`InputFileDescriptor\` syntax with strings (as done for this test run).`));
});

it('should resolve the patterns as normal files', async () => {
const result = await sut.resolve();
const actualFileNames = result.files.map(m => m.name);
expect(actualFileNames).to.deep.equal(['/file1.js', '/file2.js', '/file3.js'].map(_ => path.resolve(_)));
});
});

describe('when a globbing expression does not result in a result', () => {

it('should log a warning', async () => {
Expand Down

0 comments on commit d307961

Please sign in to comment.