Skip to content
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

Trim console reporter output (#431) #432

Merged
merged 3 commits into from
Aug 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
2 changes: 1 addition & 1 deletion elm/src/Test/Reporter/JUnit.elm
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Test.Reporter.TestResults exposing (Failure, Outcome(..), SummaryInfo, Te
import Test.Runner.Failure exposing (InvalidReason(..), Reason(..))


reportBegin : { paths : List String, fuzzRuns : Int, testCount : Int, initialSeed : Int } -> Maybe Value
reportBegin : runInfo -> Maybe Value
reportBegin _ =
Nothing

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
21 changes: 11 additions & 10 deletions lib/elm-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -364,10 +364,9 @@ if (args._[0] === 'make') {
// On Bash 4.x (or zsh), if you give it a glob as its last argument, Bash
// translates that into a list of file paths. On bash 3.x it's just a string.
// Ergo, globify all the arguments we receive.
const fileGlobs = args._.length > 0 ? args._ : [];
const testFilePaths = resolveGlobs(fileGlobs);
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 All @@ -385,9 +384,9 @@ if (args._[0] === 'make') {
"\n\nAlternatively, if your application has tests in a different directory, try calling elm-test with a glob: elm-test 'frontend-app/**/*Tests.elm'.";

var errorMessage =
fileGlobs.length > 0
testFileGlobs.length > 0
? 'No tests found for the file pattern "' +
fileGlobs.toString() +
testFileGlobs.toString() +
'"\n\nMaybe try running elm-test with no arguments?'
: "No tests found in the tests/ directory.\n\nNOTE: Make sure you're running elm-test from your project's root directory, where its elm.json lives.\n\nTo generate some initial tests to get things going, run elm-test init." +
(isPackageProject ? '' : extraAppError);
Expand All @@ -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