liudong
2023-05-29 340f156319b863525e50e900c58e59b86ecb3d5e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
const should = require("should");
const sinon = require("sinon");
 
const NR_TEST_UTILS = require("nr-test-utils");
const plugins = NR_TEST_UTILS.require("@node-red/runtime/lib/api/plugins")
 
const mockLog = () => ({
    log: sinon.stub(),
    debug: sinon.stub(),
    trace: sinon.stub(),
    warn: sinon.stub(),
    info: sinon.stub(),
    metric: sinon.stub(),
    audit: sinon.stub(),
    _: function() { return "abc"}
})
 
describe("runtime-api/plugins", function() {
    const pluginList = [{id:"one",module:'test-module'},{id:"two",module:"node-red"}];
    const pluginConfigs = "123";
 
    describe("getPluginList", function() {
        it("gets the plugin list", function() {
            plugins.init({
                log: mockLog(),
                plugins: {
                    getPluginList: function() { return pluginList}
                }
            });
            return plugins.getPluginList({}).then(function(result) {
                result.should.eql(pluginList);
            })
        });
    });
    describe("getPluginConfigs", function() {
        it("gets the plugin configs", function() {
            plugins.init({
                log: mockLog(),
                plugins: {
                    getPluginConfigs: function() { return pluginConfigs}
                }
            });
            return plugins.getPluginConfigs({}).then(function(result) {
                result.should.eql(pluginConfigs);
            })
        });
    });
    describe("getPluginCatalogs", function() {
        it("gets the plugin catalogs", function() {
            plugins.init({
                log: mockLog(),
                plugins: {
                    getPluginList: function() { return pluginList}
                },
                i18n: {
                    i: {
                        changeLanguage: function(lang,done) { done && done() },
                        getResourceBundle: function(lang, id) { return {lang,id}}
                    }
                }
            });
            return plugins.getPluginCatalogs({lang: "en-US"}).then(function(result) {
                JSON.stringify(result).should.eql(JSON.stringify({ one: { lang: "en-US", id: "one" } }))
            })
        });
    });
 
});