Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Commit

Permalink
Merge pull request #73 from bespoken/TweakingAway
Browse files Browse the repository at this point in the history
Closes #62
  • Loading branch information
OpenDog committed Sep 8, 2016
2 parents fc0f654 + a29a6a8 commit 22057f6
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ We call it working in BEAST mode - rampage through code/test iterations as Alexa
Do not slow-down for:
* Time-consuming server deployments
* Over-complicated and error-prone packaging scripts
* Seemingly-innocuous-but-still-pesky service restarts.
* Seemingly-innocuous-but-still-pesky service restarts

The current version provides three commands - **proxy http**, **proxy lambda** and **speak**.

Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ We call it working in BEAST mode - rampage through code/test iterations as Alexa
Do not slow-down for:
* Time-consuming server deployments
* Over-complicated and error-prone packaging scripts
* Seemingly-innocuous-but-still-pesky service restarts.
* Seemingly-innocuous-but-still-pesky service restarts

The current version provides three commands - **proxy http**, **proxy lambda** and **speak**.

Expand Down
15 changes: 12 additions & 3 deletions lib/client/lambda-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class LambdaRunner {
private lambda: any = null;
private watcher: FSWatcher = null;
private requests: Array<IncomingMessage> = [];
public onDirty: () => void = null; // Callback for test-ability
public onDirty: (filename: string) => void = null; // Callback for test-ability

/**
* The file to run
Expand All @@ -38,11 +38,20 @@ export class LambdaRunner {
// Add a watch to the current directory
let watchOptions = {"persistent": false, "recursive": true};
this.watcher = fs.watch(process.cwd(), watchOptions, function(event: string, filename: string) {
if (filename.indexOf("node_modules") === -1) {
let exclude = false;
if (filename.indexOf("node_modules") !== -1) {
exclude = true;
} else if (filename.endsWith("___")) {
exclude = true;
} else if (filename.startsWith(".")) {
exclude = true;
}

if (!exclude) {
LoggingHelper.info(Logger, "FS.Watch Event: " + event + ". File: " + filename + ". Reloading.");
self.dirty = true;
if (self.onDirty !== undefined && self.onDirty !== null) {
self.onDirty();
self.onDirty(filename);
}
}
});
Expand Down
6 changes: 4 additions & 2 deletions lib/core/file-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as fs from "fs";
export class FileUtil {
// StackOverflow code - always the best :-)
// http://stackoverflow.com/questions/11293857/fastest-way-to-copy-file-in-node-js
public static copyFile(source: string, target: string, callback: (error?: string) => void) {
public static copyFile(source: string, target: string, callback?: (error?: string) => void) {
let cbCalled = false;

let readStream = fs.createReadStream(source);
Expand All @@ -23,7 +23,9 @@ export class FileUtil {

function done(error?: string) {
if (!cbCalled) {
callback(error);
if (callback !== undefined && callback !== null) {
callback(error);
}
cbCalled = true;
}
}
Expand Down
31 changes: 29 additions & 2 deletions test/client/lambda-runner-test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/// <reference path="../../typings/index.d.ts" />

import * as assert from "assert";
import * as fs from "fs";
import {Global} from "../../lib/core/global";
import {LambdaRunner} from "../../lib/client/lambda-runner";
import {HTTPClient} from "../../lib/core/http-client";
Expand Down Expand Up @@ -111,8 +112,9 @@ describe("LambdaRunner", function() {
let o = JSON.parse(data.toString());
assert.equal(o.success, true);
assert.equal(o.reloaded, true);
runner.stop();
done();
runner.stop(function () {
done();
});
});
};

Expand All @@ -130,6 +132,31 @@ describe("LambdaRunner", function() {
});
});

it("Handles Reload Exclusions Correctly", function(done) {
let targetFile = "ExampleLambda.js";
let runner = new LambdaRunner("ExampleLambda.js", 10000);
runner.start();

runner.onDirty = function (filename: string) {
if (filename === "ExampleLambdaCopy.js") {
// We some times get the change from the previous test - we can ignore it
} else {
assert(false, "Should not be called");
}
};

FileUtil.copyFile(targetFile, "ExampleLambda.js___");
FileUtil.copyFile(targetFile, ".dummy");

setTimeout(function () {
fs.unlinkSync("ExampleLambda.js___");
fs.unlinkSync(".dummy");
runner.stop(function () {
done();
});
}, 100);
});

it("Handles No Reload after stop", function(done) {
let tempFile = "ExampleLambdaCopy.js";
let runner = new LambdaRunner(tempFile, 10000);
Expand Down

0 comments on commit 22057f6

Please sign in to comment.