Skip to content

Commit 2a24d69

Browse files
committed
Update plugin tests
They still aren't very good but they are at least not the boilerplate ones!
1 parent a7134ad commit 2a24d69

2 files changed

Lines changed: 58 additions & 101 deletions

File tree

Lines changed: 29 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
/*eslint-env node, mocha*/
22

33
describe('ExportToJSON', function () {
4+
const {promisify} = require('util');
5+
const assert = require('assert').strict;
46
var testFixture = require('../../globals'),
57
gmeConfig = testFixture.getGmeConfig(),
6-
expect = testFixture.expect,
78
logger = testFixture.logger.fork('ExportToJSON'),
89
PluginCliManager = testFixture.WebGME.PluginCliManager,
910
projectName = 'testProject',
@@ -13,43 +14,33 @@ describe('ExportToJSON', function () {
1314
storage,
1415
commitHash;
1516

16-
before(function (done) {
17-
testFixture.clearDBAndGetGMEAuth(gmeConfig, projectName)
18-
.then(function (gmeAuth_) {
19-
gmeAuth = gmeAuth_;
20-
// This uses in memory storage. Use testFixture.getMongoStorage to persist test to database.
21-
storage = testFixture.getMemoryStorage(logger, gmeConfig, gmeAuth);
22-
return storage.openDatabase();
23-
})
24-
.then(function () {
25-
var importParam = {
26-
projectSeed: testFixture.path.join(testFixture.SEED_DIR, 'EmptyProject.webgmex'),
27-
projectName: projectName,
28-
branchName: 'master',
29-
logger: logger,
30-
gmeConfig: gmeConfig
31-
};
17+
const manager = new PluginCliManager(null, logger, gmeConfig);
18+
manager.executePlugin = promisify(manager.executePlugin.bind(manager));
3219

33-
return testFixture.importProject(storage, importParam);
34-
})
35-
.then(function (importResult) {
36-
project = importResult.project;
37-
commitHash = importResult.commitHash;
38-
return project.createBranch('test', commitHash);
39-
})
40-
.nodeify(done);
20+
before(async function () {
21+
gmeAuth = await testFixture.clearDBAndGetGMEAuth(gmeConfig, projectName)
22+
storage = testFixture.getMemoryStorage(logger, gmeConfig, gmeAuth);
23+
await storage.openDatabase();
24+
const importParam = {
25+
projectSeed: testFixture.path.join(testFixture.SEED_DIR, 'EmptyProject.webgmex'),
26+
projectName: projectName,
27+
branchName: 'master',
28+
logger: logger,
29+
gmeConfig: gmeConfig
30+
};
31+
32+
const importResult = await testFixture.importProject(storage, importParam);
33+
project = importResult.project;
34+
commitHash = importResult.commitHash;
35+
await project.createBranch('test', commitHash);
4136
});
4237

43-
after(function (done) {
44-
storage.closeDatabase()
45-
.then(function () {
46-
return gmeAuth.unload();
47-
})
48-
.nodeify(done);
38+
after(async function () {
39+
await storage.closeDatabase()
40+
await gmeAuth.unload();
4941
});
5042

51-
it('should run plugin and update the branch', function (done) {
52-
var manager = new PluginCliManager(null, logger, gmeConfig),
43+
it('should run plugin and update the branch', async function () {
5344
pluginConfig = {
5445
},
5546
context = {
@@ -59,21 +50,10 @@ describe('ExportToJSON', function () {
5950
activeNode: '/1',
6051
};
6152

62-
manager.executePlugin(pluginName, pluginConfig, context, function (err, pluginResult) {
63-
try {
64-
expect(err).to.equal(null);
65-
expect(typeof pluginResult).to.equal('object');
66-
expect(pluginResult.success).to.equal(true);
67-
} catch (e) {
68-
done(e);
69-
return;
70-
}
71-
72-
project.getBranchHash('test')
73-
.then(function (branchHash) {
74-
expect(branchHash).to.not.equal(commitHash);
75-
})
76-
.nodeify(done);
77-
});
53+
const pluginResult = await manager.executePlugin(pluginName, pluginConfig, context);
54+
assert.equal(typeof pluginResult, 'object');
55+
assert(pluginResult.success);
56+
const branchHash = await project.getBranchHash('test');
57+
assert.equal(branchHash, commitHash);
7858
});
7959
});
Lines changed: 29 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
/*eslint-env node, mocha*/
2-
/**
3-
* Generated by PluginGenerator 2.20.5 from webgme on Tue Mar 30 2021 07:29:49 GMT-0500 (Central Daylight Time).
4-
*/
52

63
describe('SetStateFromJSON', function () {
4+
const assert = require('assert').strict;
5+
const {promisify} = require('util');
76
var testFixture = require('../../globals'),
87
gmeConfig = testFixture.getGmeConfig(),
98
expect = testFixture.expect,
@@ -16,44 +15,34 @@ describe('SetStateFromJSON', function () {
1615
storage,
1716
commitHash;
1817

19-
before(function (done) {
20-
testFixture.clearDBAndGetGMEAuth(gmeConfig, projectName)
21-
.then(function (gmeAuth_) {
22-
gmeAuth = gmeAuth_;
23-
// This uses in memory storage. Use testFixture.getMongoStorage to persist test to database.
24-
storage = testFixture.getMemoryStorage(logger, gmeConfig, gmeAuth);
25-
return storage.openDatabase();
26-
})
27-
.then(function () {
28-
var importParam = {
29-
projectSeed: testFixture.path.join(testFixture.SEED_DIR, 'EmptyProject.webgmex'),
30-
projectName: projectName,
31-
branchName: 'master',
32-
logger: logger,
33-
gmeConfig: gmeConfig
34-
};
18+
const manager = new PluginCliManager(null, logger, gmeConfig);
19+
manager.executePlugin = promisify(manager.executePlugin.bind(manager));
3520

36-
return testFixture.importProject(storage, importParam);
37-
})
38-
.then(function (importResult) {
39-
project = importResult.project;
40-
commitHash = importResult.commitHash;
41-
return project.createBranch('test', commitHash);
42-
})
43-
.nodeify(done);
21+
before(async function () {
22+
gmeAuth = await testFixture.clearDBAndGetGMEAuth(gmeConfig, projectName)
23+
storage = testFixture.getMemoryStorage(logger, gmeConfig, gmeAuth);
24+
await storage.openDatabase();
25+
const importParam = {
26+
projectSeed: testFixture.path.join(testFixture.SEED_DIR, 'EmptyProject.webgmex'),
27+
projectName: projectName,
28+
branchName: 'master',
29+
logger: logger,
30+
gmeConfig: gmeConfig
31+
};
32+
33+
const importResult = await testFixture.importProject(storage, importParam);
34+
project = importResult.project;
35+
commitHash = importResult.commitHash;
36+
await project.createBranch('test', commitHash);
4437
});
4538

46-
after(function (done) {
47-
storage.closeDatabase()
48-
.then(function () {
49-
return gmeAuth.unload();
50-
})
51-
.nodeify(done);
39+
after(async function () {
40+
await storage.closeDatabase()
41+
await gmeAuth.unload();
5242
});
5343

54-
it('should run plugin and update the branch', function (done) {
55-
var manager = new PluginCliManager(null, logger, gmeConfig),
56-
pluginConfig = {
44+
it('should require JSON file', async function () {
45+
var pluginConfig = {
5746
},
5847
context = {
5948
project: project,
@@ -62,21 +51,9 @@ describe('SetStateFromJSON', function () {
6251
activeNode: '/1',
6352
};
6453

65-
manager.executePlugin(pluginName, pluginConfig, context, function (err, pluginResult) {
66-
try {
67-
expect(err).to.equal(null);
68-
expect(typeof pluginResult).to.equal('object');
69-
expect(pluginResult.success).to.equal(true);
70-
} catch (e) {
71-
done(e);
72-
return;
73-
}
74-
75-
project.getBranchHash('test')
76-
.then(function (branchHash) {
77-
expect(branchHash).to.not.equal(commitHash);
78-
})
79-
.nodeify(done);
80-
});
54+
await assert.rejects(
55+
() => manager.executePlugin(pluginName, pluginConfig, context),
56+
/JSON file required/
57+
);
8158
});
8259
});

0 commit comments

Comments
 (0)