Skip to content

Commit 282b1f4

Browse files
committed
test: add esm plugin tests
1 parent bf57a27 commit 282b1f4

File tree

1 file changed

+62
-33
lines changed

1 file changed

+62
-33
lines changed

test/plugin/plugin.test.js

Lines changed: 62 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,7 @@ import chai from 'chai';
22
import { spawnSync } from 'child_process';
33
import { rmSync } from 'fs';
44
import { 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

127
chai.should();
138

@@ -22,35 +17,69 @@ 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();
33+
expect(loader.pushPlugins.length).to.equal(1);
34+
expect(loader.pullPlugins.length).to.equal(1);
35+
expect(loader.pushPlugins.every((p) => isCompatiblePlugin(p))).to.be.true;
36+
expect(loader.pushPlugins.every((p) => isCompatiblePlugin(p, 'isGitProxyPushActionPlugin')))
37+
.to.be.true;
38+
expect(loader.pullPlugins.every((p) => isCompatiblePlugin(p, 'isGitProxyPullActionPlugin')))
39+
.to.be.true;
40+
}).timeout(10000);
4541

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);
42+
it('should load plugins that are subclassed from plugin classes', async function () {
43+
const loader = new PluginLoader([join(testPackagePath, 'subclass.js')]);
44+
await loader.load();
45+
expect(loader.pushPlugins.length).to.equal(1);
46+
expect(loader.pushPlugins.every((p) => isCompatiblePlugin(p))).to.be.true;
47+
expect(loader.pushPlugins.every((p) => isCompatiblePlugin(p, 'isGitProxyPushActionPlugin')))
48+
.to.be.true;
49+
}).timeout(10000);
50+
});
51+
52+
describe('ESM syntax', () => {
53+
it('should load plugins that are the default export (exports default pluginObj)', async function () {
54+
const loader = new PluginLoader([join(testPackagePath, 'esm-export.js')]);
55+
await loader.load();
56+
expect(loader.pushPlugins.length).to.equal(1);
57+
expect(loader.pushPlugins.every((p) => isCompatiblePlugin(p))).to.be.true;
58+
expect(loader.pushPlugins.every((p) => isCompatiblePlugin(p, 'isGitProxyPushActionPlugin')))
59+
.to.be.true;
60+
}).timeout(10000);
61+
62+
it('should load multiple plugins from a module that match the plugin class (exports default { pluginFoo, pluginBar })', async function () {
63+
const loader = new PluginLoader([join(testPackagePath, 'esm-multiple-export.js')]);
64+
await loader.load();
65+
expect(loader.pushPlugins.length).to.equal(1);
66+
expect(loader.pullPlugins.length).to.equal(1);
67+
expect(loader.pushPlugins.every((p) => isCompatiblePlugin(p))).to.be.true;
68+
expect(loader.pushPlugins.every((p) => isCompatiblePlugin(p, 'isGitProxyPushActionPlugin')))
69+
.to.be.true;
70+
expect(loader.pullPlugins.every((p) => isCompatiblePlugin(p, 'isGitProxyPullActionPlugin')))
71+
.to.be.true;
72+
}).timeout(10000);
73+
74+
it('should load plugins that are subclassed from plugin classes (exports default class DummyPlugin extends PushActionPlugin {})', async function () {
75+
const loader = new PluginLoader([join(testPackagePath, 'esm-subclass.js')]);
76+
await loader.load();
77+
expect(loader.pushPlugins.length).to.equal(1);
78+
expect(loader.pushPlugins.every((p) => isCompatiblePlugin(p))).to.be.true;
79+
expect(loader.pushPlugins.every((p) => isCompatiblePlugin(p, 'isGitProxyPushActionPlugin')))
80+
.to.be.true;
81+
}).timeout(10000);
82+
});
5483

5584
it('should not load plugins that are not valid modules', async function () {
5685
const loader = new PluginLoader([join(__dirname, './dummy.js')]);

0 commit comments

Comments
 (0)