-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: remove json-parse-helpfulerror dev dep
- Loading branch information
Showing
10 changed files
with
131 additions
and
25 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ os: | |
- linux | ||
- osx | ||
|
||
osx_image: xcode7 | ||
osx_image: xcode7.3 | ||
|
||
dist: trusty | ||
sudo: required | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |