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

Support custom tests location #46

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions lib/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -85,7 +82,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
Expand Down
2 changes: 2 additions & 0 deletions tests/data/custom-locations/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.coverage
elm-stuff/
8 changes: 8 additions & 0 deletions tests/data/custom-locations/client/src/Main.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module Main exposing (foo)

import Simple


foo : String
foo =
"hello " ++ Simple.foo
5 changes: 5 additions & 0 deletions tests/data/custom-locations/client/src/Simple.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module Simple exposing (foo)

foo : String
foo =
"world"
13 changes: 13 additions & 0 deletions tests/data/custom-locations/client/tests/Example.elm
Original file line number Diff line number Diff line change
@@ -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"
29 changes: 29 additions & 0 deletions tests/data/custom-locations/elm.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
41 changes: 41 additions & 0 deletions tests/data/custom-locations/expected.json
Original file line number Diff line number Diff line change
@@ -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"
}
1 change: 1 addition & 0 deletions tests/data/simple/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.coverage
elm-stuff/
17 changes: 10 additions & 7 deletions tests/data/simple/elm.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
2 changes: 1 addition & 1 deletion tests/data/simple/tests/Example.elm
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Example exposing (..)

import Expect exposing (Expectation)
import Expect
import Main
import Test exposing (..)

Expand Down
122 changes: 70 additions & 52 deletions tests/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,69 +37,87 @@ describe("Sanity test", () => {
});
});

var projects = [
{
path: "simple",
args: [],
generateArgs: [],
},
{
path: "custom-locations",
args: ["client/src", "--tests", "client/tests"],
generateArgs: ["client/src"],
}
];

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)
}
);

Expand Down