generated from actions/typescript-action
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from ethanis/use-actions-glob
Correctly filter out exclusion paths
- Loading branch information
Showing
5 changed files
with
197 additions
and
7 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": "Debug Jest Tests", | ||
"type": "node", | ||
"request": "launch", | ||
"program": "${workspaceFolder}/node_modules/.bin/jest", | ||
"args": ["--runInBand"], | ||
"console": "integratedTerminal", | ||
"internalConsoleOptions": "neverOpen" | ||
} | ||
] | ||
} |
This file contains 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 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 |
---|---|---|
@@ -0,0 +1,166 @@ | ||
import { getMatchingFilePaths } from '../../src/services'; | ||
import { Comment, Change, ChangeType } from '../../src/models'; | ||
|
||
test('* matches everything', () => { | ||
const comment: Comment = { | ||
pathFilter: ['*'], | ||
markdown: 'Woohoo!', | ||
blocking: false | ||
}; | ||
|
||
const changes: Change[] = [ | ||
{ | ||
file: 'app/models/foo.rb', | ||
changeType: ChangeType.edit | ||
} | ||
]; | ||
|
||
const result = getMatchingFilePaths(comment, changes); | ||
|
||
expect(result).toEqual(changes.map(c => c.file)); | ||
}); | ||
|
||
test('match recursively', () => { | ||
const comment: Comment = { | ||
pathFilter: ['app/**'], | ||
markdown: 'Woohoo!', | ||
blocking: false | ||
}; | ||
|
||
const changes: Change[] = [ | ||
{ | ||
file: 'app/models/foo.rb', | ||
changeType: ChangeType.edit | ||
} | ||
]; | ||
|
||
const result = getMatchingFilePaths(comment, changes); | ||
|
||
expect(result).toEqual(changes.map(c => c.file)); | ||
}); | ||
|
||
test('ignore case', () => { | ||
const comment: Comment = { | ||
pathFilter: ['app/**'], | ||
markdown: 'Woohoo!', | ||
blocking: false | ||
}; | ||
|
||
const changes: Change[] = [ | ||
{ | ||
file: 'APP/MODELS/FOO.rb', | ||
changeType: ChangeType.edit | ||
} | ||
]; | ||
|
||
const result = getMatchingFilePaths(comment, changes); | ||
|
||
expect(result).toEqual(changes.map(c => c.file)); | ||
}); | ||
|
||
test('remove exclusion patterns', () => { | ||
const comment: Comment = { | ||
pathFilter: ['app/**', '!app/models/*.h'], | ||
markdown: 'Everything except headers', | ||
blocking: false | ||
}; | ||
|
||
const changes: Change[] = [ | ||
{ | ||
file: 'app/models/main.h', | ||
changeType: ChangeType.edit | ||
} | ||
]; | ||
|
||
const result = getMatchingFilePaths(comment, changes); | ||
|
||
expect(result).toEqual([]); | ||
}); | ||
|
||
test('match new files only', () => { | ||
const comment: Comment = { | ||
pathFilter: ['+app/**'], | ||
markdown: 'Only new files', | ||
blocking: false | ||
}; | ||
|
||
const changes: Change[] = [ | ||
{ | ||
file: 'app/models/old.rb', | ||
changeType: ChangeType.edit | ||
}, | ||
{ | ||
file: 'app/models/new.rb', | ||
changeType: ChangeType.add | ||
} | ||
]; | ||
|
||
const result = getMatchingFilePaths(comment, changes); | ||
|
||
expect(result).toEqual(['app/models/new.rb']); | ||
}); | ||
|
||
test('match deleted files only', () => { | ||
const comment: Comment = { | ||
pathFilter: ['-app/**'], | ||
markdown: 'Only deleted files', | ||
blocking: false | ||
}; | ||
|
||
const changes: Change[] = [ | ||
{ | ||
file: 'app/models/old.rb', | ||
changeType: ChangeType.edit | ||
}, | ||
{ | ||
file: 'app/models/deleted.rb', | ||
changeType: ChangeType.delete | ||
} | ||
]; | ||
|
||
const result = getMatchingFilePaths(comment, changes); | ||
|
||
expect(result).toEqual(['app/models/deleted.rb']); | ||
}); | ||
|
||
test('match edited files only', () => { | ||
const comment: Comment = { | ||
pathFilter: ['~app/**'], | ||
markdown: 'Only deleted files', | ||
blocking: false | ||
}; | ||
|
||
const changes: Change[] = [ | ||
{ | ||
file: 'app/models/old.rb', | ||
changeType: ChangeType.edit | ||
}, | ||
{ | ||
file: 'app/models/deleted.rb', | ||
changeType: ChangeType.delete | ||
} | ||
]; | ||
|
||
const result = getMatchingFilePaths(comment, changes); | ||
|
||
expect(result).toEqual(['app/models/old.rb']); | ||
}); | ||
|
||
test('disallow multiple modifiers', () => { | ||
const comment: Comment = { | ||
pathFilter: ['!~app/**'], | ||
markdown: 'Not edited files', | ||
blocking: false | ||
}; | ||
|
||
const changes: Change[] = [ | ||
{ | ||
file: 'app/models/old.rb', | ||
changeType: ChangeType.edit | ||
} | ||
]; | ||
|
||
expect(() => getMatchingFilePaths(comment, changes)).toThrow( | ||
'Multiple path modifiers are not supported' | ||
); | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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