Skip to content

Commit

Permalink
Pass file selection globs to test reporters (#431)
Browse files Browse the repository at this point in the history
Changes:
The console reporter prints the arguments passed to elm-test and the
`--seed` and `--fuzz` flags. Before, it would list the full path of
every single test file found using the passed file selection glob.

The JSON reporter returns the additional field "globs".
  • Loading branch information
marc136 authored and harrysarson committed Aug 24, 2020
1 parent 70afb35 commit 7269fd6
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 15 deletions.
6 changes: 3 additions & 3 deletions elm/src/Test/Reporter/Console.elm
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ textToValue useColor txt =
|> Encode.string


reportBegin : UseColor -> { paths : List String, fuzzRuns : Int, testCount : Int, initialSeed : Int } -> Maybe Value
reportBegin useColor { paths, fuzzRuns, testCount, initialSeed } =
reportBegin : UseColor -> { r | globs : List String, fuzzRuns : Int, testCount : Int, initialSeed : Int } -> Maybe Value
reportBegin useColor { globs, fuzzRuns, testCount, initialSeed } =
let
prefix =
"Running "
Expand All @@ -103,7 +103,7 @@ reportBegin useColor { paths, fuzzRuns, testCount, initialSeed } =
++ " --seed "
++ String.fromInt initialSeed
in
(String.join " " (prefix :: paths) ++ "\n")
(String.join " " (prefix :: globs) ++ "\n")
|> plain
|> textToValue useColor
|> Just
Expand Down
5 changes: 3 additions & 2 deletions elm/src/Test/Reporter/Json.elm
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import Test.Reporter.TestResults as TestResults exposing (Failure, Outcome(..),
import Test.Runner.Failure exposing (InvalidReason(..), Reason(..))


reportBegin : { paths : List String, fuzzRuns : Int, testCount : Int, initialSeed : Int } -> Maybe Value
reportBegin { paths, fuzzRuns, testCount, initialSeed } =
reportBegin : { globs : List String, paths : List String, fuzzRuns : Int, testCount : Int, initialSeed : Int } -> Maybe Value
reportBegin { globs, paths, fuzzRuns, testCount, initialSeed } =
Encode.object
[ ( "event", Encode.string "runStart" )
, ( "testCount", Encode.string <| String.fromInt testCount )
, ( "fuzzRuns", Encode.string <| String.fromInt fuzzRuns )
, ( "globs", Encode.list Encode.string globs )
, ( "paths", Encode.list Encode.string paths )
, ( "initialSeed", Encode.string <| String.fromInt initialSeed )
]
Expand Down
3 changes: 2 additions & 1 deletion elm/src/Test/Reporter/Reporter.elm
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ type alias TestReporter =


type alias RunInfo =
{ paths : List String
{ globs : List String
, paths : List String
, fuzzRuns : Int
, testCount : Int
, initialSeed : Int
Expand Down
8 changes: 6 additions & 2 deletions elm/src/Test/Runner/Node.elm
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type alias TestId =
type alias InitArgs =
{ initialSeed : Int
, processes : Int
, globs : List String
, paths : List String
, fuzzRuns : Int
, runners : SeededRunners
Expand All @@ -48,6 +49,7 @@ type alias RunnerOptions =
{ seed : Int
, runs : Maybe Int
, report : Report
, globs : List String
, paths : List String
, processes : Int
}
Expand Down Expand Up @@ -258,7 +260,7 @@ sendBegin model =


init : InitArgs -> Int -> ( Model, Cmd Msg )
init { processes, paths, fuzzRuns, initialSeed, report, runners } _ =
init { processes, globs, paths, fuzzRuns, initialSeed, report, runners } _ =
let
{ indexedRunners, autoFail } =
case runners of
Expand Down Expand Up @@ -292,6 +294,7 @@ init { processes, paths, fuzzRuns, initialSeed, report, runners } _ =
{ available = Dict.fromList indexedRunners
, runInfo =
{ testCount = testCount
, globs = globs
, paths = paths
, fuzzRuns = fuzzRuns
, initialSeed = initialSeed
Expand All @@ -309,7 +312,7 @@ init { processes, paths, fuzzRuns, initialSeed, report, runners } _ =
{-| Run the tests.
-}
run : RunnerOptions -> Test -> Program Int Model Msg
run { runs, seed, report, paths, processes } test =
run { runs, seed, report, globs, paths, processes } test =
let
fuzzRuns =
Maybe.withDefault defaultRunCount runs
Expand All @@ -321,6 +324,7 @@ run { runs, seed, report, paths, processes } test =
init
{ initialSeed = seed
, processes = processes
, globs = globs
, paths = paths
, fuzzRuns = fuzzRuns
, runners = runners
Expand Down
6 changes: 5 additions & 1 deletion lib/Generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ function generateMainModule(
fuzz /*: number */,
seed /*: number */,
report /*: string */,
testFileGlobs /*: Array<string> */,
testFilePaths /*: Array<string> */,
testModules /*: Array<{ moduleName: string, tests: Array<string> }> */,
generatedSrc /*: string */,
Expand Down Expand Up @@ -350,6 +351,7 @@ function generateMainModule(
fuzz: isNaN(fuzz) ? 'Nothing' : 'Just ' + fuzz,
seed: seed,
report: getReportCode(),
globs: testFileGlobs.map(sanitizedToString).join(','),
paths: testFilePaths.map(sanitizedToString).join(','),
};

Expand All @@ -362,7 +364,9 @@ function generateMainModule(
opts.seed +
', processes = ' +
processes +
', paths = [' +
', globs = [' +
opts.globs +
'], paths = [' +
opts.paths +
']}';

Expand Down
13 changes: 7 additions & 6 deletions lib/elm-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,6 @@ if (args._[0] === 'make') {
const testFileGlobs = args._.length > 0 ? args._ : [];
const testFilePaths = resolveGlobs(testFileGlobs);
const projectRootDir = getProjectRootDir(testFilePaths);
const hasBeenGivenCustomGlobs = fileGlobs.length > 0;

const elmJsonPath = path.resolve(path.join(projectRootDir, 'elm.json'));

Expand Down Expand Up @@ -408,24 +407,25 @@ if (args._[0] === 'make') {
Runner.getIndirectDeps(projectRootDir).then((packageIndirectDeps) => {
return generateAndRun(
projectRootDir,
testFileGlobs,
testFilePaths,
packageIndirectDeps,
hasBeenGivenCustomGlobs
packageIndirectDeps
);
});
});
} else {
generateAndRun(projectRootDir, testFilePaths, {}, hasBeenGivenCustomGlobs);
generateAndRun(projectRootDir, testFileGlobs, testFilePaths, {});
}
}

function generateAndRun(
projectRootDir /*: string */,
testFileGlobs /* Array<string> */,
testFilePaths /*: Array<string> */,
packageIndirectDeps /*: Object */,
hasBeenGivenCustomGlobs /*: boolean */
packageIndirectDeps /*: Object */
) {
const generatedCodeDir = Compile.getGeneratedCodeDir(projectRootDir);
const hasBeenGivenCustomGlobs = testFileGlobs.length > 0;

const returnValues = Generate.generateElmJson(
projectRootDir,
Expand Down Expand Up @@ -457,6 +457,7 @@ function generateAndRun(
parseInt(args.fuzz),
parseInt(args.seed),
args.report,
testFileGlobs,
testFilePaths,
testModules,
generatedSrc,
Expand Down

0 comments on commit 7269fd6

Please sign in to comment.