-
Notifications
You must be signed in to change notification settings - Fork 712
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resolves #1635
- Loading branch information
Showing
11 changed files
with
127 additions
and
13 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
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
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
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,93 @@ | ||
import { Project, tempdirProject } from "@typestrong/fs-fixture-builder"; | ||
import type { Application } from "../../index"; | ||
import { loadPlugins } from "../../lib/utils/plugins"; | ||
import { TestLogger } from "../TestLogger"; | ||
import { join, resolve } from "path"; | ||
|
||
describe("loadPlugins", () => { | ||
let project: Project; | ||
let logger: TestLogger; | ||
const fakeApp = {} as any as Application; | ||
beforeEach(() => { | ||
project = tempdirProject(); | ||
logger = fakeApp.logger = new TestLogger(); | ||
}); | ||
|
||
afterEach(() => { | ||
project.rm(); | ||
}); | ||
|
||
it("Should support loading a basic plugin", async () => { | ||
project.addJsonFile("package.json", { | ||
type: "commonjs", | ||
main: "index.js", | ||
}); | ||
project.addFile("index.js", "exports.load = function load() {}"); | ||
project.write(); | ||
|
||
const plugin = resolve(project.cwd); | ||
await loadPlugins(fakeApp, [plugin]); | ||
logger.expectMessage(`info: Loaded plugin ${plugin}`); | ||
}); | ||
|
||
it("Should support loading a ESM plugin", async () => { | ||
project.addJsonFile("package.json", { | ||
type: "module", | ||
main: "index.js", | ||
}); | ||
project.addFile("index.js", "export function load() {}"); | ||
project.write(); | ||
|
||
const plugin = join(resolve(project.cwd), "index.js"); | ||
await loadPlugins(fakeApp, [plugin]); | ||
logger.expectMessage(`info: Loaded plugin ${plugin}`); | ||
}); | ||
|
||
it("Should handle errors when requiring plugins", async () => { | ||
project.addJsonFile("package.json", { | ||
type: "commonjs", | ||
main: "index.js", | ||
}); | ||
project.addFile("index.js", "throw Error('bad')"); | ||
project.write(); | ||
|
||
const plugin = join(resolve(project.cwd), "index.js"); | ||
await loadPlugins(fakeApp, [plugin]); | ||
logger.expectMessage( | ||
`error: The plugin ${plugin} could not be loaded.` | ||
); | ||
}); | ||
|
||
it("Should handle errors when loading plugins", async () => { | ||
project.addJsonFile("package.json", { | ||
type: "commonjs", | ||
main: "index.js", | ||
}); | ||
project.addFile( | ||
"index.js", | ||
"exports.load = function load() { throw Error('bad') }" | ||
); | ||
project.write(); | ||
|
||
const plugin = join(resolve(project.cwd), "index.js"); | ||
await loadPlugins(fakeApp, [plugin]); | ||
logger.expectMessage( | ||
`error: The plugin ${plugin} could not be loaded.` | ||
); | ||
}); | ||
|
||
it("Should handle plugins without a load method", async () => { | ||
project.addJsonFile("package.json", { | ||
type: "commonjs", | ||
main: "index.js", | ||
}); | ||
project.addFile("index.js", ""); | ||
project.write(); | ||
|
||
const plugin = join(resolve(project.cwd), "index.js"); | ||
await loadPlugins(fakeApp, [plugin]); | ||
logger.expectMessage( | ||
`error: Invalid structure in plugin ${plugin}, no load function found.` | ||
); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "CommonJS", | ||
"module": "Node16", | ||
"lib": ["es2020"], | ||
"target": "es2020", | ||
|
||
|