Skip to content
This repository has been archived by the owner on Oct 30, 2021. It is now read-only.

Commit

Permalink
Fixes bug when UrlParser.parsePath is used during initialisation whic…
Browse files Browse the repository at this point in the history
…h causes require of test file to fail
  • Loading branch information
benansell committed Mar 3, 2018
1 parent 2843522 commit 8717771
Show file tree
Hide file tree
Showing 9 changed files with 121 additions and 17 deletions.
17 changes: 11 additions & 6 deletions lib/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,18 +120,18 @@ export class LoboImp implements Lobo {
return Bluebird.mapSeries(stages, (item: () => Bluebird<object>) => {
return item();
}).then(() => {
this.logger.debug("launch success");
this.logger.debug("Test execution complete");
if (program.watch) {
this.done(config);
}
}).catch((err) => {
if (err instanceof ReferenceError) {
if (err instanceof ReferenceError || err instanceof TypeError) {
this.handleUncaughtException(err, config);
return;
} else if (/Ran into a `Debug.crash` in module/.test(err)) {
this.logger.error(err);
} else {
this.logger.debug("launch failed", err);
this.logger.error("Error running the tests. ", err);
}

if (program.watch) {
Expand Down Expand Up @@ -406,7 +406,7 @@ export class LoboImp implements Lobo {
errorString = error.toString();
}

if (error instanceof ReferenceError) {
if (error instanceof ReferenceError || error instanceof TypeError) {
if (config && config.testFile && error.stack && error.stack.match(new RegExp(config.testFile))) {
if (/ElmTest.*Plugin\$findTests is not defined/.test(errorString)) {
this.logger.error("Error running the tests. This is usually caused by an npm upgrade to lobo: ");
Expand All @@ -420,8 +420,13 @@ export class LoboImp implements Lobo {
this.logger.info("");
this.logger.error(errorString);
this.logger.info("");
this.logger.error("Please raise an issue against lobo to request adding support for the elm-package that " +
"is referencing the above browser object");

if (program.veryVerbose || program.verbose) {
this.logger.error("Please raise an issue against lobo including the above messages to request adding support for the " +
"elm-package that caused this issue");
} else {
this.logger.error("Please rerun lobo with the --verbose option to see the cause of the error");
}
}
} else {
this.logger.error("Unhandled exception", errorString);
Expand Down
12 changes: 8 additions & 4 deletions lib/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ export interface NodeProcessStdout {

export interface BrowserGlobal extends NodeJS.Global {
document: { // required by Dom & Navigation
location: object // required by Navigation
location: { // required by Navigation & UrlParser
hash: string,
pathname: string,
search: string
}
};
window: { // required by AnimationFrame & Navigation
navigator: object // required by Navigation
Expand Down Expand Up @@ -108,8 +112,8 @@ export class RunnerImp {
app = require(testFile);
// tslint:enable:no-require-imports
} catch (err) {
logger.debug("Failed to require test file", err);
throw new Error("Failed to load test file" + testFile);
logger.debug("Failed to require test file", testFile);
throw err;
}

return app;
Expand All @@ -124,7 +128,7 @@ export class RunnerImp {
logger.info("-----------------------------------[ TEST ]-------------------------------------");

// add to the global scope browser global properties that are used by elm imports
(<BrowserGlobal>global).document = { location: {} };
(<BrowserGlobal>global).document = { location: { hash: "#", pathname: "/", search: "?" } };
(<BrowserGlobal>global).window = { navigator: {} };

let elmApp = this.loadElmTestApp(config.testFile, logger);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lobo",
"version": "0.4.2",
"version": "0.4.3",
"description": "Elm test runner",
"keywords": [
"elm",
Expand Down
2 changes: 1 addition & 1 deletion test/integration/elm-lang/elm-lang.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe("elm-lang", () => {

// assert
reporterExpect(result).summaryPassed();
reporterExpect(result).summaryCounts(2, 0);
reporterExpect(result).summaryCounts(3, 0);
expect(result.code).to.equal(0);
});
});
Expand Down
3 changes: 2 additions & 1 deletion test/integration/elm-lang/elm-package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"elm-lang/trampoline": "1.0.1 <= v < 2.0.0",
"elm-lang/virtual-dom": "2.0.0 <= v < 3.0.0",
"elm-lang/websocket": "1.0.2 <= v < 2.0.0",
"elm-lang/window": "1.0.1 <= v < 2.0.0"
"elm-lang/window": "1.0.1 <= v < 2.0.0",
"evancz/url-parser": "2.0.1 <= v < 3.0.0"
},
"elm-version": "0.18.0 <= v < 0.19.0"
}
20 changes: 18 additions & 2 deletions test/integration/elm-lang/src/ImportNavigation.elm
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module ImportNavigation exposing (..)

import Html exposing (Html, div)
import Navigation
import UrlParser


-- PROGRAM
Expand All @@ -29,12 +30,27 @@ main =


type alias Model =
{}
{ route : Maybe Route }


type Route
= AppRoute


routeParser : UrlParser.Parser (Route -> a) a
routeParser =
UrlParser.s "foo"
|> UrlParser.map AppRoute


parseLocation : Navigation.Location -> Maybe Route
parseLocation location =
UrlParser.parsePath routeParser location


init : Navigation.Location -> ( Model, Cmd Msg )
init location =
( {}, Cmd.none )
( { route = parseLocation location }, Cmd.none )



Expand Down
24 changes: 23 additions & 1 deletion test/integration/elm-lang/tests/Tests.elm
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ all =
describe "Tests"
[ testImportCheck
, testImportNavigation
, testImportNavigationInit
]


Expand All @@ -25,6 +26,27 @@ testImportNavigation : Test
testImportNavigation =
test "test import navigation" <|
\() ->
ImportNavigation.update ImportNavigation.None {}
ImportNavigation.update ImportNavigation.None { route = Nothing }
|> Tuple.second
|> Expect.equal Cmd.none


testImportNavigationInit : Test
testImportNavigationInit =
test "test import navigation init" <|
\() ->
{ href = "https://somebody:secret@example.com:123/foo/bar?id=baz#qux"
, host = "example.com:123"
, hostname = "example.com"
, protocol = "https"
, origin = "https://example.com"
, port_ = "123"
, pathname = "/foo/bar"
, search = "?id=baz"
, hash = "#qux"
, username = "somebody"
, password = "secret"
}
|> ImportNavigation.init
|> Tuple.second
|> Expect.equal Cmd.none
56 changes: 56 additions & 0 deletions test/unit/lib/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1616,6 +1616,62 @@ describe("lib main", () => {
"caused by an elm package using objects that are found in the browser but not in a node process");
});

it("should log unknown type error for missing browser objects correctly", () => {
// arrange
let error = new TypeError();
error.stack = "foo";
let config = <LoboConfig> {testFile: "foo"};

// act
lobo.handleUncaughtException(error, config);

// assert
expect(mockLogger.error).to.have.been.calledWith("Error running the tests. This is usually " +
"caused by an elm package using objects that are found in the browser but not in a node process");
});

it("should not ask for rerun with verbose option when verbose is set", () => {
// arrange
let error = new TypeError();
error.stack = "foo";
let config = <LoboConfig> {testFile: "foo"};
let revert = rewiredMain.__with__({program: {verbose: true}});

// act
revert(() => lobo.handleUncaughtException(error, config));

// assert
expect(mockLogger.error).to.have.been.not.calledWith("Please rerun lobo with the --verbose option to see the cause of the error");
});

it("should not ask for rerun with verbose option when veryVerbose is set", () => {
// arrange
let error = new TypeError();
error.stack = "foo";
let config = <LoboConfig> {testFile: "foo"};
let revert = rewiredMain.__with__({program: {veryVerbose: true}});

// act
revert(() => lobo.handleUncaughtException(error, config));

// assert
expect(mockLogger.error).to.have.been.not.calledWith("Please rerun lobo with the --verbose option to see the cause of the error");
});

it("should ask for rerun with verbose option when verbose is not set", () => {
// arrange
let error = new TypeError();
error.stack = "foo";
let config = <LoboConfig> {testFile: "foo"};
let revert = rewiredMain.__with__({program: {verbose: false}});

// act
revert(() => lobo.handleUncaughtException(error, config));

// assert
expect(mockLogger.error).to.have.been.calledWith("Please rerun lobo with the --verbose option to see the cause of the error");
});

it("should not exit the process when there is an error and in watch mode", () => {
// arrange
let error = new Error();
Expand Down
2 changes: 1 addition & 1 deletion test/unit/lib/runner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ describe("lib runner", () => {
});

it("should throw an error when the elm test app is not found", () => {
expect(() => runner.loadElmTestApp("./foo", mockLogger)).to.throw("Failed to load test file");
expect(() => runner.loadElmTestApp("./foo", mockLogger)).to.throw("Cannot find module './foo'");
});
});

Expand Down

0 comments on commit 8717771

Please sign in to comment.