From 443c2667f167f6a212aa4aa663658f6d29f5070d Mon Sep 17 00:00:00 2001 From: Rob Yoder Date: Wed, 26 Jan 2022 21:09:12 -0700 Subject: [PATCH 1/6] Fix local `elm make` in test project --- tests/data/simple/elm.json | 17 ++++++++++------- tests/data/simple/tests/Example.elm | 2 +- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/tests/data/simple/elm.json b/tests/data/simple/elm.json index 3b75394..7468f5e 100644 --- a/tests/data/simple/elm.json +++ b/tests/data/simple/elm.json @@ -6,20 +6,23 @@ "elm-version": "0.19.1", "dependencies": { "direct": { - "elm/core": "1.0.4" + "elm/browser": "1.0.2", + "elm/core": "1.0.5", + "elm/html": "1.0.0" }, - "indirect": {} + "indirect": { + "elm/json": "1.1.3", + "elm/time": "1.0.0", + "elm/url": "1.0.0", + "elm/virtual-dom": "1.0.2" + } }, "test-dependencies": { "direct": { "elm-explorations/test": "1.2.2" }, "indirect": { - "elm/html": "1.0.0", - "elm/json": "1.1.3", - "elm/random": "1.0.0", - "elm/time": "1.0.0", - "elm/virtual-dom": "1.0.2" + "elm/random": "1.0.0" } } } diff --git a/tests/data/simple/tests/Example.elm b/tests/data/simple/tests/Example.elm index ae27040..d39457a 100644 --- a/tests/data/simple/tests/Example.elm +++ b/tests/data/simple/tests/Example.elm @@ -1,6 +1,6 @@ module Example exposing (..) -import Expect exposing (Expectation) +import Expect import Main import Test exposing (..) From eb3fb98deb19faa1c096a97d826f6c3361478b66 Mon Sep 17 00:00:00 2001 From: Rob Yoder Date: Wed, 26 Jan 2022 21:24:44 -0700 Subject: [PATCH 2/6] Ignore generated coverage files --- tests/data/simple/.gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/data/simple/.gitignore b/tests/data/simple/.gitignore index a72d1b2..1e4d2f5 100644 --- a/tests/data/simple/.gitignore +++ b/tests/data/simple/.gitignore @@ -1 +1,2 @@ +.coverage elm-stuff/ From 462a79361dbca2271191cee253dee63d7168c6cc Mon Sep 17 00:00:00 2001 From: Rob Yoder Date: Wed, 26 Jan 2022 22:10:52 -0700 Subject: [PATCH 3/6] Support multiple test projects --- tests/runner.js | 117 +++++++++++++++++++++++++++--------------------- 1 file changed, 65 insertions(+), 52 deletions(-) diff --git a/tests/runner.js b/tests/runner.js index e38c5b6..0908dcc 100644 --- a/tests/runner.js +++ b/tests/runner.js @@ -37,69 +37,82 @@ describe("Sanity test", () => { }); }); +var projects = [ + { + path: "simple", + args: [], + generateArgs: [], + }, +]; + describe("E2E tests", function() { this.timeout(Infinity); - it("Should run succesfully", done => { - var process = spawn.spawn(elmCoverage, { - cwd: path.join("tests", "data", "simple") - }); - - process.stderr.on("data", data => { - console.error(data.toString()); - }); - process.on("exit", exitCode => { - assert.equal(exitCode, 0, "Expected to finish succesfully"); - done(); + projects.forEach((project) => { + describe(project.path, () => { + it("Should run succesfully", done => { + var process = spawn.spawn(elmCoverage, project.args, { + cwd: path.join("tests", "data", project.path) + }); + + process.stderr.on("data", data => { + console.error(data.toString()); + }); + + process.on("exit", exitCode => { + assert.equal(exitCode, 0, "Expected to finish succesfully"); + done(); + }); + }); + + it("Should generate schema-validated JSON", () => + Promise.all([ + fs.readJSON(require.resolve("../docs/elm-coverage.json")), + generateJSON(project) + ]).spread((json, schema) => { + expect(json).to.be.jsonSchema(schema); + })); + + it("Should generate JSON that matches the pregenerated one, modulus runcount", () => + Promise.all([ + generateJSON(project), + fs.readJSON(require.resolve("./data/" + project.path + "/expected.json")) + ]).spread((actual, expectedJSON) => { + var expected = {}; + + //expected event is "coverage" + expected.event = "coverage"; + + // Ignore runcounts + expected.coverageData = _.mapValues( + expectedJSON.coverageData, + moduleData => + _.map(moduleData, coverage => + Object.assign({}, coverage, { + count: _.isInteger + }) + ) + ); + + // System agnostic paths + expected.moduleMap = _.mapValues( + expectedJSON.moduleMap, + modulePath => _.partial(_.matchesPath, modulePath, _) + ); + + expect(actual).to.matchPattern(expected); + })); }); }); - - it("Should generate schema-validated JSON", () => - Promise.all([ - fs.readJSON(require.resolve("../docs/elm-coverage.json")), - generateJSON() - ]).spread((json, schema) => { - expect(json).to.be.jsonSchema(schema); - })); - - it("Should generate JSON that matches the pregenerated one, modulus runcount", () => - Promise.all([ - generateJSON(), - fs.readJSON(require.resolve("./data/simple/expected.json")) - ]).spread((actual, expectedJSON) => { - var expected = {}; - - //expected event is "coverage" - expected.event = "coverage"; - - // Ignore runcounts - expected.coverageData = _.mapValues( - expectedJSON.coverageData, - moduleData => - _.map(moduleData, coverage => - Object.assign({}, coverage, { - count: _.isInteger - }) - ) - ); - - // System agnostic paths - expected.moduleMap = _.mapValues( - expectedJSON.moduleMap, - modulePath => _.partial(_.matchesPath, modulePath, _) - ); - - expect(actual).to.matchPattern(expected); - })); }); -function generateJSON() { +function generateJSON(project) { return new Promise((resolve, reject) => { var process = spawn.spawn( elmCoverage, - ["generate", "--report", "json"], + ["generate", ...project.generateArgs, "--report", "json"], { - cwd: path.join("tests", "data", "simple") + cwd: path.join("tests", "data", project.path) } ); From eba522aa85131452ab995d121aae5c8fcb95498d Mon Sep 17 00:00:00 2001 From: Rob Yoder Date: Wed, 26 Jan 2022 22:12:01 -0700 Subject: [PATCH 4/6] Add (failing) tests for custom tests location --- tests/data/custom-locations/.gitignore | 2 + .../data/custom-locations/client/src/Main.elm | 8 ++++ .../custom-locations/client/src/Simple.elm | 5 +++ .../custom-locations/client/tests/Example.elm | 13 ++++++ tests/data/custom-locations/elm.json | 29 +++++++++++++ tests/data/custom-locations/expected.json | 41 +++++++++++++++++++ tests/runner.js | 5 +++ 7 files changed, 103 insertions(+) create mode 100644 tests/data/custom-locations/.gitignore create mode 100644 tests/data/custom-locations/client/src/Main.elm create mode 100644 tests/data/custom-locations/client/src/Simple.elm create mode 100644 tests/data/custom-locations/client/tests/Example.elm create mode 100644 tests/data/custom-locations/elm.json create mode 100644 tests/data/custom-locations/expected.json diff --git a/tests/data/custom-locations/.gitignore b/tests/data/custom-locations/.gitignore new file mode 100644 index 0000000..1e4d2f5 --- /dev/null +++ b/tests/data/custom-locations/.gitignore @@ -0,0 +1,2 @@ +.coverage +elm-stuff/ diff --git a/tests/data/custom-locations/client/src/Main.elm b/tests/data/custom-locations/client/src/Main.elm new file mode 100644 index 0000000..e74b0cb --- /dev/null +++ b/tests/data/custom-locations/client/src/Main.elm @@ -0,0 +1,8 @@ +module Main exposing (foo) + +import Simple + + +foo : String +foo = + "hello " ++ Simple.foo diff --git a/tests/data/custom-locations/client/src/Simple.elm b/tests/data/custom-locations/client/src/Simple.elm new file mode 100644 index 0000000..839e85f --- /dev/null +++ b/tests/data/custom-locations/client/src/Simple.elm @@ -0,0 +1,5 @@ +module Simple exposing (foo) + +foo : String +foo = + "world" diff --git a/tests/data/custom-locations/client/tests/Example.elm b/tests/data/custom-locations/client/tests/Example.elm new file mode 100644 index 0000000..d39457a --- /dev/null +++ b/tests/data/custom-locations/client/tests/Example.elm @@ -0,0 +1,13 @@ +module Example exposing (..) + +import Expect +import Main +import Test exposing (..) + + +suite : Test +suite = + test "A simple, succesfull test" <| + \_ -> + Main.foo + |> Expect.equal "hello world" diff --git a/tests/data/custom-locations/elm.json b/tests/data/custom-locations/elm.json new file mode 100644 index 0000000..e8a326e --- /dev/null +++ b/tests/data/custom-locations/elm.json @@ -0,0 +1,29 @@ +{ + "type": "application", + "source-directories": [ + "client/src", + "client/tests" + ], + "elm-version": "0.19.1", + "dependencies": { + "direct": { + "elm/browser": "1.0.2", + "elm/core": "1.0.5", + "elm/html": "1.0.0" + }, + "indirect": { + "elm/json": "1.1.3", + "elm/time": "1.0.0", + "elm/url": "1.0.0", + "elm/virtual-dom": "1.0.2" + } + }, + "test-dependencies": { + "direct": { + "elm-explorations/test": "1.2.2" + }, + "indirect": { + "elm/random": "1.0.0" + } + } +} diff --git a/tests/data/custom-locations/expected.json b/tests/data/custom-locations/expected.json new file mode 100644 index 0000000..a828c13 --- /dev/null +++ b/tests/data/custom-locations/expected.json @@ -0,0 +1,41 @@ +{ + "coverageData": { + "Simple": [ + { + "type": "declaration", + "name": "foo", + "complexity": 1, + "from": { + "line": 4, + "column": 1 + }, + "to": { + "line": 5, + "column": 12 + }, + "count": 8 + } + ], + "Main": [ + { + "type": "declaration", + "name": "foo", + "complexity": 1, + "from": { + "line": 7, + "column": 1 + }, + "to": { + "line": 8, + "column": 27 + }, + "count": 8 + } + ] + }, + "moduleMap": { + "Simple": "client/src/Simple.elm", + "Main": "client/src/Main.elm" + }, + "event": "coverage" +} diff --git a/tests/runner.js b/tests/runner.js index 0908dcc..642121b 100644 --- a/tests/runner.js +++ b/tests/runner.js @@ -43,6 +43,11 @@ var projects = [ args: [], generateArgs: [], }, + { + path: "custom-locations", + args: ["client/src", "--tests", "client/tests"], + generateArgs: ["client/src"], + } ]; describe("E2E tests", function() { From 9509ff8ffed9d26ea2e5d6b9ed5a5985f1c9fec1 Mon Sep 17 00:00:00 2001 From: Rob Yoder Date: Wed, 26 Jan 2022 22:12:19 -0700 Subject: [PATCH 5/6] Fix issue with custom tests location --- lib/runner.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/runner.js b/lib/runner.js index fab55e2..8302a2e 100644 --- a/lib/runner.js +++ b/lib/runner.js @@ -85,7 +85,7 @@ var setupTests = (log, args) => () => { return fs.writeJson(tmpElmJson, elmPackage); }) .then(function() { - var generatedTestsDir = path.join(coverageDir, "tests"); + var generatedTestsDir = path.join(coverageDir, args.tests); log.debug( "copyTests", "Copying tests from " + args.tests + " to " + generatedTestsDir From 28786ce52e7e137b217728fedbaacd68da14e610 Mon Sep 17 00:00:00 2001 From: Rob Yoder Date: Wed, 26 Jan 2022 22:13:08 -0700 Subject: [PATCH 6/6] Remove unused lines --- lib/runner.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/runner.js b/lib/runner.js index 8302a2e..2c05a68 100644 --- a/lib/runner.js +++ b/lib/runner.js @@ -73,9 +73,6 @@ var setupTests = (log, args) => () => { "modifyingTests", "Generating elm.json for coverage at " + tmpElmJson + "..." ); - var covSrc = path.resolve(path.join(coverageDir, args.path)); - var originalPath = path.resolve(args.path); - elmPackage["name"] = "author/project"; return elmPackage;