From 6850a8c56a0b17474985ef662f3f98fc2622893b Mon Sep 17 00:00:00 2001 From: bja Date: Sun, 5 Nov 2017 18:16:49 +0000 Subject: [PATCH 1/4] Improves checking for dependencies to check for difference in minimum constraint --- lib/builder.ts | 8 +-- lib/elm-package-helper.ts | 19 ++++++ test/unit/lib/builder.test.ts | 24 +++++++- test/unit/lib/elm-package-helper.test.ts | 75 ++++++++++++++++++++++++ 4 files changed, 121 insertions(+), 5 deletions(-) diff --git a/lib/builder.ts b/lib/builder.ts index 9e25f97..5eaf1b3 100644 --- a/lib/builder.ts +++ b/lib/builder.ts @@ -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); @@ -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) { @@ -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]); }); } diff --git a/lib/elm-package-helper.ts b/lib/elm-package-helper.ts index 7943949..19f5889 100644 --- a/lib/elm-package-helper.ts +++ b/lib/elm-package-helper.ts @@ -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; @@ -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"); } diff --git a/test/unit/lib/builder.test.ts b/test/unit/lib/builder.test.ts index 52df7e5..5148b8e 100644 --- a/test/unit/lib/builder.test.ts +++ b/test/unit/lib/builder.test.ts @@ -36,7 +36,7 @@ describe("lib builder", () => { mockLogger.error = Sinon.spy(); mockLogger.info = Sinon.spy(); mockLogger.trace = Sinon.spy(); - mockHelper = {path: x => x, read: Sinon.stub(), write: Sinon.stub()}; + mockHelper = {isImprovedMinimumConstraint: Sinon.stub(), path: x => x, read: Sinon.stub(), write: Sinon.stub()}; mockUtil = {}; mockUtil.resolveDir = Sinon.spy(); builder = new rewiredImp(mockHelper, mockLogger, mockUtil); @@ -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", () => { diff --git a/test/unit/lib/elm-package-helper.test.ts b/test/unit/lib/elm-package-helper.test.ts index 533fd65..373ac16 100644 --- a/test/unit/lib/elm-package-helper.test.ts +++ b/test/unit/lib/elm-package-helper.test.ts @@ -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 From f6e457e506a06b223bc7c61ca8e0aa780e2dd74c Mon Sep 17 00:00:00 2001 From: bja Date: Sun, 5 Nov 2017 18:38:54 +0000 Subject: [PATCH 2/4] Updates dependencies, typescript to 2.6.1 --- lib/builder.ts | 4 ++-- lib/plugin.ts | 4 +++- package.json | 10 +++++----- tsconfig.json | 5 +---- 4 files changed, 11 insertions(+), 12 deletions(-) diff --git a/lib/builder.ts b/lib/builder.ts index 5eaf1b3..a2afc48 100644 --- a/lib/builder.ts +++ b/lib/builder.ts @@ -90,14 +90,14 @@ export class BuilderImp implements Builder { } public syncTestElmPackage(config: LoboConfig, baseElmPackageDir: string, testElmPackageDir: string, testDir: string): Bluebird { - let steps: Array<(result?: ElmPackageCompare) => Bluebird> = [() => this.readElmPackage(baseElmPackageDir, testElmPackageDir), + let steps: Array<(result: ElmPackageCompare) => Bluebird> = [() => 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) => item(value) + return Bluebird.mapSeries(steps, (item: (result: ElmPackageCompare) => Bluebird) => item(value) .then((result: ElmPackageCompare) => value = result)); } diff --git a/lib/plugin.ts b/lib/plugin.ts index 7ad43ba..823bc5b 100644 --- a/lib/plugin.ts +++ b/lib/plugin.ts @@ -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 { diff --git a/package.json b/package.json index 6a63734..4d149fe 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "lobo", - "version": "0.3.3", + "version": "0.4.0", "description": "Elm test runner", "keywords": [ "elm", @@ -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", @@ -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": [ diff --git a/tsconfig.json b/tsconfig.json index 1d1f0f6..88da970 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -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 }, From 23cf1ed44a9c756aaf53d8d4485ac646bc0ca1af Mon Sep 17 00:00:00 2001 From: bja Date: Sun, 5 Nov 2017 18:49:26 +0000 Subject: [PATCH 3/4] Adds nodejs builds for v8, v9 --- .travis.yml | 1 + appveyor.yml | 1 + 2 files changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index a35fccc..55785a5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,7 @@ language: node_js node_js: - "6" + - "8" cache: directories: diff --git a/appveyor.yml b/appveyor.yml index 203b79a..94b71b3 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -2,6 +2,7 @@ environment: ELM_VERSION: "0.18.0" matrix: - nodejs_version: "4" + - nodejs_version: "Stable" platform: - x64 From fec27f6adfc535271bbb0f709c15060fe3878fc4 Mon Sep 17 00:00:00 2001 From: bja Date: Sun, 5 Nov 2017 19:02:39 +0000 Subject: [PATCH 4/4] Updates appveyor to not use Stable alias --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index 94b71b3..f9398e9 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -2,7 +2,7 @@ environment: ELM_VERSION: "0.18.0" matrix: - nodejs_version: "4" - - nodejs_version: "Stable" + - nodejs_version: "9" platform: - x64