This repository has been archived by the owner on Aug 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix plugins not being found when no node_modules exists (#171)
* Implement test for plugin load This test should pass when it has been updated to use resolve * Update findRoot to use resolve function * Fix findRoot not working due to incorrect assumptions Assume resolve returns an entry file not a directory
- Loading branch information
Showing
5 changed files
with
98 additions
and
32 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import * as path from 'path' | ||
|
||
import {expect, fancy} from './test' | ||
import * as Plugin from '../src/plugin' | ||
import * as util from '../src/util' | ||
|
||
const root = path.resolve(__dirname, 'fixtures/typescript') | ||
const pluginName = '@oclif/plugin-help' | ||
const pluginLocation = 'some/external/directory' | ||
const pluginPjsonLocation = path.join(pluginLocation, 'package.json') | ||
|
||
const withPluginInstance = () => { | ||
return fancy | ||
.add('plugin', () => new Plugin.Plugin({ | ||
type: 'core', | ||
root, | ||
name: pluginName, | ||
ignoreManifest: true, | ||
})) | ||
.stub(util, 'exists', (checkPath: string) => checkPath === pluginPjsonLocation) | ||
.stub(util, 'resolvePackage', (id: string): Promise<string> => { | ||
if (id !== pluginName) { | ||
return Promise.reject() | ||
} | ||
return Promise.resolve(path.join(pluginLocation, 'lib', 'index.js')) | ||
}) | ||
.stub(util, 'loadJSON', (jsonPath: string) => { | ||
if (jsonPath !== pluginPjsonLocation) { | ||
return {} | ||
} | ||
return { | ||
name: pluginName, | ||
version: '1.0.0', | ||
files: [], | ||
oclif: {}, | ||
} | ||
}) | ||
} | ||
|
||
describe('Plugin', () => { | ||
withPluginInstance() | ||
.it('Should correctly instantiate a Plugin instance', ctx => { | ||
expect(ctx.plugin).to.be.instanceOf( | ||
Plugin.Plugin, | ||
'Expected instance to be an instance of Plugin!', | ||
) | ||
}) | ||
|
||
withPluginInstance() | ||
.it('Should correctly load a Plugin', async ctx => { | ||
await ctx.plugin.load() | ||
}) | ||
}) |
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