Skip to content

Commit

Permalink
Merge branch 'master' into chore/jest-26.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Vinnl committed May 19, 2020
2 parents d600d73 + 1967585 commit 477cf02
Show file tree
Hide file tree
Showing 15 changed files with 148 additions and 74 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**/*.snap
3 changes: 3 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@ module.exports = {
parserOptions: {
ecmaVersion: 2018,
sourceType: "module",
tsconfigRootDir: __dirname,
project: ["./tsconfig.json"],
},
plugins: ["@typescript-eslint"],
rules: {
// There's a TypeScript-specific version of this rule;
// we disable the generic one, because it thinks imported types are unused
// when they're not:
"no-unused-vars": "off",
"@typescript-eslint/no-floating-promises": "error",
},
};
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ jobs:
- run: npm ci
- run: npm run build
- run: npm test
- run: npm run e2e-test
- run: npx prettier --check "src/**"
# Prettier for some reason reports that the formatting is off on Windows.
# Since a single check is sufficient for code formatting, we skip it there:
Expand Down
2 changes: 2 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# We want to ignore compiled Javascript in .gitignore, but not when publishing to npm. Hence this file.
coverage
*.test.js
*.test.ts
26 changes: 14 additions & 12 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'jsdom',
preset: "ts-jest",
testEnvironment: "jsdom",
clearMocks: true,
collectCoverage: true,
coverageThreshold: {
"global": {
"branches": 100,
"functions": 100,
"lines": 100,
"statements": 100,
}
global: {
branches: 100,
functions: 100,
lines: 100,
statements: 100,
},
},
coveragePathIgnorePatterns: [
coveragePathIgnorePatterns: ["/node_modules/", "<rootDir>/dist"],
testPathIgnorePatterns: [
"/node_modules/",
"<rootDir>/dist"
]
};
// By default we only run unit tests:
"e2e.test.ts",
],
};
7 changes: 7 additions & 0 deletions jest.e2e.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* Config file to run just end-to-end tests */

module.exports = {
preset: "ts-jest",
clearMocks: true,
testRegex: "e2e.test.ts",
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "0.0.1",
"scripts": {
"test": "eslint --config .eslintrc.js \"src/**\" && jest",
"e2e-test": "jest --config=jest.e2e.config.js",
"build": "rollup --config rollup.config.js",
"prepublishOnly": "yarn run build"
},
Expand Down
15 changes: 15 additions & 0 deletions src/datatypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,21 @@ import { NamedNode, Literal, Quad } from "rdf-js";
import { DataFactory } from "./rdfjs";
import { IriString, LocalNode, Iri } from "./index";

/**
* IRIs of the XML Schema data types we support
* @internal
*/
export const xmlSchemaTypes = {
boolean: "http://www.w3.org/2001/XMLSchema#boolean",
dateTime: "http://www.w3.org/2001/XMLSchema#dateTime",
decimal: "http://www.w3.org/2001/XMLSchema#decimal",
integer: "http://www.w3.org/2001/XMLSchema#integer",
string: "http://www.w3.org/2001/XMLSchema#string",
langString: "http://www.w3.org/1999/02/22-rdf-syntax-ns#langString",
} as const;
/** @internal */
export type XmlSchemaTypeIri = typeof xmlSchemaTypes[keyof typeof xmlSchemaTypes];

/**
* @internal
* @param value Value to serialise.
Expand Down
50 changes: 50 additions & 0 deletions src/e2e.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import {
fetchLitDataset,
setThing,
getThingOne,
getStringUnlocalizedOne,
setDatetime,
setStringUnlocalized,
saveLitDatasetAt,
} from "./index";
import { foaf, schema } from "rdf-namespaces";

describe("End-to-end tests", () => {
it("should be able to read and update data in a Pod", async () => {
const randomNick = "Random nick " + Math.random();

const dataset = await fetchLitDataset(
"https://lit-e2e-test.inrupt.net/public/lit-solid-core-test.ttl"
);
const existingThing = getThingOne(
dataset,
"https://lit-e2e-test.inrupt.net/public/lit-solid-core-test.ttl#thing1"
);

expect(getStringUnlocalizedOne(existingThing, foaf.name)).toBe(
"Thing for first end-to-end test"
);

let updatedThing = setDatetime(
existingThing,
schema.dateModified,
new Date()
);
updatedThing = setStringUnlocalized(updatedThing, foaf.nick, randomNick);

const updatedDataset = setThing(dataset, updatedThing);
const savedDataset = await saveLitDatasetAt(
"https://lit-e2e-test.inrupt.net/public/lit-solid-core-test.ttl",
updatedDataset
);

const savedThing = getThingOne(
savedDataset,
"https://lit-e2e-test.inrupt.net/public/lit-solid-core-test.ttl#thing1"
);
expect(getStringUnlocalizedOne(savedThing, foaf.name)).toBe(
"Thing for first end-to-end test"
);
expect(getStringUnlocalizedOne(savedThing, foaf.nick)).toBe(randomNick);
});
});
19 changes: 8 additions & 11 deletions src/thing/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import {
serializeDecimal,
serializeInteger,
normalizeLocale,
XmlSchemaTypeIri,
xmlSchemaTypes,
} from "../datatypes";
import { DataFactory } from "../rdfjs";
import { Literal, NamedNode } from "rdf-js";
Expand Down Expand Up @@ -48,7 +50,7 @@ export const addBoolean: AddOfType<boolean> = (thing, predicate, value) => {
thing,
predicate,
serializeBoolean(value),
"http://www.w3.org/2001/XMLSchema#boolean"
xmlSchemaTypes.boolean
);
};

Expand All @@ -67,7 +69,7 @@ export const addDatetime: AddOfType<Date> = (thing, predicate, value) => {
thing,
predicate,
serializeDatetime(value),
"http://www.w3.org/2001/XMLSchema#dateTime"
xmlSchemaTypes.dateTime
);
};

Expand All @@ -86,7 +88,7 @@ export const addDecimal: AddOfType<number> = (thing, predicate, value) => {
thing,
predicate,
serializeDecimal(value),
"http://www.w3.org/2001/XMLSchema#decimal"
xmlSchemaTypes.decimal
);
};

Expand All @@ -105,7 +107,7 @@ export const addInteger: AddOfType<number> = (thing, predicate, value) => {
thing,
predicate,
serializeInteger(value),
"http://www.w3.org/2001/XMLSchema#integer"
xmlSchemaTypes.integer
);
};

Expand Down Expand Up @@ -151,12 +153,7 @@ export const addStringUnlocalized: AddOfType<string> = (
predicate,
value
) => {
return addLiteralOfType(
thing,
predicate,
value,
"http://www.w3.org/2001/XMLSchema#string"
);
return addLiteralOfType(thing, predicate, value, xmlSchemaTypes.string);
};

/**
Expand Down Expand Up @@ -219,7 +216,7 @@ function addLiteralOfType<T extends Thing>(
thing: T,
predicate: Iri | IriString,
value: string,
type: IriString
type: XmlSchemaTypeIri
): T extends ThingLocal ? ThingLocal : ThingPersisted;
function addLiteralOfType(
thing: Thing,
Expand Down
16 changes: 8 additions & 8 deletions src/thing/get.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1560,10 +1560,10 @@ describe("getLiteralAll", () => {
"https://some.vocab/predicate"
);
expect(foundLiterals.length).toBe(2);
expect((foundLiterals[0] as Literal).termType).toBe("Literal");
expect((foundLiterals[0] as Literal).value).toBe("Some string 1");
expect((foundLiterals[1] as Literal).termType).toBe("Literal");
expect((foundLiterals[1] as Literal).value).toBe("Some string 2");
expect(foundLiterals[0].termType).toBe("Literal");
expect(foundLiterals[0].value).toBe("Some string 1");
expect(foundLiterals[1].termType).toBe("Literal");
expect(foundLiterals[1].value).toBe("Some string 2");
});

it("accepts Predicates as Named Nodes", () => {
Expand All @@ -1579,10 +1579,10 @@ describe("getLiteralAll", () => {
DataFactory.namedNode("https://some.vocab/predicate")
);
expect(foundLiterals.length).toBe(2);
expect((foundLiterals[0] as Literal).termType).toBe("Literal");
expect((foundLiterals[0] as Literal).value).toBe("Some string 1");
expect((foundLiterals[1] as Literal).termType).toBe("Literal");
expect((foundLiterals[1] as Literal).value).toBe("Some string 2");
expect(foundLiterals[0].termType).toBe("Literal");
expect(foundLiterals[0].value).toBe("Some string 1");
expect(foundLiterals[1].termType).toBe("Literal");
expect(foundLiterals[1].value).toBe("Some string 2");
});

it("returns an empty array if no Literal values were found", () => {
Expand Down

0 comments on commit 477cf02

Please sign in to comment.