Skip to content

Commit

Permalink
fix: no need to make resulting function async
Browse files Browse the repository at this point in the history
  • Loading branch information
jenspots committed Apr 7, 2024
1 parent 7ddfa18 commit 634b681
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
6 changes: 2 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ type ValidateArguments = {
validationIsFatal?: boolean;
};

export async function validate(
args: ValidateArguments,
): Promise<() => Promise<void>> {
export async function validate(args: ValidateArguments): Promise<() => void> {
const { shaclPath, incoming, outgoing, report, validationIsFatal } = args;

// Initialize the shared serializer.
Expand All @@ -42,7 +40,7 @@ export async function validate(
// @ts-expect-error Factory is valid.
const validator = new Validator(shapes, { factory: rdf });

return async () => {
return () => {
// Anything that passes through this processor and identifies with a
// specific shape should match the SHACL definition.
incoming.on("data", async (data) => {
Expand Down
21 changes: 11 additions & 10 deletions tests/error.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ describe("errors", () => {
test("invalid shacl file path", async () => {
expect.assertions(1);

const func = validate({
shaclPath: "/tmp/shacl-doesnt-exist.ttl",
incoming: new SimpleStream<string>(),
outgoing: new SimpleStream<string>(),
});

expect(func).rejects.toThrow(ShaclError.fileSystemError());
const func = () =>
validate({
shaclPath: "/tmp/shacl-doesnt-exist.ttl",
incoming: new SimpleStream<string>(),
outgoing: new SimpleStream<string>(),
});

expect(func()).rejects.toThrow(ShaclError.fileSystemError());
});

test("invalid shacl rdf format", async () => {
Expand All @@ -30,7 +31,7 @@ describe("errors", () => {
outgoing: new SimpleStream<string>(),
});

expect(func).rejects.toThrow(ShaclError.invalidRdfFormat());
expect(func).rejects.toThrowError(ShaclError.invalidRdfFormat());
});

test("invalid input data", async () => {
Expand All @@ -44,7 +45,7 @@ describe("errors", () => {
incoming,
outgoing,
});
await func();
func();

expect(
incoming.push("This is not a valid Turtle file!"),
Expand All @@ -65,7 +66,7 @@ describe("errors", () => {
outgoing: new SimpleStream<string>(),
validationIsFatal: true,
});
await func();
func();

expect(incoming.push(invalidRdfData)).rejects.toThrow(
ShaclError.validationFailed(),
Expand Down
2 changes: 1 addition & 1 deletion tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ beforeEach(async () => {
outgoing,
report,
});
await func();
func();
});

describe("shacl", () => {
Expand Down

0 comments on commit 634b681

Please sign in to comment.