-
Notifications
You must be signed in to change notification settings - Fork 54
NEW @W-17977844@ rules command can output csv files #1877
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
bf814ad
NEW @W-17977844@ rules command can output csv files
jfeingold35 f681237
NEW @W-17977844@ rules command takes multiple output files
jfeingold35 651dab3
NEW @W-17977844@ Feedback from review
jfeingold35 1f2896a
NEW @W-17977844@ Last feedback
jfeingold35 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| # error.unrecognized-file-format | ||
|
|
||
| The output file %s has an unsupported extension. Valid extension(s): .json. | ||
| The output file %s has an unsupported extension. Valid extension(s): .json, .csv |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,65 +6,68 @@ import * as Stub from '../../stubs/StubRuleSelection'; | |
|
|
||
| describe('RulesWriter', () => { | ||
|
|
||
| let writeFileSpy: jest.SpyInstance; | ||
| let writeFileInvocations: { file: fs.PathOrFileDescriptor, contents: string | ArrayBufferView }[]; | ||
| let writeFileSpy: jest.SpyInstance; | ||
| let writeFileInvocations: { file: fs.PathOrFileDescriptor, contents: string | ArrayBufferView }[]; | ||
|
|
||
| beforeEach(() => { | ||
| jest.resetAllMocks(); | ||
| writeFileInvocations = []; | ||
| writeFileSpy = jest.spyOn(fs, 'writeFileSync').mockImplementation((file, contents) => { | ||
| writeFileInvocations.push({file, contents}); | ||
| }); | ||
| }); | ||
| beforeEach(() => { | ||
| jest.resetAllMocks(); | ||
| writeFileInvocations = []; | ||
| writeFileSpy = jest.spyOn(fs, 'writeFileSync').mockImplementation((file, contents) => { | ||
| writeFileInvocations.push({file, contents}); | ||
| }); | ||
| }); | ||
|
|
||
| describe('RulesFileWriter', () => { | ||
| describe('RulesFileWriter', () => { | ||
|
|
||
| it('Rejects invalid file format', () => { | ||
| const invalidFile = 'file.xml'; | ||
| expect(() => new RulesFileWriter(invalidFile)).toThrow(invalidFile); | ||
| }); | ||
| it('Rejects invalid file format', () => { | ||
| const invalidFile = 'file.xml'; | ||
| expect(() => new RulesFileWriter(invalidFile)).toThrow(invalidFile); | ||
| }); | ||
|
|
||
| it('Writes to a json file path', () => { | ||
| const outfilePath = path.join('the', 'results', 'path', 'file.json'); | ||
| const expectations = { | ||
| file: outfilePath, | ||
| contents: `Rules formatted as ${OutputFormat.JSON}` | ||
| }; | ||
| const rulesWriter = new RulesFileWriter(expectations.file); | ||
| const stubbedSelection = new Stub.StubEmptyRuleSelection(); | ||
| rulesWriter.write(stubbedSelection); | ||
| it.each([ | ||
| {ext: 'json', format: OutputFormat.JSON}, | ||
| {ext: 'csv', format: OutputFormat.CSV} | ||
| ])('Writes to a $ext file path', ({ext, format}) => { | ||
| const outfilePath = path.join('the', 'results', 'path', `file.${ext}`); | ||
| const expectations = { | ||
| file: outfilePath, | ||
| contents: `Rules formatted as ${format}` | ||
| }; | ||
| const rulesWriter = new RulesFileWriter(expectations.file); | ||
| const stubbedSelection = new Stub.StubEmptyRuleSelection(); | ||
| rulesWriter.write(stubbedSelection); | ||
|
|
||
| expect(writeFileSpy).toHaveBeenCalled(); | ||
| expect(writeFileInvocations).toEqual([expectations]); | ||
| }); | ||
| }); | ||
| expect(writeFileSpy).toHaveBeenCalled(); | ||
| expect(writeFileInvocations).toEqual([expectations]); | ||
| }); | ||
|
Comment on lines
+27
to
+42
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I changed this test to use |
||
| }); | ||
|
|
||
| describe('CompositeRulesWriter', () => { | ||
| describe('CompositeRulesWriter', () => { | ||
|
|
||
| it('Does a no-op when there are no files to write to', () => { | ||
| const outputFileWriter = CompositeRulesWriter.fromFiles([]); | ||
| const stubbedEmptyRuleSelection = new Stub.StubEmptyRuleSelection(); | ||
| it('Does a no-op when there are no files to write to', () => { | ||
| const outputFileWriter = CompositeRulesWriter.fromFiles([]); | ||
| const stubbedEmptyRuleSelection = new Stub.StubEmptyRuleSelection(); | ||
|
|
||
| outputFileWriter.write(stubbedEmptyRuleSelection); | ||
| outputFileWriter.write(stubbedEmptyRuleSelection); | ||
|
|
||
| expect(writeFileSpy).not.toHaveBeenCalled(); | ||
| }); | ||
| it('When given multiple files, outputs to all of them', () => { | ||
| const expectations = [{ | ||
| file: 'outFile1.json', | ||
| contents: `Rules formatted as ${OutputFormat.JSON}` | ||
| }, { | ||
| file: 'outFile2.json', | ||
| contents: `Rules formatted as ${OutputFormat.JSON}` | ||
| }]; | ||
| const outputFileWriter = CompositeRulesWriter.fromFiles(expectations.map(i => i.file)); | ||
| const stubbedSelection = new Stub.StubEmptyRuleSelection(); | ||
| outputFileWriter.write(stubbedSelection); | ||
| expect(writeFileSpy).toHaveBeenCalledTimes(2); | ||
| expect(writeFileInvocations).toEqual(expectations); | ||
| }); | ||
| }) | ||
| }); | ||
| expect(writeFileSpy).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('When given multiple files, outputs to all of them', () => { | ||
| const expectations = [{ | ||
| file: 'outFile1.json', | ||
| contents: `Rules formatted as ${OutputFormat.JSON}` | ||
| }, { | ||
| file: 'outFile2.json', | ||
| contents: `Rules formatted as ${OutputFormat.JSON}` | ||
| }]; | ||
| const outputFileWriter = CompositeRulesWriter.fromFiles(expectations.map(i => i.file)); | ||
| const stubbedSelection = new Stub.StubEmptyRuleSelection(); | ||
|
|
||
| outputFileWriter.write(stubbedSelection); | ||
|
|
||
| expect(writeFileSpy).toHaveBeenCalledTimes(2); | ||
| expect(writeFileInvocations).toEqual(expectations); | ||
| }); | ||
| }) | ||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noticing that some of the files created by people other than me are space-indented, so I'm adding a thing to the
.editorconfigto hopefully keep it all consistent in the future.