Skip to content

Commit ea1f875

Browse files
committed
Merge branch 'main' into 1150-vitest-migration-from-service
2 parents 8e38584 + 93704e6 commit ea1f875

File tree

5 files changed

+112
-28
lines changed

5 files changed

+112
-28
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { PushActionPlugin } from '@finos/git-proxy/plugin';
2+
3+
// test default export (ESM syntax)
4+
export default new PushActionPlugin(async (req, action) => {
5+
console.log('Dummy plugin: ', action);
6+
return action;
7+
});
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { PushActionPlugin, PullActionPlugin } from '@finos/git-proxy/plugin';
2+
3+
// test multiple exports (ESM syntax)
4+
export default {
5+
foo: new PushActionPlugin(async (req, action) => {
6+
console.log('PushActionPlugin: ', action);
7+
return action;
8+
}),
9+
bar: new PullActionPlugin(async (req, action) => {
10+
console.log('PullActionPlugin: ', action);
11+
return action;
12+
}),
13+
baz: {
14+
exec: async (req, action) => {
15+
console.log('not a real plugin object');
16+
},
17+
},
18+
};
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { PushActionPlugin } from '@finos/git-proxy/plugin';
2+
3+
class DummyPlugin extends PushActionPlugin {
4+
constructor(exec) {
5+
super();
6+
this.exec = exec;
7+
}
8+
}
9+
10+
// test default export (ESM syntax)
11+
export default new DummyPlugin(async (req, action) => {
12+
console.log('Dummy plugin: ', action);
13+
return action;
14+
});

test/fixtures/test-package/multiple-export.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,9 @@ module.exports = {
99
console.log('PullActionPlugin: ', action);
1010
return action;
1111
}),
12+
baz: {
13+
exec: async (req, action) => {
14+
console.log('not a real plugin object');
15+
},
16+
},
1217
};

test/plugin/plugin.test.ts

Lines changed: 68 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,70 @@ describe('loading plugins from packages', () => {
1111
spawnSync('npm', ['install'], { cwd: testPackagePath, timeout: 5000 });
1212
});
1313

14-
it(
15-
'should load plugins that are the default export (module.exports = pluginObj)',
16-
async () => {
17-
const loader = new PluginLoader([join(testPackagePath, 'default-export.js')]);
18-
await loader.load();
19-
expect(loader.pushPlugins.length).toBe(1);
20-
expect(loader.pushPlugins.every((p) => isCompatiblePlugin(p))).toBe(true);
21-
expect(
22-
loader.pushPlugins.every((p) => isCompatiblePlugin(p, 'isGitProxyPushActionPlugin')),
23-
).toBe(true);
24-
},
25-
{ timeout: 10000 },
26-
);
14+
describe('CommonJS syntax', () => {
15+
it(
16+
'should load plugins that are the default export (module.exports = pluginObj)',
17+
async () => {
18+
const loader = new PluginLoader([join(testPackagePath, 'default-export.js')]);
19+
await loader.load();
20+
expect(loader.pushPlugins.length).toBe(1);
21+
expect(loader.pushPlugins.every((p) => isCompatiblePlugin(p))).toBe(true);
22+
expect(
23+
loader.pushPlugins.every((p) => isCompatiblePlugin(p, 'isGitProxyPushActionPlugin')),
24+
).toBe(true);
25+
},
26+
{ timeout: 10000 },
27+
);
2728

28-
it(
29-
'should load multiple plugins from a module that match the plugin class (module.exports = { pluginFoo, pluginBar })',
30-
async () => {
31-
const loader = new PluginLoader([join(testPackagePath, 'multiple-export.js')]);
29+
it(
30+
'should load multiple plugins from a module that match the plugin class (module.exports = { pluginFoo, pluginBar })',
31+
async () => {
32+
const loader = new PluginLoader([join(testPackagePath, 'multiple-export.js')]);
33+
await loader.load();
34+
expect(loader.pushPlugins.length).toBe(1);
35+
expect(loader.pullPlugins.length).toBe(1);
36+
expect(loader.pushPlugins.every((p) => isCompatiblePlugin(p))).toBe(true);
37+
expect(
38+
loader.pushPlugins.every((p) => isCompatiblePlugin(p, 'isGitProxyPushActionPlugin')),
39+
).toBe(true);
40+
expect(
41+
loader.pullPlugins.every((p) => isCompatiblePlugin(p, 'isGitProxyPullActionPlugin')),
42+
).toBe(true);
43+
},
44+
{ timeout: 10000 },
45+
);
46+
47+
it(
48+
'should load plugins that are subclassed from plugin classes',
49+
async () => {
50+
const loader = new PluginLoader([join(testPackagePath, 'subclass.js')]);
51+
await loader.load();
52+
expect(loader.pushPlugins.length).toBe(1);
53+
expect(loader.pushPlugins.every((p) => isCompatiblePlugin(p))).toBe(true);
54+
expect(
55+
loader.pushPlugins.every((p) => isCompatiblePlugin(p, 'isGitProxyPushActionPlugin')),
56+
).toBe(true);
57+
},
58+
{ timeout: 10000 },
59+
);
60+
});
61+
62+
describe('ESM syntax', () => {
63+
it(
64+
'should load plugins that are the default export (exports default pluginObj)',
65+
async () => {
66+
const loader = new PluginLoader([join(testPackagePath, 'esm-export.js')]);
67+
await loader.load();
68+
expect(loader.pushPlugins.length).toBe(1);
69+
expect(loader.pushPlugins.every((p) => isCompatiblePlugin(p))).toBe(true);
70+
expect(
71+
loader.pushPlugins.every((p) => isCompatiblePlugin(p, 'isGitProxyPushActionPlugin')),
72+
).toBe(true);
73+
},
74+
{ timeout: 10000 },
75+
);
76+
it('should load multiple plugins from a module that match the plugin class (exports default { pluginFoo, pluginBar })', async () => {
77+
const loader = new PluginLoader([join(testPackagePath, 'esm-multiple-export.js')]);
3278
await loader.load();
3379
expect(loader.pushPlugins.length).toBe(1);
3480
expect(loader.pullPlugins.length).toBe(1);
@@ -39,23 +85,17 @@ describe('loading plugins from packages', () => {
3985
expect(
4086
loader.pullPlugins.every((p) => isCompatiblePlugin(p, 'isGitProxyPullActionPlugin')),
4187
).toBe(true);
42-
},
43-
{ timeout: 10000 },
44-
);
45-
46-
it(
47-
'should load plugins that are subclassed from plugin classes',
48-
async () => {
49-
const loader = new PluginLoader([join(testPackagePath, 'subclass.js')]);
88+
});
89+
it('should load plugins that are subclassed from plugin classes (exports default class DummyPlugin extends PushActionPlugin {})', async () => {
90+
const loader = new PluginLoader([join(testPackagePath, 'esm-subclass.js')]);
5091
await loader.load();
5192
expect(loader.pushPlugins.length).toBe(1);
5293
expect(loader.pushPlugins.every((p) => isCompatiblePlugin(p))).toBe(true);
5394
expect(
5495
loader.pushPlugins.every((p) => isCompatiblePlugin(p, 'isGitProxyPushActionPlugin')),
5596
).toBe(true);
56-
},
57-
{ timeout: 10000 },
58-
);
97+
});
98+
});
5999

60100
it(
61101
'should not load plugins that are not valid modules',

0 commit comments

Comments
 (0)