1
- import * as assert from 'assert ' ;
1
+ import * as path from 'path ' ;
2
2
import * as sinon from 'sinon' ;
3
3
import * as ts from 'typescript' ;
4
4
import { InMemoryFileSystem } from '../memfs' ;
5
5
import { PluginLoader , PluginModule , PluginModuleFactory } from '../plugins' ;
6
6
import { InitializationOptions } from '../request-type' ;
7
+ import { path2uri } from '../util' ;
7
8
8
9
describe ( 'plugins' , ( ) => {
9
- describe ( 'constructor' , ( ) => {
10
- it ( 'should use defaults if no initializationOptions are provided' , ( ) => {
11
- const memfs = new InMemoryFileSystem ( '/' ) ;
12
-
13
- const loader = new PluginLoader ( '/' , memfs ) ;
14
- assert ( ! loader . allowLocalPluginLoads ) ;
15
- assert . equal ( loader . globalPlugins . length , 0 ) ;
16
- assert . equal ( loader . pluginProbeLocations . length , 0 ) ;
17
- } ) ;
18
- } ) ;
19
- describe ( 'loader' , ( ) => {
10
+ describe ( 'loadPlugins()' , ( ) => {
20
11
it ( 'should do nothing if no plugins are configured' , ( ) => {
21
12
const memfs = new InMemoryFileSystem ( '/' ) ;
22
13
@@ -29,16 +20,18 @@ describe('plugins', () => {
29
20
30
21
it ( 'should load a global plugin if specified' , ( ) => {
31
22
const memfs = new InMemoryFileSystem ( '/' ) ;
32
- memfs . add ( 'file:///Users/tomv/Projects/sourcegraph/node_modules/some-plugin/package.json' , '{ "name": "some-plugin", "version": "0.1.1", "main": "plugin.js"}' ) ;
33
- memfs . add ( 'file:///Users/tomv/Projects/sourcegraph/node_modules/some-plugin/plugin.js' , 'module.exports = function (modules) { return 5; };' ) ;
23
+ const peerPackagesPath = path . resolve ( __filename , '../../../../' ) ;
24
+ const peerPackagesUri = path2uri ( peerPackagesPath ) ;
25
+ memfs . add ( peerPackagesUri + '/node_modules/some-plugin/package.json' , '{ "name": "some-plugin", "version": "0.1.1", "main": "plugin.js"}' ) ;
26
+ memfs . add ( peerPackagesUri + '/node_modules/some-plugin/plugin.js' , '' ) ;
34
27
const initializationOptions : InitializationOptions = {
35
28
globalPlugins : [ 'some-plugin' ] ,
36
29
allowLocalPluginLoads : false ,
37
30
pluginProbeLocations : [ ]
38
31
} ;
39
32
const pluginFactoryFunc = ( modules : any ) => 5 ;
40
- const loader = new PluginLoader ( '/' , memfs , initializationOptions ) ;
41
- loader . require = ( path : string ) => pluginFactoryFunc ;
33
+ const fakeRequire = ( path : string ) => pluginFactoryFunc ;
34
+ const loader = new PluginLoader ( '/' , memfs , initializationOptions , undefined , fakeRequire ) ;
42
35
const compilerOptions : ts . CompilerOptions = { } ;
43
36
const applyProxy = sinon . spy ( ) ;
44
37
loader . loadPlugins ( compilerOptions , applyProxy ) ;
@@ -49,15 +42,15 @@ describe('plugins', () => {
49
42
it ( 'should load a local plugin if specified' , ( ) => {
50
43
const memfs = new InMemoryFileSystem ( '/some-project' ) ;
51
44
memfs . add ( 'file:///some-project/node_modules/some-plugin/package.json' , '{ "name": "some-plugin", "version": "0.1.1", "main": "plugin.js"}' ) ;
52
- memfs . add ( 'file:///some-project/node_modules/some-plugin/plugin.js' , 'module.exports = function (modules) { return 5; }; ' ) ;
45
+ memfs . add ( 'file:///some-project/node_modules/some-plugin/plugin.js' , '' ) ;
53
46
const initializationOptions : InitializationOptions = {
54
47
globalPlugins : [ ] ,
55
48
allowLocalPluginLoads : true ,
56
49
pluginProbeLocations : [ ]
57
50
} ;
58
51
const pluginFactoryFunc = ( modules : any ) => 5 ;
59
- const loader = new PluginLoader ( '/some-project' , memfs , initializationOptions ) ;
60
- loader . require = ( path : string ) => pluginFactoryFunc ;
52
+ const fakeRequire = ( path : string ) => pluginFactoryFunc ;
53
+ const loader = new PluginLoader ( '/some-project' , memfs , initializationOptions , undefined , fakeRequire ) ;
61
54
const pluginOption : ts . PluginImport = {
62
55
name : 'some-plugin'
63
56
} ;
@@ -67,7 +60,7 @@ describe('plugins', () => {
67
60
const applyProxy = sinon . spy ( ) ;
68
61
loader . loadPlugins ( compilerOptions , applyProxy ) ;
69
62
sinon . assert . calledOnce ( applyProxy ) ;
70
- sinon . assert . calledWithExactly ( applyProxy , pluginFactoryFunc , sinon . match ( { name : 'some-plugin' } ) ) ;
63
+ sinon . assert . calledWithExactly ( applyProxy , pluginFactoryFunc , sinon . match ( pluginOption ) ) ;
71
64
} ) ;
72
65
73
66
} ) ;
0 commit comments