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

Commit

Permalink
Merge pull request #18 from benansell/update_node_carbon
Browse files Browse the repository at this point in the history
Update node carbon
  • Loading branch information
benansell authored Nov 6, 2017
2 parents d56a066 + fec27f6 commit a9ff4f9
Show file tree
Hide file tree
Showing 9 changed files with 134 additions and 17 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ language: node_js

node_js:
- "6"
- "8"

cache:
directories:
Expand Down
1 change: 1 addition & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ environment:
ELM_VERSION: "0.18.0"
matrix:
- nodejs_version: "4"
- nodejs_version: "9"

platform:
- x64
Expand Down
12 changes: 6 additions & 6 deletions lib/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,14 @@ export class BuilderImp implements Builder {
}

public syncTestElmPackage(config: LoboConfig, baseElmPackageDir: string, testElmPackageDir: string, testDir: string): Bluebird<object> {
let steps: Array<(result?: ElmPackageCompare) => Bluebird<object>> = [() => this.readElmPackage(baseElmPackageDir, testElmPackageDir),
let steps: Array<(result: ElmPackageCompare) => Bluebird<object>> = [() => this.readElmPackage(baseElmPackageDir, testElmPackageDir),
(result: ElmPackageCompare) =>
this.updateSourceDirectories(config, baseElmPackageDir, result.base, testElmPackageDir, testDir, result.test),
(result: ElmPackageCompare) => this.updateDependencies(config, result.base, testElmPackageDir, result.test)];

let value: ElmPackageCompare;

return Bluebird.mapSeries(steps, (item: (result: ElmPackageCompare) => Bluebird<object>) => item(value)
return Bluebird.mapSeries(steps, (item: (result: ElmPackageCompare) => Bluebird<ElmPackageCompare>) => item(value)
.then((result: ElmPackageCompare) => value = result));
}

Expand Down Expand Up @@ -157,8 +157,8 @@ export class BuilderImp implements Builder {
});
}

public updateSourceDirectoriesAction(sourceDirectories: string[], testElmPackageDir: string, testElmPackage: ElmPackageJson)
: ElmPackageJson {
public updateSourceDirectoriesAction(sourceDirectories: string[], testElmPackageDir: string, testElmPackage: ElmPackageJson):
ElmPackageJson {
testElmPackage.sourceDirectories = sourceDirectories;
this.elmPackageHelper.write(testElmPackageDir, testElmPackage);

Expand Down Expand Up @@ -187,7 +187,7 @@ export class BuilderImp implements Builder {

promptly.confirm(
"The dependencies of the test elm-package.json need to be updated to contain:\n" +
diffString.join("\n") + "\n\nMay I add them to elm-package.json for you?" +
diffString.join("\n") + "\n\nMay I add them to elm-package.json for you--------?" +
this.yOrN,
{"default": "yes"}, (err, value) => {
if (err) {
Expand Down Expand Up @@ -273,7 +273,7 @@ export class BuilderImp implements Builder {

public isNotExistingDependency(dependencies: string[][], candidate: string[]): boolean {
return !_.find(dependencies, x => {
return candidate[0] === x[0] && candidate[1] === x[1];
return x[0] === candidate[0] && !this.elmPackageHelper.isImprovedMinimumConstraint(x[1], candidate[1]);
});
}

Expand Down
19 changes: 19 additions & 0 deletions lib/elm-package-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export interface ElmPackageJson {
}

export interface ElmPackageHelper {
isImprovedMinimumConstraint(dependency: string, candidate: string): boolean;
path(elmPackageJsonDirectory: string): string;
read(elmPackageJsonDirectory: string): ElmPackageJson | undefined;
write(elmPackageJsonDirectory: string, elmPackage: ElmPackageJson): void;
Expand All @@ -27,6 +28,24 @@ export class ElmPackageHelperImp implements ElmPackageHelper {
this.logger = logger;
}

public isImprovedMinimumConstraint(dependency: string, candidate: string): boolean {
if (dependency === candidate) {
return false;
}

let versionRegex = /^(\d)\.(\d)\.(\d)/;
let dependencyLowerBound = versionRegex.exec(dependency);
let candidateLowerBound = versionRegex.exec(candidate);

if (!dependencyLowerBound || dependencyLowerBound.length !== 4 || !candidateLowerBound || candidateLowerBound.length !== 4) {
return false;
}

return dependencyLowerBound[1] < candidateLowerBound[1]
|| dependencyLowerBound[2] < candidateLowerBound[2]
|| dependencyLowerBound[3] < candidateLowerBound[3];
}

public path(elmPackageJsonDirectory: string): string {
return path.join(elmPackageJsonDirectory, "elm-package.json");
}
Expand Down
4 changes: 3 additions & 1 deletion lib/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ export interface PluginOption {
readonly defaultValue?: PluginOptionValue;
readonly description: string;
readonly flags: string;
readonly parser?: ((arg1: PluginOptionValue, arg2?: PluginOptionValue) => PluginOptionValue) | RegExp;
readonly parser?: RegExp
| ((arg1: string) => PluginOptionValue)
| ((arg1: string, arg2: string) => PluginOptionValue);
}

export interface PluginReporter {
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lobo",
"version": "0.3.3",
"version": "0.4.0",
"description": "Elm test runner",
"keywords": [
"elm",
Expand Down Expand Up @@ -37,13 +37,13 @@
"tmp": "^0.0.33"
},
"devDependencies": {
"@types/bluebird": "^3.5.17",
"@types/bluebird": "^3.5.18",
"@types/chai": "^4.0.3",
"@types/chai-things": "0.0.32",
"@types/chokidar": "^1.7.3",
"@types/commander": "^2.11.0",
"@types/fast-levenshtein": "0.0.1",
"@types/lodash": "^4.14.80",
"@types/lodash": "^4.14.81",
"@types/mocha": "^2.2.44",
"@types/node": "^8.0.47",
"@types/promptly": "^1.1.28",
Expand All @@ -63,12 +63,12 @@
"nyc": "^11.3.0",
"rewire": "^2.5.2",
"rimraf": "^2.6.2",
"sinon": "^4.0.2",
"sinon": "^4.1.1",
"sinon-chai": "^2.14.0",
"source-map-support": "^0.5.0",
"ts-node": "^3.3.0",
"tslint": "^5.8.0",
"typescript": "^2.5.3"
"typescript": "^2.6.1"
},
"nyc": {
"exclude": [
Expand Down
24 changes: 23 additions & 1 deletion test/unit/lib/builder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe("lib builder", () => {
mockLogger.error = Sinon.spy();
mockLogger.info = Sinon.spy();
mockLogger.trace = Sinon.spy();
mockHelper = <ElmPackageHelper> {path: x => x, read: Sinon.stub(), write: Sinon.stub()};
mockHelper = <ElmPackageHelper> {isImprovedMinimumConstraint: Sinon.stub(), path: x => x, read: Sinon.stub(), write: Sinon.stub()};
mockUtil = <Util> {};
mockUtil.resolveDir = Sinon.spy();
builder = new rewiredImp(mockHelper, mockLogger, mockUtil);
Expand Down Expand Up @@ -1561,6 +1561,28 @@ describe("lib builder", () => {
// assert
expect(actual).to.be.true;
});

it("should return true when the candidate is an improved constraint", () => {
// arrange
mockHelper.isImprovedMinimumConstraint = (x, y) => true;

// act
let actual = builder.isNotExistingDependency([["foo", "1.0.0"]], ["foo", "2.0.0"]);

// assert
expect(actual).to.be.true;
});

it("should return false when the candidate is not an improved constraint", () => {
// arrange
mockHelper.isImprovedMinimumConstraint = (x, y) => false;

// act
let actual = builder.isNotExistingDependency([["foo", "2.0.0"]], ["foo", "1.0.0"]);

// assert
expect(actual).to.be.false;
});
});

describe("installDependencies", () => {
Expand Down
75 changes: 75 additions & 0 deletions test/unit/lib/elm-package-helper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,81 @@ describe("lib elm-package-helper", () => {
});
});

describe("isImprovedMinimumConstraint", () => {
it("should return false when the dependency and the candidate constraints are the same", () => {
// act
let actual = helper.isImprovedMinimumConstraint("1.0.0 <= v < 2.0.0", "1.0.0 <= v < 2.0.0");

// assert
expect(actual).to.be.false;
});

it("should return false when the dependency is not a valid constraint", () => {
// act
let actual = helper.isImprovedMinimumConstraint("foo", "1.0.0");

// assert
expect(actual).to.be.false;
});

it("should return false when the candidate is not a valid constraint", () => {
// act
let actual = helper.isImprovedMinimumConstraint("1.0.0", "foo");

// assert
expect(actual).to.be.false;
});

it("should return false when the candidate is not an improved major constraint", () => {
// act
let actual = helper.isImprovedMinimumConstraint("2.0.0", "1.0.0");

// assert
expect(actual).to.be.false;
});

it("should return false when the candidate is not an improved minor constraint", () => {
// act
let actual = helper.isImprovedMinimumConstraint("1.1.0", "1.0.0");

// assert
expect(actual).to.be.false;
});

it("should return false when the candidate is not an improved patch constraint", () => {
// act
let actual = helper.isImprovedMinimumConstraint("1.0.1", "1.0.0");

// assert
expect(actual).to.be.false;
});

it("should return true when the candidate is an improved major constraint", () => {
// act
let actual = helper.isImprovedMinimumConstraint("1.0.0", "2.0.0");

// assert
expect(actual).to.be.true;
});

it("should return true when the candidate is an improved minor constraint", () => {
// act
let actual = helper.isImprovedMinimumConstraint("1.0.0", "1.1.0");

// assert
expect(actual).to.be.true;
});

it("should return true when the candidate is an improved patch constraint", () => {
// act
let actual = helper.isImprovedMinimumConstraint("1.0.0", "1.0.1");

// assert
expect(actual).to.be.true;
});
});


describe("path", () => {
it("should return path starting in supplied directory", () => {
// arrange
Expand Down
5 changes: 1 addition & 4 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
{
"compilerOptions": {
"alwaysStrict": true,
"forceConsistentCasingInFileNames": true,
"module": "commonjs",
"moduleResolution": "node",
"noFallthroughCasesInSwitch": true,
"noImplicitAny": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noResolve": false,
"noUnusedLocals": true,
"noUnusedParameters": true,
"strictNullChecks": true,
"strict": true,
"target": "es5",
"sourceMap": true
},
Expand Down

0 comments on commit a9ff4f9

Please sign in to comment.