Skip to content

Commit

Permalink
added the serenityrunner jasmine run [file] command for CI integration
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremydmiller committed Nov 15, 2011
1 parent 174f62f commit 254b68c
Show file tree
Hide file tree
Showing 10 changed files with 188 additions and 66 deletions.
44 changes: 28 additions & 16 deletions src/FubuMVC.OwinHost/FubuOwinHost.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Net;
using System.Threading;
using System.Web.Routing;
using FubuCore;
using FubuMVC.Core;
Expand All @@ -16,13 +17,13 @@ public class FubuOwinHost
{
private readonly IApplicationSource _source;
private readonly ISchedulerDelegate _schedulerDelegate;
private FubuRuntime _runtime;
private IPEndPoint _listeningEndpoint;
private AppDelegate _applicationDelegate;
private IScheduler _scheduler;
private IServer _server;
private int _port;
private bool _latched;
private IDisposable _kayakListenerDisposer;

public FubuOwinHost(IApplicationSource source) : this(source, new SchedulerDelegate())
{
Expand All @@ -34,6 +35,8 @@ public FubuOwinHost(IApplicationSource source, ISchedulerDelegate schedulerDeleg
_schedulerDelegate = schedulerDelegate;
}

public bool Verbose { get; set; }

public void RunApplication(int port, Action<FubuRuntime> activation)
{
_port = port;
Expand All @@ -52,31 +55,44 @@ public void RunApplication(int port, Action<FubuRuntime> activation)
throw new InvalidOperationException("Start() can only be called after RunApplication() and Stop()");
}

rebuildFubuMVCApplication(activation);
var runtime = rebuildFubuMVCApplication();

using (_server.Listen(_listeningEndpoint))
{
_kayakListenerDisposer = _server.Listen(_listeningEndpoint);
_scheduler.Post(() => ThreadPool.QueueUserWorkItem(o => activation(runtime)));
_scheduler.Start();
}



}

private void rebuildFubuMVCApplication(Action<FubuRuntime> activation)
private FubuRuntime rebuildFubuMVCApplication()
{
RouteTable.Routes.Clear();
_runtime = _source.BuildApplication().Bootstrap();
activation(_runtime);
return _source.BuildApplication().Bootstrap();
}

public void Stop()
{
_scheduler.Stop();
try
{
_scheduler.Stop();

}
catch (Exception)
{
// That's right, shut this puppy down
}

_server.SafeDispose();
}

public void Recycle(Action<FubuRuntime> activation)
{
_latched = true;
rebuildFubuMVCApplication(activation);
var runtime = rebuildFubuMVCApplication();
_latched = false;

activation(runtime);
}


Expand All @@ -87,7 +103,7 @@ public void ExecuteRequest(IDictionary<string, object> env, ResultDelegate resul
var request = new Request(env);
var response = new Response(result);

Console.Write("Received " + request.Path);
if (Verbose) Console.WriteLine("Received " + request.Path);

var context = new GateHttpContext(request);
var routeData = RouteTable.Routes.GetRouteData(context);
Expand All @@ -104,7 +120,7 @@ public void ExecuteRequest(IDictionary<string, object> env, ResultDelegate resul

// TODO -- return 404 if the route is not found

Console.WriteLine(" ({0})", response.Status);
if (Verbose) Console.WriteLine(" ({0})", response.Status);
}

private static void write404(Response response)
Expand Down Expand Up @@ -135,10 +151,6 @@ private static void executeRoute(Request request, RouteData routeData, Response
}
}

public FubuRuntime Runtime
{
get { return _runtime; }
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ public void has_all_the_nodes()
{
var expectedValues =
@"
application
Pak2
Pak2/folder1
Pak2/folder1/folder2
Expand Down
38 changes: 20 additions & 18 deletions src/Serenity.Testing/Jasmine/SpecificationGraphTester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ public void finds_all_the_specs_and_puts_in_folder_structure()
scripts/lib1.js
scripts/lib2.js
scripts/lib3.js
scripts/specs/something.js
scripts/specs/lib1.spec.js
scripts/specs/lib2.spec.js
scripts/specs/lib3.spec.js
pak1:scripts/specs/something.js
pak1:scripts/specs/lib1.spec.js
pak1:scripts/specs/lib2.spec.js
pak1:scripts/specs/lib3.spec.js
pak1:scripts/specs/lib4.spec.js
pak1:scripts/specs/lib5.spec.js
pak1:scripts/specs/lib6.spec.js
Expand All @@ -42,14 +42,16 @@ public void finds_all_the_specs_and_puts_in_folder_structure()
");

var graph = new SpecificationGraph(thePipeline);
graph.AllSpecifications.Select(x => x.File.Name).Each(x => Debug.WriteLine(x));


graph.AllSpecifications.Select(x => x.File.Name)
.ShouldHaveTheSameElementsAs(
"specs/something.js",
"f1/specs/lib7.spec.js",
"specs/something.js",
"specs/lib1.spec.js",
"specs/lib2.spec.js",
"specs/lib3.spec.js",
"f1/specs/lib7.spec.js",

"specs/lib4.spec.js",

"specs/lib5.spec.js",
Expand All @@ -64,30 +66,30 @@ public void finds_all_the_specs_and_puts_in_folder_structure()
public void makes_asset_graph_dependencies_between_files()
{
theFiles.LoadAssets(@"
scripts/lib1.js
scripts/lib2.js
scripts/lib3.js
scripts/specs/something.js
scripts/specs/lib1.spec.js
scripts/specs/lib2.spec.js
scripts/specs/lib3.spec.js
pak1:scripts/lib1.js
pak1:scripts/lib2.js
pak1:scripts/lib3.js
pak1:scripts/specs/something.js
pak1:scripts/specs/lib1.spec.js
pak1:scripts/specs/lib2.spec.js
pak1:scripts/specs/lib3.spec.js
");


var graph = new SpecificationGraph(thePipeline);

graph.FindSpecByFullName("specs/lib1.spec.js").Libraries.Select(x => x.Name)
graph.FindSpecByFullName("pak1/lib1.spec.js").Libraries.Select(x => x.Name)
.ShouldHaveTheSameElementsAs("lib1.js");


graph.FindSpecByFullName("specs/lib2.spec.js").Libraries.Select(x => x.Name)
graph.FindSpecByFullName("pak1/lib2.spec.js").Libraries.Select(x => x.Name)
.ShouldHaveTheSameElementsAs("lib2.js");


graph.FindSpecByFullName("specs/lib3.spec.js").Libraries.Select(x => x.Name)
graph.FindSpecByFullName("pak1/lib3.spec.js").Libraries.Select(x => x.Name)
.ShouldHaveTheSameElementsAs("lib3.js");

graph.FindSpecByFullName("specs/something.js").Libraries.Any().ShouldBeFalse();
graph.FindSpecByFullName("pak1/something.js").Libraries.Any().ShouldBeFalse();

}
}
Expand Down
12 changes: 12 additions & 0 deletions src/Serenity/ApplicationDriver.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using FubuMVC.Core.Assets.Http;
using FubuMVC.Core.Runtime;
using FubuMVC.Core.Urls;
Expand All @@ -24,6 +25,12 @@ public void NavigateTo(object target)
_application.Driver.Navigate().GoToUrl(url);
}

public void NavigateTo<T>(Expression<Action<T>> expression)
{
var url = _application.Urls.UrlFor(expression);
_application.Driver.Navigate().GoToUrl(url);
}

public ScreenDriver GetCurrentScreen()
{
return new ScreenDriver(_application.Driver);
Expand All @@ -38,6 +45,11 @@ public string AssetUrlFor(string file)
{
return _application.RootUrl + ("/_content/" + file).Replace("//", "/");
}

public void NavigateToHome()
{
_application.Driver.Navigate().GoToUrl(_application.RootUrl);
}
}

public class AssetTagsState
Expand Down
18 changes: 0 additions & 18 deletions src/Serenity/Jasmine/InteractiveJasmineCommand.cs

This file was deleted.

33 changes: 33 additions & 0 deletions src/Serenity/Jasmine/JasmineCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;
using FubuCore.CommandLine;

namespace Serenity.Jasmine
{
[CommandDescription("Opens up a web browser application to browse and execute Jasmine specifications",
Name = "jasmine")]
public class JasmineCommand : FubuCommand<JasmineInput>
{
public override bool Execute(JasmineInput input)
{
// TODO -- tighten up the defensive programming against bad input
var runner = new JasmineRunner(input);

if (input.Mode == JasmineMode.interactive)
{
runner.OpenInteractive();
}

if (input.Mode == JasmineMode.run)
{
if (!runner.RunAllSpecs())
{
Console.WriteLine("any key will do");
Console.ReadLine();
throw new ApplicationException("Jasmine specs failed!");
}
}

return true;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,25 @@

namespace Serenity.Jasmine
{
public class InteractiveJasmineInput
public enum JasmineMode
{
public InteractiveJasmineInput()
interactive,
run
}

public class JasmineInput
{
public JasmineInput()
{
PortFlag = 5500;
BrowserFlag = BrowserType.Chrome;

}

public JasmineMode Mode { get; set; }

public string SerenityFile { get; set; }

public int PortFlag { get; set; }
public BrowserType BrowserFlag { get; set; }

Expand Down

0 comments on commit 254b68c

Please sign in to comment.