-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cbb720f
commit 5e9fffd
Showing
40 changed files
with
617 additions
and
272 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { Internal } from "@engine/components/internal.ts" | ||
import { expect, test } from "@utils/testing.ts" | ||
|
||
class InternalTest extends Internal { | ||
protected static readonly meta = import.meta | ||
constructor() { | ||
super(null as test) | ||
} | ||
} | ||
|
||
Deno.test("Internal()", { permissions: "none" }, () => { | ||
const internal = new InternalTest() | ||
expect(internal.id).to.equal("metrics/engine/components/internal_test.ts") | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { expect, MetricsError, test } from "@utils/testing.ts" | ||
import { is, Plugin } from "@engine/components/plugin.ts" | ||
import { config as schema } from "@engine/config.ts" | ||
import { config, getPermissions, setup } from "@engine/components/component_test.ts" | ||
import { deepMerge } from "std/collections/deep_merge.ts" | ||
import { process } from "@engine/process.ts" | ||
//import * as dir from "@engine/paths.ts" | ||
|
||
// TODO(@lowlighter): change to `[dir.source]` after https://github.com/denoland/deno_std/pull/3692 | ||
Deno.test("Plugin()", { permissions: { read: true } }, async (t) => { | ||
const { plugins: [context] } = schema.parse({ plugins: [{ id: "test", logs: "none", fatal: true, template: null, retries: { delay: 0 } }] }) as test | ||
class TestPlugin extends Plugin { | ||
static readonly meta = { url: "test" } as test | ||
readonly name = "⚗️ Test plugin" | ||
readonly category = "testing" | ||
readonly supports = ["user"] | ||
readonly description = "Test plugin" | ||
readonly inputs = is.object({}) | ||
readonly outputs = is.object({}) | ||
protected async action() {} | ||
async run() { | ||
const state = await Plugin.state.parseAsync({ results: [], errors: [] }) | ||
return super.run(state) | ||
} | ||
constructor(context: Plugin["context"]) { | ||
super(context) | ||
} | ||
} | ||
|
||
await t.step("tests() returns a list of tests", async () => { | ||
const plugin = new TestPlugin(context) | ||
await expect(plugin.tests()).to.eventually.be.an("array") | ||
}) | ||
|
||
await t.step("templates() returns a list of templates", async () => { | ||
const plugin = new TestPlugin(context) | ||
await expect(plugin.templates()).to.eventually.be.an("array") | ||
}) | ||
|
||
await t.step("supported()", async (t) => { | ||
await t.step("is a noop when entity is supported", async () => { | ||
const plugin = new TestPlugin({ ...context, entity: "user" }) | ||
await expect(plugin.run()).to.be.eventually.be.ok | ||
}) | ||
await t.step("throws if not supported", async () => { | ||
const plugin = new TestPlugin({ ...context, entity: "organization" }) | ||
await expect(plugin.run()).to.be.rejectedWith(MetricsError, /not supported for organization/i) | ||
}) | ||
}) | ||
}) | ||
|
||
for (const id of await Plugin.list()) { | ||
const plugin = await Plugin.load({ id }) | ||
const tests = await plugin.tests() | ||
const templates = await plugin.templates() | ||
const name = `${plugin.icon} plugins/${plugin.id}` | ||
if (!tests.length) { | ||
Deno.test.ignore(name, () => void null) | ||
continue | ||
} | ||
for (const test of tests) { | ||
Deno.test(`${name} | ${test.name}`, await getPermissions(test), async (t) => { | ||
const { teardown } = setup() | ||
for (const template of templates) { | ||
await t.step(template, async () => { | ||
await expect(process(deepMerge({ presets: { default: { plugins: { template } } } }, deepMerge(config, test, { arrays: "replace" })))).to.be.fulfilled.and.eventually.be.ok | ||
}) | ||
} | ||
teardown() | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { expect, MetricsError, test } from "@utils/testing.ts" | ||
import { Processor } from "@engine/components/processor.ts" | ||
import { config as schema } from "@engine/config.ts" | ||
import { config, getPermissions, setup } from "@engine/components/component_test.ts" | ||
import { deepMerge } from "std/collections/deep_merge.ts" | ||
import { process } from "@engine/process.ts" | ||
//import * as dir from "@engine/paths.ts" | ||
|
||
// TODO(@lowlighter): change to `[dir.source]` after https://github.com/denoland/deno_std/pull/3692 | ||
Deno.test("Processor()", { permissions: { read: true } }, async (t) => { | ||
const { plugins: [{ processors: [context] }] } = schema.parse({ plugins: [{ processors: [{ id: "test", logs: "none", fatal: true, retries: { delay: 0 } }] }] }) as test | ||
class TestProcessor extends Processor { | ||
static readonly meta = { url: "test" } as test | ||
readonly name = "⚗️ Test processor" | ||
readonly category = "testing" | ||
readonly supports = ["image/svg+xml"] | ||
readonly description = "Test processor" | ||
protected async action() {} | ||
async run({ mime }: test) { | ||
const state = await Processor.state.parseAsync({ result: { content: "", mime, base64: false, result: {} }, results: [], errors: [] }) | ||
return super.run(state) | ||
} | ||
constructor(context: Processor["context"]) { | ||
super(context) | ||
} | ||
} | ||
|
||
await t.step("tests() returns a list of tests", async () => { | ||
const plugin = new TestProcessor(context) | ||
await expect(plugin.tests()).to.eventually.be.an("array") | ||
}) | ||
|
||
await t.step("supported()", async (t) => { | ||
await t.step("is a noop when entity is supported", async () => { | ||
const plugin = new TestProcessor(context) | ||
await expect(plugin.run({ mime: "image/svg+xml" })).to.be.eventually.be.ok | ||
}) | ||
await t.step("throws if not supported", async () => { | ||
const plugin = new TestProcessor(context) | ||
await expect(plugin.run({ mime: "text/plain" })).to.be.rejectedWith(MetricsError, /not supported for text\/plain/i) | ||
}) | ||
}) | ||
}) | ||
|
||
for (const id of await Processor.list()) { | ||
const processor = await Processor.load({ id }) | ||
const tests = await processor.tests() | ||
const name = `${processor.icon} processors/${processor.id}` | ||
if (!tests.length) { | ||
Deno.test.ignore(name, () => void null) | ||
continue | ||
} | ||
for (const test of tests) { | ||
Deno.test(`${name} | ${test.name}`, await getPermissions(test), async () => { | ||
const { teardown } = setup() | ||
await expect(process(deepMerge(config, test, { arrays: "replace" }))).to.be.fulfilled.and.eventually.be.ok | ||
teardown() | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.