Commit d47c51e5 authored by Fabien Amarger's avatar Fabien Amarger
Browse files

feat: [prettier] Add prettier config

Copy from sparqlexplorer config
parent ed1f59eca44f
Pipeline #13913 passed with stages
in 1 minute and 56 seconds
......@@ -21,7 +21,7 @@ Deps:
Lint:
stage: lint
script:
- npm run linter
- npm run lint
Format:
stage: lint
......
tabWidth = 4
singleQuote = true
trailingComma = "es5"
bracketSpacing = false
{
"name": "@logilab/libview",
"version": "0.6.0",
"description": "Library for view specification and definition for a data browser.",
"repository": {
"type": "mercurial",
"url": "https://forge.extranet.logilab.fr/open-source/LDBrowser/libview"
},
"keywords": [
"DataBrowser",
"Typescript"
],
"files": [
"build"
],
"main": "./build/index.js",
"types": "./build/lib/index.d.ts",
"devDependencies": {
"@types/chai": "^4.1.7",
"@types/mocha": "^5.2.5",
"@types/rdflib": "^0.17.0",
"@types/xhr-mock": "^2.0.0",
"chai": "^4.2.0",
"copy-webpack-plugin": "^4.5.2",
"mocha": "^5.2.0",
"source-map-loader": "^0.2.3",
"tslint": "^5.11.0",
"ts-loader": "^4.4.2",
"ts-node": "^7.0.1",
"typedoc": "0.10.0",
"typescript": "^2.9.2",
"typescript-formatter": "^7.2.2",
"webpack": "^4.20.2",
"webpack-cli": "^3.1.1",
"xhr-mock": "^2.4.1"
},
"scripts": {
"clean": "rm -rf build",
"format:write": "tsfmt -r",
"format": "tsfmt --verify",
"linter": "tslint -p . -c tslint.json 'src/**/*.ts*'",
"build": "webpack",
"build:production": "NODE_ENV=production tsfmt --verify && tslint -p . -c tslint.json 'src/**/*.ts*' && webpack",
"prepublishOnly": "NODE_ENV=production webpack",
"test": "mocha --reporter spec --require ts-node/register src/**/*.test.ts",
"doc": "typedoc --mode modules --out build/docs --exclude '**/*.test.ts' 'src/'"
},
"author": "LOGILAB <contact@logilab.fr>",
"license": "LGPL-3.0"
"name": "@logilab/libview",
"version": "0.6.0",
"description": "Library for view specification and definition for a data browser.",
"repository": {
"type": "mercurial",
"url": "https://forge.extranet.logilab.fr/open-source/LDBrowser/libview"
},
"keywords": [
"DataBrowser",
"Typescript"
],
"files": [
"build"
],
"main": "./build/index.js",
"types": "./build/lib/index.d.ts",
"devDependencies": {
"@types/chai": "^4.1.7",
"@types/mocha": "^5.2.5",
"@types/rdflib": "^0.17.0",
"@types/xhr-mock": "^2.0.0",
"chai": "^4.2.0",
"copy-webpack-plugin": "^4.5.2",
"mocha": "^5.2.0",
"source-map-loader": "^0.2.3",
"tslint": "^5.11.0",
"ts-loader": "^4.4.2",
"ts-node": "^7.0.1",
"typedoc": "0.10.0",
"typescript": "^2.9.2",
"typescript-formatter": "^7.2.2",
"webpack": "^4.20.2",
"webpack-cli": "^3.1.1",
"xhr-mock": "^2.4.1"
},
"scripts": {
"clean": "rm -rf build",
"format": "npx prettier --check ./src/**/*.{jsx,tsx,ts,js,css}",
"lint": "npx tsc --noEmit",
"build": "webpack",
"build:production": "NODE_ENV=production tsfmt --verify && tslint -p . -c tslint.json 'src/**/*.ts*' && webpack",
"prepublishOnly": "NODE_ENV=production webpack",
"test": "mocha --reporter spec --require ts-node/register src/**/*.test.ts",
"doc": "typedoc --mode modules --out build/docs --exclude '**/*.test.ts' 'src/'"
},
"author": "LOGILAB <contact@logilab.fr>",
"license": "LGPL-3.0"
}
......@@ -19,262 +19,281 @@
******************************************************************************/
import {
serializableResult,
RenderingResult,
NO_LANGUAGE,
uriEquivalents,
newResourceFromUri,
cloneResource,
sameResources,
probeResourceWith,
Resource,
withTimeout
} from "./application";
serializableResult,
RenderingResult,
NO_LANGUAGE,
uriEquivalents,
newResourceFromUri,
cloneResource,
sameResources,
probeResourceWith,
Resource,
withTimeout,
} from './application';
import * as chai from "chai";
import { fail } from "assert";
import * as chai from 'chai';
const expect = chai.expect;
describe("@logilab/libview/application", () => {
it("should handle a promise that complete correctly", async () => {
let promise = new Promise<string>(
(resolve: (result: string) => void, reject: (reason: any) => void) => {
resolve("test");
}
);
let settled = false;
await withTimeout(promise, 100)
.then((value: string) => {
expect(value).equals("test");
settled = true;
})
.catch((reason: any) => {
fail("expected the promise to completed successfully");
});
expect(settled).equals(true);
});
const fail = chai.assert.fail;
it("should handle a promise that is rejected", async () => {
let promise = new Promise<string>(
(resolve: (result: string) => void, reject: (reason: any) => void) => {
reject("test");
}
);
let settled = false;
await withTimeout(promise, 100)
.then((value: string) => {
fail("expected the promise to be rejected");
})
.catch((reason: any) => {
expect(reason).equals("test");
settled = true;
});
expect(settled).equals(true);
});
describe('@logilab/libview/application', () => {
it('should handle a promise that complete correctly', async () => {
let promise = new Promise<string>(
(
resolve: (result: string) => void,
reject: (reason: any) => void
) => {
resolve('test');
}
);
let settled = false;
await withTimeout(promise, 100)
.then((value: string) => {
expect(value).equals('test');
settled = true;
})
.catch((reason: any) => {
fail('expected the promise to completed successfully');
});
expect(settled).equals(true);
});
it("should handle a promise that times out", async () => {
let promise = new Promise<string>(
(resolve: (result: string) => void, reject: (reason: any) => void) => {
// do nothing
}
);
let settled = false;
await withTimeout(promise, 100)
.then((value: string) => {
settled = true;
})
.catch((reason: any) => {
expect(reason).equals("timeout");
});
expect(settled).equals(false);
});
it('should handle a promise that is rejected', async () => {
let promise = new Promise<string>(
(
resolve: (result: string) => void,
reject: (reason: any) => void
) => {
reject('test');
}
);
let settled = false;
await withTimeout(promise, 100)
.then((value: string) => {
fail('expected the promise to be rejected');
})
.catch((reason: any) => {
expect(reason).equals('test');
settled = true;
});
expect(settled).equals(true);
});
it("should correctly compute equivalent URIs on simple URI", () => {
let original = "http://google.com/";
let equivalents = uriEquivalents(original);
expect(equivalents.length).equals(1);
expect(equivalents[0]).equals(original);
});
it('should handle a promise that times out', async () => {
let promise = new Promise<string>(
(
resolve: (result: string) => void,
reject: (reason: any) => void
) => {
// do nothing
}
);
let settled = false;
await withTimeout(promise, 100)
.then((value: string) => {
settled = true;
})
.catch((reason: any) => {
expect(reason).equals('timeout');
});
expect(settled).equals(false);
});
it("should correctly compute equivalent URIs with accented characters", () => {
let original = "http://dbpedia.org/resource/Paul_Valéry";
let expected = [
original,
"http://dbpedia.org/resource/Paul_Val\u00E9ry",
"http://dbpedia.org/resource/Paul_Val%C3%A9ry"
];
let equivalents = uriEquivalents(original);
expect(equivalents.length).equals(expected.length);
expected.forEach((e: string) => {
expect(equivalents).contains(e);
it('should correctly compute equivalent URIs on simple URI', () => {
let original = 'http://google.com/';
let equivalents = uriEquivalents(original);
expect(equivalents.length).equals(1);
expect(equivalents[0]).equals(original);
});
});
it("should correctly compute equivalent URIs for already unicode escaped strings", () => {
let original = "http://dbpedia.org/resource/Paul_Val\u00E9ry";
let expected = [
original,
"http://dbpedia.org/resource/Paul_Valéry",
"http://dbpedia.org/resource/Paul_Val%C3%A9ry"
];
let equivalents = uriEquivalents(original);
expect(equivalents.length).equals(expected.length);
expected.forEach((e: string) => {
expect(equivalents).contains(e);
it('should correctly compute equivalent URIs with accented characters', () => {
let original = 'http://dbpedia.org/resource/Paul_Valéry';
let expected = [
original,
'http://dbpedia.org/resource/Paul_Val\u00E9ry',
'http://dbpedia.org/resource/Paul_Val%C3%A9ry',
];
let equivalents = uriEquivalents(original);
expect(equivalents.length).equals(expected.length);
expected.forEach((e: string) => {
expect(equivalents).contains(e);
});
});
});
it("should correctly compute equivalent URIs for already percent encoded strings", () => {
let original = "http://dbpedia.org/resource/Paul_Val%C3%A9ry";
let expected = [
original,
"http://dbpedia.org/resource/Paul_Valéry",
"http://dbpedia.org/resource/Paul_Val\u00E9ry"
];
let equivalents = uriEquivalents(original);
expect(equivalents.length).equals(expected.length);
expected.forEach((e: string) => {
expect(equivalents).contains(e);
it('should correctly compute equivalent URIs for already unicode escaped strings', () => {
let original = 'http://dbpedia.org/resource/Paul_Val\u00E9ry';
let expected = [
original,
'http://dbpedia.org/resource/Paul_Valéry',
'http://dbpedia.org/resource/Paul_Val%C3%A9ry',
];
let equivalents = uriEquivalents(original);
expect(equivalents.length).equals(expected.length);
expected.forEach((e: string) => {
expect(equivalents).contains(e);
});
});
});
it("should fully clone resources", () => {
let original = "http://dbpedia.org/resource/Paul_Valéry";
let resource1 = newResourceFromUri(original);
let resource2 = cloneResource(resource1);
// modify resource 2
resource2.uri = "xxx";
resource2.uris.push("xxx");
expect(resource1.uri).equals(original);
expect(resource2.uris.length).equals(resource1.uris.length + 1);
});
it('should correctly compute equivalent URIs for already percent encoded strings', () => {
let original = 'http://dbpedia.org/resource/Paul_Val%C3%A9ry';
let expected = [
original,
'http://dbpedia.org/resource/Paul_Valéry',
'http://dbpedia.org/resource/Paul_Val\u00E9ry',
];
let equivalents = uriEquivalents(original);
expect(equivalents.length).equals(expected.length);
expected.forEach((e: string) => {
expect(equivalents).contains(e);
});
});
it('should fully clone resources', () => {
let original = 'http://dbpedia.org/resource/Paul_Valéry';
let resource1 = newResourceFromUri(original);
let resource2 = cloneResource(resource1);
// modify resource 2
resource2.uri = 'xxx';
resource2.uris.push('xxx');
expect(resource1.uri).equals(original);
expect(resource2.uris.length).equals(resource1.uris.length + 1);
});
it("should compare same resource with URIs in different order", () => {
let resource1 = newResourceFromUri(
"http://dbpedia.org/resource/Paul_Valéry"
);
let resource2 = newResourceFromUri(
"http://dbpedia.org/resource/Paul_Val%C3%A9ry"
);
expect(sameResources(resource1, resource2)).equals(true);
});
it('should compare same resource with URIs in different order', () => {
let resource1 = newResourceFromUri(
'http://dbpedia.org/resource/Paul_Valéry'
);
let resource2 = newResourceFromUri(
'http://dbpedia.org/resource/Paul_Val%C3%A9ry'
);
expect(sameResources(resource1, resource2)).equals(true);
});
it("should compare different resources", () => {
let resource1 = newResourceFromUri(
"http://dbpedia.org/resource/Paul_Valéry"
);
let resource2 = newResourceFromUri(
"http://dbpedia.org/resource/Paul_Valery"
);
expect(sameResources(resource1, resource2)).equals(false);
});
it('should compare different resources', () => {
let resource1 = newResourceFromUri(
'http://dbpedia.org/resource/Paul_Valéry'
);
let resource2 = newResourceFromUri(
'http://dbpedia.org/resource/Paul_Valery'
);
expect(sameResources(resource1, resource2)).equals(false);
});
it("should probe all URIs in a resource", async () => {
let resource = newResourceFromUri(
"http://dbpedia.org/resource/Paul_Valéry"
);
let probed: string[] = [];
let probe = function(uri: string): Promise<string> {
return new Promise<string>(
(resolve: (result: string) => void, reject: (reason: any) => void) => {
probed.push(uri);
resolve(uri);
}
);
};
await probeResourceWith(resource, probe)
.then((target: Resource) => {
expect(probed.length).equals(resource.uris.length);
resource.uris.forEach((uri: string) => {
expect(probed).contain(uri);
});
})
.catch((reason: any) => {
fail(reason);
});
});
it('should probe all URIs in a resource', async () => {
let resource = newResourceFromUri(
'http://dbpedia.org/resource/Paul_Valéry'
);
let probed: string[] = [];
let probe = function (uri: string): Promise<string> {
return new Promise<string>(
(
resolve: (result: string) => void,
reject: (reason: any) => void
) => {
probed.push(uri);
resolve(uri);
}
);
};
await probeResourceWith(resource, probe)
.then((target: Resource) => {
expect(probed.length).equals(resource.uris.length);
resource.uris.forEach((uri: string) => {
expect(probed).contain(uri);
});
})
.catch((reason: any) => {
fail(reason);
});
});
it("should only return successfully probed URIs", async () => {
let resource = {
uri: "http://example.com/a",
uris: [
"http://example.com/a",
"http://example.com/b",
"http://example.com/c"
]
};
let expected = ["http://example.com/b", "http://example.com/c"];
let probe = function(uri: string): Promise<string> {
return new Promise<string>(
(resolve: (result: string) => void, reject: (reason: any) => void) => {
if (uri === "http://example.com/a") {
reject("none");
} else {
resolve(uri);
}
}
);
};
await probeResourceWith(resource, probe)
.then((target: Resource) => {
expect(target.uris.length).equals(expected.length);
target.uris.forEach((uri: string) => {
expect(expected).contain(uri);
});
expect(target.uris).contains(target.uri);
expect(target.uris).does.not.contain("http://example.com/a");
})
.catch((reason: any) => {
fail(reason);
});
});
it('should only return successfully probed URIs', async () => {
let resource = {
uri: 'http://example.com/a',
uris: [
'http://example.com/a',
'http://example.com/b',
'http://example.com/c',
],
};
let expected = ['http://example.com/b', 'http://example.com/c'];
let probe = function (uri: string): Promise<string> {
return new Promise<string>(
(
resolve: (result: string) => void,
reject: (reason: any) => void
) => {
if (uri === 'http://example.com/a') {
reject('none');
} else {
resolve(uri);
}
}
);
};
await probeResourceWith(resource, probe)
.then((target: Resource) => {
expect(target.uris.length).equals(expected.length);
target.uris.forEach((uri: string) => {
expect(expected).contain(uri);
});
expect(target.uris).contains(target.uri);
expect(target.uris).does.not.contain('http://example.com/a');
})
.catch((reason: any) => {
fail(reason);
});
});
it("should use a timeout when probing URIs", async () => {
let resource = {
uri: "http://example.com/a",
uris: ["http://example.com/a", "http://example.com/b"]
};
let expected = ["http://example.com/a"];
let probe = function(uri: string): Promise<string> {
return new Promise<string>(
(resolve: (result: string) => void, reject: (reason: any) => void) => {
if (uri === "http://example.com/a") {
resolve("http://example.com/a");
}
}
);
};
await probeResourceWith(resource, probe)
.then((target: Resource) => {
expect(target.uris.length).equals(expected.length);
target.uris.forEach((uri: string) => {
expect(expected).contain(uri);
});
expect(target.uris).contains(target.uri);
})
.catch((reason: any) => {
fail(reason);
});
});
it('should use a timeout when probing URIs', async () => {
let resource = {
uri: 'http://example.com/a',
uris: ['http://example.com/a', 'http://example.com/b'],
};
let expected = ['http://example.com/a'];
let probe = function (uri: string): Promise<string> {
return new Promise<string>(
(
resolve: (result: string) => void,
reject: (reason: any) => void
) => {
if (uri === 'http://example.com/a') {
resolve('http://example.com/a');
}
}
);
};
await probeResourceWith(resource, probe)
.then((target: Resource) => {
expect(target.uris.length).equals(expected.length);
target.uris.forEach((uri: string) => {
expect(expected).contain(uri);
});
expect(target.uris).contains(target.uri);
})
.catch((reason: any) => {