@@ -2,12 +2,7 @@ import chai from 'chai';
22import { spawnSync } from 'child_process' ;
33import { rmSync } from 'fs' ;
44import { join } from 'path' ;
5- import {
6- isCompatiblePlugin ,
7- PullActionPlugin ,
8- PushActionPlugin ,
9- PluginLoader ,
10- } from '../../src/plugin.ts' ;
5+ import { isCompatiblePlugin , PushActionPlugin , PluginLoader } from '../../src/plugin.ts' ;
116
127chai . should ( ) ;
138
@@ -22,35 +17,73 @@ describe('loading plugins from packages', function () {
2217 spawnSync ( 'npm' , [ 'install' ] , { cwd : testPackagePath , timeout : 5000 } ) ;
2318 } ) ;
2419
25- it ( 'should load plugins that are the default export (module.exports = pluginObj)' , async function ( ) {
26- const loader = new PluginLoader ( [ join ( testPackagePath , 'default-export.js' ) ] ) ;
27- await loader . load ( ) ;
28- expect ( loader . pushPlugins . length ) . to . equal ( 1 ) ;
29- expect ( loader . pushPlugins . every ( ( p ) => isCompatiblePlugin ( p ) ) ) . to . be . true ;
30- expect ( loader . pushPlugins . every ( ( p ) => isCompatiblePlugin ( p , 'isGitProxyPushActionPlugin' ) ) ) . to
31- . be . true ;
32- } ) . timeout ( 10000 ) ;
20+ describe ( 'CommonJS syntax' , ( ) => {
21+ it ( 'should load plugins that are the default export (module.exports = pluginObj)' , async function ( ) {
22+ const loader = new PluginLoader ( [ join ( testPackagePath , 'default-export.js' ) ] ) ;
23+ await loader . load ( ) ;
24+ expect ( loader . pushPlugins . length ) . to . equal ( 1 ) ;
25+ expect ( loader . pushPlugins . every ( ( p ) => isCompatiblePlugin ( p ) ) ) . to . be . true ;
26+ expect ( loader . pushPlugins . every ( ( p ) => isCompatiblePlugin ( p , 'isGitProxyPushActionPlugin' ) ) )
27+ . to . be . true ;
28+ } ) . timeout ( 10000 ) ;
3329
34- it ( 'should load multiple plugins from a module that match the plugin class (module.exports = { pluginFoo, pluginBar })' , async function ( ) {
35- const loader = new PluginLoader ( [ join ( testPackagePath , 'multiple-export.js' ) ] ) ;
36- await loader . load ( ) ;
37- expect ( loader . pushPlugins . length ) . to . equal ( 1 ) ;
38- expect ( loader . pullPlugins . length ) . to . equal ( 1 ) ;
39- expect ( loader . pushPlugins . every ( ( p ) => isCompatiblePlugin ( p ) ) ) . to . be . true ;
40- expect ( loader . pushPlugins . every ( ( p ) => isCompatiblePlugin ( p , 'isGitProxyPushActionPlugin' ) ) ) . to
41- . be . true ;
42- expect ( loader . pullPlugins . every ( ( p ) => isCompatiblePlugin ( p , 'isGitProxyPullActionPlugin' ) ) ) . to
43- . be . true ;
44- } ) . timeout ( 10000 ) ;
30+ it ( 'should load multiple plugins from a module that match the plugin class (module.exports = { pluginFoo, pluginBar })' , async function ( ) {
31+ const loader = new PluginLoader ( [ join ( testPackagePath , 'multiple-export.js' ) ] ) ;
32+ await loader . load ( ) ;
4533
46- it ( 'should load plugins that are subclassed from plugin classes' , async function ( ) {
47- const loader = new PluginLoader ( [ join ( testPackagePath , 'subclass.js' ) ] ) ;
48- await loader . load ( ) ;
49- expect ( loader . pushPlugins . length ) . to . equal ( 1 ) ;
50- expect ( loader . pushPlugins . every ( ( p ) => isCompatiblePlugin ( p ) ) ) . to . be . true ;
51- expect ( loader . pushPlugins . every ( ( p ) => isCompatiblePlugin ( p , 'isGitProxyPushActionPlugin' ) ) ) . to
52- . be . true ;
53- } ) . timeout ( 10000 ) ;
34+ // Should load the foo and bar plugins, but not the baz object which isn't a plugin
35+ expect ( loader . pushPlugins . length ) . to . equal ( 1 ) ;
36+ expect ( loader . pullPlugins . length ) . to . equal ( 1 ) ;
37+ expect ( loader . pushPlugins . every ( ( p ) => isCompatiblePlugin ( p ) ) ) . to . be . true ;
38+ expect ( loader . pushPlugins . every ( ( p ) => isCompatiblePlugin ( p , 'isGitProxyPushActionPlugin' ) ) )
39+ . to . be . true ;
40+ expect ( loader . pullPlugins . every ( ( p ) => isCompatiblePlugin ( p , 'isGitProxyPullActionPlugin' ) ) )
41+ . to . be . true ;
42+ } ) . timeout ( 10000 ) ;
43+
44+ it ( 'should load plugins that are subclassed from plugin classes' , async function ( ) {
45+ const loader = new PluginLoader ( [ join ( testPackagePath , 'subclass.js' ) ] ) ;
46+ await loader . load ( ) ;
47+ expect ( loader . pushPlugins . length ) . to . equal ( 1 ) ;
48+ expect ( loader . pushPlugins . every ( ( p ) => isCompatiblePlugin ( p ) ) ) . to . be . true ;
49+ expect ( loader . pushPlugins . every ( ( p ) => isCompatiblePlugin ( p , 'isGitProxyPushActionPlugin' ) ) )
50+ . to . be . true ;
51+ } ) . timeout ( 10000 ) ;
52+ } ) ;
53+
54+ describe ( 'ESM syntax' , ( ) => {
55+ it ( 'should load plugins that are the default export (exports default pluginObj)' , async function ( ) {
56+ const loader = new PluginLoader ( [ join ( testPackagePath , 'esm-export.js' ) ] ) ;
57+ await loader . load ( ) ;
58+ expect ( loader . pushPlugins . length ) . to . equal ( 1 ) ;
59+ expect ( loader . pushPlugins . every ( ( p ) => isCompatiblePlugin ( p ) ) ) . to . be . true ;
60+ expect ( loader . pushPlugins . every ( ( p ) => isCompatiblePlugin ( p , 'isGitProxyPushActionPlugin' ) ) )
61+ . to . be . true ;
62+ } ) . timeout ( 10000 ) ;
63+
64+ it ( 'should load multiple plugins from a module that match the plugin class (exports default { pluginFoo, pluginBar })' , async function ( ) {
65+ const loader = new PluginLoader ( [ join ( testPackagePath , 'esm-multiple-export.js' ) ] ) ;
66+ await loader . load ( ) ;
67+
68+ // Should load the foo and bar plugins, but not the baz object which isn't a plugin
69+ expect ( loader . pushPlugins . length ) . to . equal ( 1 ) ;
70+ expect ( loader . pullPlugins . length ) . to . equal ( 1 ) ;
71+ expect ( loader . pushPlugins . every ( ( p ) => isCompatiblePlugin ( p ) ) ) . to . be . true ;
72+ expect ( loader . pushPlugins . every ( ( p ) => isCompatiblePlugin ( p , 'isGitProxyPushActionPlugin' ) ) )
73+ . to . be . true ;
74+ expect ( loader . pullPlugins . every ( ( p ) => isCompatiblePlugin ( p , 'isGitProxyPullActionPlugin' ) ) )
75+ . to . be . true ;
76+ } ) . timeout ( 10000 ) ;
77+
78+ it ( 'should load plugins that are subclassed from plugin classes (exports default class DummyPlugin extends PushActionPlugin {})' , async function ( ) {
79+ const loader = new PluginLoader ( [ join ( testPackagePath , 'esm-subclass.js' ) ] ) ;
80+ await loader . load ( ) ;
81+ expect ( loader . pushPlugins . length ) . to . equal ( 1 ) ;
82+ expect ( loader . pushPlugins . every ( ( p ) => isCompatiblePlugin ( p ) ) ) . to . be . true ;
83+ expect ( loader . pushPlugins . every ( ( p ) => isCompatiblePlugin ( p , 'isGitProxyPushActionPlugin' ) ) )
84+ . to . be . true ;
85+ } ) . timeout ( 10000 ) ;
86+ } ) ;
5487
5588 it ( 'should not load plugins that are not valid modules' , async function ( ) {
5689 const loader = new PluginLoader ( [ join ( __dirname , './dummy.js' ) ] ) ;
0 commit comments