Skip to content

Commit

Permalink
moar plugin tests
Browse files Browse the repository at this point in the history
  • Loading branch information
chris48s committed Aug 25, 2024
1 parent 3896d37 commit 521ece6
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
18 changes: 16 additions & 2 deletions src/plugins.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ describe("resolveUserPlugins", function () {
});

describe("parseInputFile", function () {
it("throws when parseInputFile returns unexpected type", async function () {
it("throws when parseInputFile returns unexpected object", async function () {
const plugins = await loadAllPlugins([
"../testfiles/plugins/bad-parse-method.js",
"../testfiles/plugins/bad-parse-method1.js",
]);
assert.throws(
() => parseFile(plugins.allLoadedPlugins, "{}", "foo.json", null),
Expand All @@ -99,4 +99,18 @@ describe("parseInputFile", function () {
},
);
});

it("throws when parseInputFile returns unexpected array", async function () {
const plugins = await loadAllPlugins([
"../testfiles/plugins/bad-parse-method2.js",
]);
assert.throws(
() => parseFile(plugins.allLoadedPlugins, "{}", "foo.json", null),
{
name: "Error",
message:
"Plugin v8r-plugin-test-bad-parse-method returned an unexpected type from parseInputFile hook. Expected Document, got string",
},
);
});
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BasePlugin } from "v8r";

export default class ValidTestPlugin extends BasePlugin {
export default class BadParseMethod1TestPlugin extends BasePlugin {
static name = "v8r-plugin-test-bad-parse-method";

// eslint-disable-next-line no-unused-vars
Expand Down
12 changes: 12 additions & 0 deletions testfiles/plugins/bad-parse-method2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { BasePlugin, Document } from "v8r";

export default class BadParseMethod2TestPlugin extends BasePlugin {
static name = "v8r-plugin-test-bad-parse-method";

// eslint-disable-next-line no-unused-vars
parseInputFile(contents, fileLocation, parser) {
// if we are returning an array
// all objects in the array should be a Document
return [new Document({}), "foobar"];
}
}

0 comments on commit 521ece6

Please sign in to comment.