Skip to content

Commit

Permalink
refactor: remove json-parse-helpfulerror dev dep
Browse files Browse the repository at this point in the history
  • Loading branch information
develar committed Jun 1, 2016
1 parent 1110596 commit e923e72
Show file tree
Hide file tree
Showing 10 changed files with 131 additions and 25 deletions.
1 change: 1 addition & 0 deletions .idea/dictionaries/develar.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ os:
- linux
- osx

osx_image: xcode7
osx_image: xcode7.3

dist: trusty
sudo: required
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,9 @@
"babel-plugin-transform-es2015-parameters": "^6.9.0",
"babel-plugin-transform-es2015-spread": "^6.8.0",
"decompress-zip": "^0.3.0",
"diff": "^2.2.3",
"electron-download": "^2.1.2",
"json-parse-helpfulerror": "^1.0.3",
"json8": "^0.9.0",
"path-sort": "^0.1.0",
"plist": "^1.2.0",
"pre-git": "^3.8.4",
Expand Down
4 changes: 4 additions & 0 deletions src/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,10 @@ export class Platform {
return this.name
}

toJSON() {
return this.name
}

public createTarget(type?: string | null, arch: Arch = archFromString(process.arch)): Map<Platform, Map<Arch, Array<string>>> {
return new Map([[this, new Map([[arch, type == null ? [] : [type]]])]])
}
Expand Down
18 changes: 9 additions & 9 deletions test/src/BuildTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { createYargs } from "out/cliOptions"
//noinspection JSUnusedLocalSymbols
const __awaiter = require("out/awaiter")

test("cli", (t) => {
test("cli", () => {
const yargs = createYargs()

const base = {
Expand All @@ -28,14 +28,14 @@ test("cli", (t) => {
return normalizeOptions(yargs.parse(input.split(" ")))
}

t.deepEqual(parse("--osx"), expected({targets: Platform.OSX.createTarget()}))
t.deepEqual(parse("--linux"), expected({targets: Platform.LINUX.createTarget()}))
t.deepEqual(parse("--win"), expected({targets: Platform.WINDOWS.createTarget()}))
t.deepEqual(parse("-owl"), expected({targets: createTargets([Platform.OSX, Platform.WINDOWS, Platform.LINUX])}))
t.deepEqual(parse("-l tar.gz:ia32"), expected({targets: Platform.LINUX.createTarget("tar.gz", Arch.ia32)}))
t.deepEqual(parse("-l tar.gz:x64"), expected({targets: Platform.LINUX.createTarget("tar.gz", Arch.x64)}))
t.deepEqual(parse("-l tar.gz"), expected({targets: Platform.LINUX.createTarget("tar.gz", archFromString(process.arch))}))
t.deepEqual(parse("-w tar.gz:x64"), expected({targets: Platform.WINDOWS.createTarget("tar.gz", Arch.x64)}))
assertThat(parse("--osx")).isEqualTo(expected({targets: Platform.OSX.createTarget()}))
assertThat(parse("--linux")).isEqualTo(expected({targets: Platform.LINUX.createTarget()}))
assertThat(parse("--win")).isEqualTo(expected({targets: Platform.WINDOWS.createTarget()}))
assertThat(parse("-owl")).isEqualTo(expected({targets: createTargets([Platform.OSX, Platform.WINDOWS, Platform.LINUX])}))
assertThat(parse("-l tar.gz:ia32")).isEqualTo(expected({targets: Platform.LINUX.createTarget("tar.gz", Arch.ia32)}))
assertThat(parse("-l tar.gz:x64")).isEqualTo(expected({targets: Platform.LINUX.createTarget("tar.gz", Arch.x64)}))
assertThat(parse("-l tar.gz")).isEqualTo(expected({targets: Platform.LINUX.createTarget("tar.gz", archFromString(process.arch))}))
assertThat(parse("-w tar.gz:x64")).isEqualTo(expected({targets: Platform.WINDOWS.createTarget("tar.gz", Arch.x64)}))
})

test("custom buildResources dir", () => assertPack("test-app-one", allPlatforms(), {
Expand Down
49 changes: 39 additions & 10 deletions test/src/helpers/fileAssert.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,68 @@
import { stat } from "fs-extra-p"
import * as json8 from "json8"
import { green, red, gray } from "chalk"
import { diffJson } from "diff"
import { AssertionError } from "assert"

//noinspection JSUnusedLocalSymbols
const __awaiter = require("out/awaiter")

// http://joel-costigliola.github.io/assertj/
export function assertThat(path: string) {
return new FileAssertions(path)
export function assertThat(actual: any): Assertions {
return new Assertions(actual)
}

class FileAssertions {
constructor (private path: string) {
function jsonReplacer(key: any, value: any): any {
if (value instanceof Map) {
return [...value]
}
return value === undefined ? undefined : value
}

class Assertions {
constructor (private actual: any) {
}

isEqualTo(expected: any) {
if (!json8.equal(this.actual, expected)) {
throw new AssertionError({
message: prettyDiff(JSON.parse(JSON.stringify(this.actual, jsonReplacer)), JSON.parse(JSON.stringify(expected, jsonReplacer)))
})
}
}

async isFile() {
const info = await stat(this.path)
const info = await stat(this.actual)
if (!info.isFile()) {
throw new Error(`Path ${this.path} is not a file`)
throw new Error(`Path ${this.actual} is not a file`)
}
}

async isDirectory() {
const info = await stat(this.path)
const info = await stat(this.actual)
if (!info.isDirectory()) {
throw new Error(`Path ${this.path} is not a directory`)
throw new Error(`Path ${this.actual} is not a directory`)
}
}

async doesNotExist() {
try {
await stat(this.path)
await stat(this.actual)
}
catch (e) {
return
}

throw new Error(`Path ${this.path} must not exist`)
throw new Error(`Path ${this.actual} must not exist`)
}
}

function prettyDiff(actual: any, expected: any): string {
const diffJson2 = diffJson(expected, actual)
const diff = diffJson2.map(part => {
if (part.added) return green(part.value.replace(/.+/g, ' - $&'))
if (part.removed) return red(part.value.replace(/.+/g, ' + $&'))
return gray(part.value.replace(/.+/g, ' | $&'))
}).join('')
return `\n${diff}\n`
}
3 changes: 2 additions & 1 deletion test/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
"../typings/signcode.d.ts",
"../typings/yargs.d.ts",
"typings/decompress-zip.d.ts",
"typings/json-parse-helpfulerror.d.ts",
"typings/diff.d.ts",
"typings/json8.d.ts",
"typings/path-sort.d.ts",
"typings/plist.d.ts",
"typings/should.d.ts",
Expand Down
69 changes: 69 additions & 0 deletions test/typings/diff.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// Generated by typings
// Source: https://raw.githubusercontent.com/typed-typings/npm-diff/9b748f41b48c9ddcca5c2a135edd57df25d578cd/lib/index.d.ts
declare module '~diff/lib/index' {
// Type definitions for diff
// Project: https://github.com/kpdecker/jsdiff
// Definitions by: vvakame <https://github.com/vvakame/>
// Definitions: https://github.com/borisyankov/DefinitelyTyped

module JsDiff {
interface IDiffResult {
value: string;
added?: boolean;
removed?: boolean;
}

interface IBestPath {
newPos: number;
componenets: IDiffResult[];
}

class Diff {
ignoreWhitespace:boolean;

constructor(ignoreWhitespace?:boolean);

diff(oldString:string, newString:string):IDiffResult[];

pushComponent(components:IDiffResult[], value:string, added:boolean, removed:boolean):void;

extractCommon(basePath:IBestPath, newString:string, oldString:string, diagonalPath:number):number;

equals(left:string, right:string):boolean;

join(left:string, right:string):string;

tokenize(value:string):any; // return types are string or string[]
}

function diffChars(oldStr:string, newStr:string):IDiffResult[];

function diffWords(oldStr:string, newStr:string):IDiffResult[];

function diffWordsWithSpace(oldStr:string, newStr:string):IDiffResult[];

function diffJson(oldObj: Object, newObj: Object): IDiffResult[];

function diffLines(oldStr:string, newStr:string):IDiffResult[];

function diffCss(oldStr:string, newStr:string):IDiffResult[];

function createPatch(fileName:string, oldStr:string, newStr:string, oldHeader:string, newHeader:string):string;

function applyPatch(oldStr:string, uniDiff:string):string;

function convertChangesToXML(changes:IDiffResult[]):string;

function convertChangesToDMP(changes:IDiffResult[]):{0: number; 1:string;}[];
}

export = JsDiff;
}
declare module 'diff/lib/index' {
import alias = require('~diff/lib/index');
export = alias;
}
declare module 'diff' {
import alias = require('~diff/lib/index');
export = alias;
}
3 changes: 0 additions & 3 deletions test/typings/json-parse-helpfulerror.d.ts

This file was deleted.

4 changes: 4 additions & 0 deletions test/typings/json8.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
declare module "json8" {
export function equal(a: any, b: any): boolean
export function serialize(value: any, options?: any): string
}

0 comments on commit e923e72

Please sign in to comment.