-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ability to filter tests from the command line (#235)
Summary: Addresses part of #224 Fairly intuitive filtering implementation as well as integration with our internal CLI library. ![image](https://user-images.githubusercontent.com/5252755/74194208-b5680380-4c0d-11ea-8e74-b99e5ee5a842.png) ![image](https://user-images.githubusercontent.com/5252755/74194244-c1ec5c00-4c0d-11ea-9406-6c6aa09ee6ad.png) Pull Request resolved: #235 Differential Revision: D19827404 Pulled By: bandersongit fbshipit-source-id: bca7c71f33af48e7cf5dc6a6e1ea1910be5da15d
- Loading branch information
1 parent
d99df20
commit 70bc30c
Showing
11 changed files
with
456 additions
and
69 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
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,66 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/; | ||
|
||
let cli = (argv, testSuites) => { | ||
CLI.( | ||
program("Rely") | ||
|> description("A jest inspired native Reason testing framework") | ||
|> option( | ||
"--updateSnapshots", | ||
~aliases=["-u"], | ||
"Updates snapshots to match what is currently generated by the program", | ||
Optional(Bool), | ||
) | ||
|> option( | ||
"--onlyPrintDetailsForFailedSuites", | ||
"Prints output only for test suites that fail", | ||
Optional(Bool), | ||
) | ||
|> option( | ||
"--ci", | ||
~aliases=["-ci"], | ||
"Runs Rely in CI mode (errors on usage of testOnly and describeOnly)", | ||
Optional(Bool), | ||
) | ||
|> argument( | ||
"testNamePattern", | ||
"Only run tests matching the passed in pattern", | ||
Optional(String), | ||
) | ||
|> action(({options, args}) => { | ||
let shouldUpdateSnapshots = options.bool("--updateSnapshots"); | ||
let ci = options.bool("--ci"); | ||
let onlyPrintDetailsForFailedSuites = | ||
options.bool("--onlyPrintDetailsForFailedSuites"); | ||
|
||
let config = | ||
RunConfig.( | ||
initialize() | ||
|> updateSnapshots(shouldUpdateSnapshots) | ||
|> ciMode(ci) | ||
|> withTestNamePattern( | ||
args.optionalString("testNamePattern"), | ||
) | ||
|> withReporters([ | ||
Custom( | ||
TerminalReporter.createTerminalReporter( | ||
~onlyPrintDetailsForFailedSuites, | ||
{ | ||
printEndline: print_endline, | ||
printNewline: print_newline, | ||
printString: print_string, | ||
flush, | ||
}, | ||
), | ||
), | ||
]) | ||
); | ||
TestSuiteRunner.run(config, testSuites); | ||
}) | ||
|> parseAndRun(argv) | ||
); | ||
}; |
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
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,71 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/; | ||
|
||
let filterTestsByName = | ||
(tests: list(TestSuite.test('ext, 'env)), nameFilter) => { | ||
tests | ||
|> List.filter((test: TestSuite.test('ext, 'env)) => | ||
nameFilter(test.name) | ||
); | ||
}; | ||
|
||
let rec filterDescribeByName = | ||
(describeRecord: TestSuite.describeRecord('a, 'b), nameFilter) => { | ||
let {TestSuite.name, tests, describes, mode} = describeRecord; | ||
|
||
if (nameFilter(name)) { | ||
Some(describeRecord); | ||
} else { | ||
let tests = filterTestsByName(tests, nameFilter); | ||
let describes = filterDescribesByName(describes, nameFilter); | ||
|
||
switch (tests, describes) { | ||
| ([], []) => None | ||
| _ => | ||
Some({name, tests, describes, mode}: TestSuite.describeRecord('a, 'b)) | ||
}; | ||
}; | ||
} | ||
and filterDescribesByName = (describes, nameFilter) => { | ||
describes | ||
|> List.map(describe => filterDescribeByName(describe, nameFilter)) | ||
|> List.fold_left( | ||
(acc, optDescribe) => | ||
switch (optDescribe) { | ||
| Some(describe) => [describe, ...acc] | ||
| None => acc | ||
}, | ||
[], | ||
); | ||
}; | ||
|
||
let filterSuiteByName = (testSuite, nameFilter) => { | ||
let TestSuite.TestSuite(describeRecord, extensionFn, lifeCycle, context) = testSuite; | ||
switch (filterDescribeByName(describeRecord, nameFilter)) { | ||
| Some(record) => | ||
Some(TestSuite.TestSuite(record, extensionFn, lifeCycle, context)) | ||
| None => None | ||
}; | ||
}; | ||
|
||
let filterTestSuitesByName = (testSuites: list(TestSuite.t), nameFilter) => { | ||
testSuites | ||
|> List.fold_left( | ||
(acc, suite) => { | ||
switch (filterSuiteByName(suite, nameFilter)) { | ||
| Some(suite) => [suite, ...acc] | ||
| None => acc | ||
} | ||
}, | ||
[], | ||
); | ||
}; | ||
|
||
let filterTestSuitesByRegex = (testSuites, regex) => { | ||
let filterFn = name => Re.Pcre.pmatch(regex, name); | ||
filterTestSuitesByName(testSuites, filterFn); | ||
}; |
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
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
Oops, something went wrong.