Skip to content

Commit 6eaeb45

Browse files
author
Fletcher91
committed
Fix jest typescript code coverage issues
Finally, it really helps if the output doesn't refer to transpiled lines which aren't stored on disk.
1 parent 930d916 commit 6eaeb45

File tree

9 files changed

+989
-864
lines changed

9 files changed

+989
-864
lines changed

babel.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
presets: [
3+
['@babel/preset-env', {targets: {node: 'current'}}],
4+
'@babel/preset-typescript',
5+
],
6+
};

package.json

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
},
3737
"peerDependencies": {
3838
"@ontologies/as": ">=1.0.1",
39-
"@ontologies/core": ">=2.0.0-7",
39+
"@ontologies/core": ">=2.0.0-9",
4040
"@ontologies/ld": ">=1.0.0",
4141
"@ontologies/schema": ">=1.0.0",
4242
"@ontologies/shacl": ">=1.0.0",
@@ -47,7 +47,7 @@
4747
"devDependencies": {
4848
"@ontola/memoized-hash-factory": "^2.0.0",
4949
"@ontologies/as": "^1.0.1",
50-
"@ontologies/core": "2.0.0-7",
50+
"@ontologies/core": "2.0.0-9",
5151
"@ontologies/dcterms": "^1.0.0",
5252
"@ontologies/ld": "^1.0.0",
5353
"@ontologies/owl": "^1.0.0",
@@ -62,21 +62,26 @@
6262
"@pika/plugin-bundle-web": "^0.8.1",
6363
"@pika/plugin-ts-standard-pkg": "^0.8.1",
6464
"@rdfdev/iri": "^1.0.0",
65-
"@types/jest": "^24.0.25",
65+
"@types/jest": "^25.1.4",
6666
"@types/murmurhash-js": "^1.0.3",
6767
"@types/node": "^12.11.2",
6868
"core-js": "^3.6.3",
6969
"esdoc": "^1.1.0",
7070
"gh-pages": "^2.2.0",
7171
"http-status-codes": ">= 1.x",
72-
"jest": "^24.9.0",
73-
"jest-fetch-mock": "^2.1.2",
72+
"jest": "^25.2.4",
73+
"jest-fetch-mock": "^3.0.3",
7474
"n-quads-parser": "^2.1.0-2",
7575
"ts-jest": "^24.3.0",
7676
"tslint": "^5.20.1",
7777
"typedoc": "^0.16.2",
7878
"typescript": "^3.7.4"
7979
},
80+
"babel": {
81+
"presets": [
82+
"@babel/preset-typescript"
83+
]
84+
},
8085
"jest": {
8186
"automock": false,
8287
"coveragePathIgnorePatterns": [
@@ -91,7 +96,6 @@
9196
"statements": 85
9297
}
9398
},
94-
"preset": "ts-jest",
9599
"setupFiles": [
96100
"core-js",
97101
"./jest-plugins"
@@ -103,9 +107,6 @@
103107
"js",
104108
"ts"
105109
],
106-
"testURL": "http://example.org/resources/5",
107-
"transform": {
108-
"\\.ts$": "ts-jest"
109-
}
110+
"testURL": "http://example.org/resources/5"
110111
}
111112
}

src/LinkedRenderStore.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ export class LinkedRenderStore<T> implements Dispatcher {
133133

134134
public get dispatch(): MiddlewareActionHandler {
135135
if (typeof this._dispatch === "undefined") {
136-
throw new Error("Invariant: cannot call `dispatch` before initialization is complete");
136+
throw new Error("Invariant: cannot call `dispatch` before initialization is complete, see createStore");
137137
}
138138

139139
return this._dispatch;

src/__tests__/LinkedRenderStore.spec.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,49 @@ import rdfFactory, { Quad } from "@ontologies/core";
55
import owl from "@ontologies/owl";
66
import rdf from "@ontologies/rdf";
77
import schema from "@ontologies/schema";
8+
import { LinkedRenderStore } from "../LinkedRenderStore";
89

910
import { getBasicStore } from "../testUtilities";
1011

1112
import { example } from "./LinkedRenderStore/fixtures";
1213

1314
describe("LinkedRenderStore", () => {
15+
describe("actions", () => {
16+
it("allows overriding dispach", () => {
17+
const dispatch = jest.fn();
18+
const lrs = new LinkedRenderStore({
19+
dispatch,
20+
});
21+
22+
expect(lrs.dispatch).toStrictEqual(dispatch);
23+
});
24+
25+
it ("prevents premature executions", () => {
26+
const lrs = new LinkedRenderStore();
27+
28+
expect(lrs.exec(rdf.type)).rejects.toBeInstanceOf(Error);
29+
});
30+
});
31+
32+
describe("data fetching", () => {
33+
it("allows data reload", async () => {
34+
const apiGetEntity = jest.fn();
35+
const iri = rdf.type;
36+
// @ts-ignore
37+
const store = getBasicStore({ api: { getEntity: apiGetEntity } });
38+
39+
await store.lrs.getEntity(iri, { reload: true });
40+
41+
expect(apiGetEntity).toHaveBeenCalledWith(
42+
iri,
43+
{
44+
clearPreviousData: true,
45+
force: true,
46+
},
47+
);
48+
});
49+
});
50+
1451
describe("reasons correctly", () => {
1552
it("combines sameAs declarations", async () => {
1653
const store = getBasicStore();

src/__tests__/LinkedRenderStore/delta.spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
11
import rdfFactory, { Quadruple } from "@ontologies/core";
22

33
import { getBasicStore } from "../../testUtilities";
4+
import { DeltaProcessor } from "../../types";
45

56
import { ex, ld } from "./fixtures";
67

78
describe("LinkedRenderStore", () => {
9+
describe("#addDeltaProcessor", () => {
10+
it ("adds the processor", () => {
11+
const processor = jest.fn();
12+
const { lrs } = getBasicStore();
13+
14+
lrs.addDeltaProcessor(processor as unknown as DeltaProcessor);
15+
expect(lrs.deltaProcessors).toContain(processor);
16+
});
17+
});
18+
819
describe("#queueDelta", () => {
920
const quadDelta = [
1021
[ex("1"), ex("p"), ex("2"), ld.add],

src/store/__tests__/deltaProcessor.spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,16 @@ describe("deltaProcessor", () => {
7777
expect((store as any).quads).toHaveLength(initialCount);
7878
});
7979

80+
it("requires explicit graph names", () => {
81+
expect(() => {
82+
deltaProcessor([], [], [], [], []);
83+
}).toThrow("Pass a default graph explicitly");
84+
});
85+
86+
it("ignores unknown methods", () => {
87+
testDelta([ [bob, schema.children, alice, ld.ns("unknown")] ], [0, 0, 0]);
88+
});
89+
8090
describe("with an existing value", () => {
8191
it("add", () => {
8292
testDelta([ [bob, schema.children, alice, ld.add] ], [1, 0, 0]);

src/utilities/__tests__/memoizedNamespace.spec.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,32 +9,44 @@ import { expandProperty } from "../memoizedNamespace";
99
describe("memoizedNamespace", () => {
1010
describe("expandProperty", () => {
1111
it("returns identity when passed undefined", () => {
12-
expect(expandProperty(undefined, {})).toBeUndefined();
12+
expect(expandProperty(undefined)).toBeUndefined();
1313
});
1414

1515
it("returns identity when passed NamedNode", () => {
1616
const n = rdfFactory.namedNode("http://example.com");
17-
expect(expandProperty(n, {})).toEqual(n);
17+
expect(expandProperty(n)).toEqual(n);
1818
});
1919

2020
it("returns a NamedNode when passed a plain NN object", () => {
2121
const n = {
2222
termType: "NamedNode",
2323
value: "http://example.com/ns#1",
2424
};
25-
expect(expandProperty(n, {})).toEqual(ex.ns("1"));
25+
expect(expandProperty(n)).toEqual(ex.ns("1"));
26+
});
27+
28+
it("returns a NamedNode when passed a plain NN object with prototype interface properties", () => {
29+
const proto = { termType: "NamedNode" };
30+
const n = Object.create(proto);
31+
n.value = "http://example.com/ns#1";
32+
33+
expect(expandProperty(n)).toEqual(ex.ns("1"));
2634
});
2735

2836
it("returns undefined when passed a random plain object", () => {
2937
const n = {
3038
termType: "Whatever",
3139
value: "http://example.com/ns#1",
3240
};
33-
expect(expandProperty((n as NamedNode), {})).toBeUndefined();
41+
expect(expandProperty((n as NamedNode))).toBeUndefined();
3442
});
3543

3644
it("parses url strings to NamedNodes", () => {
37-
expect(expandProperty("http://example.com/ns#1", {})).toEqual(ex.ns("1"));
45+
expect(expandProperty("http://example.com/ns#1")).toEqual(ex.ns("1"));
46+
});
47+
48+
it("parses n-quads formatted strings to NamedNodes", () => {
49+
expect(expandProperty("<http://example.com/ns#1>")).toEqual(ex.ns("1"));
3850
});
3951

4052
it("parses shorthand strings to NamedNodes", () => {

src/utilities/memoizedNamespace.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const CI_MATCH_SUFFIX = 1;
1414
* @returns The (expanded) property
1515
*/
1616
export function expandProperty(prop: NamedNode | Term | string | undefined,
17-
namespaces: NamespaceMap): NamedNode | undefined {
17+
namespaces: NamespaceMap = {}): NamedNode | undefined {
1818
if (!prop) {
1919
return prop as undefined;
2020
}

0 commit comments

Comments
 (0)