1 | 'use strict';
|
2 |
|
3 | const assert = require('assert');
|
4 | const path = require('path');
|
5 |
|
6 | const fontoxmlDevelopmentTools = require('../');
|
7 |
|
8 | const App = fontoxmlDevelopmentTools.App;
|
9 |
|
10 | const defaultStdoutColumns = process.stdout.columns;
|
11 |
|
12 | let app;
|
13 | let oldCwd;
|
14 | let loadedCoreModulePath;
|
15 | let loadedCoreModule;
|
16 |
|
17 | describe('module: core', () => {
|
18 | beforeEach(() => {
|
19 | process.stdout.columns = 150;
|
20 |
|
21 | oldCwd = process.cwd();
|
22 | process.chdir(path.join(__dirname, './app'));
|
23 |
|
24 | app = new App({
|
25 | testMode: true,
|
26 | skipAddModules: true,
|
27 | skipWarnIfNotInsideEditorRepository: true,
|
28 | fotnoOptions: {
|
29 | appName: 'fontoxml-development-tools-test'
|
30 | }
|
31 | });
|
32 |
|
33 | loadedCoreModulePath = path.join(__dirname, '../src/modules/core');
|
34 | loadedCoreModule = app.enableBuiltInModule(loadedCoreModulePath);
|
35 | });
|
36 |
|
37 | afterEach(() => {
|
38 | process.chdir(oldCwd);
|
39 |
|
40 | process.stdout.columns = defaultStdoutColumns;
|
41 | });
|
42 |
|
43 | it('has enabled this core module', () => {
|
44 | assert.ok(app.modules.some(c => c.getInfo().name === 'fontoxml-development-tools-module-core'));
|
45 | assert.ok(app.modules.some(c => c === loadedCoreModule));
|
46 | });
|
47 |
|
48 | describe('contextInformer', () => {
|
49 | it('registers the context informer', () => {
|
50 | assert.equal(loadedCoreModule.getContextInformers().length, 1);
|
51 | });
|
52 |
|
53 | it('outputs when the who command is run', () => {
|
54 | return app.run(['who']).then(() => {
|
55 | app.testOutput.assert('FontoXML');
|
56 | app.testOutput.assert('FontoXML config (config.json)');
|
57 | });
|
58 | });
|
59 |
|
60 | it('outputs the editor repository information', () => {
|
61 | return app.run(['who']).then(() => {
|
62 | const startPosition = app.testOutput.findOutputIndex(/^ {2}Application.+fontoxml-app-development-tools-test-editor/) - 1;
|
63 |
|
64 | app.testOutput.assert(/^ {2}FontoXML/, startPosition + 0);
|
65 | app.testOutput.assert(/^ {2}Application.+fontoxml-app-development-tools-test-editor/, startPosition + 1);
|
66 | app.testOutput.assert(/^ {2}SDK version.+6\.9\.1/, startPosition + 2);
|
67 | app.testOutput.assert(/^ {2}Path.+(\/|\\)fontoxml-development-tools(\/|\\)test(\/|\\)app/, startPosition + 3);
|
68 |
|
69 | app.testOutput.assert(/^ {2}FontoXML config \(config.json\)/, startPosition + 5);
|
70 | app.testOutput.assert(/^ {2}scope.+\{.+\}/, startPosition + 6);
|
71 | app.testOutput.assert(/^ {2}scope.+"documentIds":\["document\.xml"\]/, startPosition + 6);
|
72 | app.testOutput.assert(/^ {2}fdt modules.+\.\/test-module-1/, startPosition + 7);
|
73 |
|
74 | app.testOutput.assert(/^ {2}port.+8081/, startPosition + 8);
|
75 | });
|
76 | });
|
77 |
|
78 | it('outputs none value when there are no fdt modules configured', () => {
|
79 | delete app.request.fdt.editorRepository.config.developmentToolsModules;
|
80 | return app.run(['who']).then(() => {
|
81 | const startPosition = app.testOutput.findOutputIndex(/fdt modules.+none/) - 2;
|
82 | app.testOutput.assert(/^ {2}FontoXML config \(config.json\)/, startPosition + 0);
|
83 | app.testOutput.assert(/^ {2}fdt modules.+none/, startPosition + 2);
|
84 | });
|
85 | });
|
86 |
|
87 | it('outputs config from config.js', () => {
|
88 | process.chdir(oldCwd);
|
89 | process.chdir(path.join(__dirname, './app-with-configjs'));
|
90 |
|
91 | app = new App({
|
92 | testMode: true,
|
93 | skipAddModules: true,
|
94 | skipWarnIfNotInsideEditorRepository: true,
|
95 | fotnoOptions: {
|
96 | appName: 'fontoxml-development-tools-test'
|
97 | }
|
98 | });
|
99 |
|
100 | loadedCoreModule = app.enableBuiltInModule(loadedCoreModulePath);
|
101 |
|
102 | return app.run(['who']).then(() => {
|
103 | const startPosition = app.testOutput.findOutputIndex(/^ {2}Application.+fontoxml-app-development-tools-test-editor-with-configjs/) - 1;
|
104 |
|
105 | app.testOutput.assert(/^ {2}FontoXML/, startPosition + 0);
|
106 | app.testOutput.assert(/^ {2}Application.+fontoxml-app-development-tools-test-editor-with-configjs/, startPosition + 1);
|
107 | app.testOutput.assert(/^ {2}SDK version.+6\.9\.1/, startPosition + 2);
|
108 | app.testOutput.assert(/^ {2}Path.+(\/|\\)fontoxml-development-tools(\/|\\)test(\/|\\)app-with-configjs/, startPosition + 3);
|
109 |
|
110 | app.testOutput.assert(/^ {2}FontoXML config \(config.js\)/, startPosition + 5);
|
111 | app.testOutput.assert(/^ {2}scope.+\{.+\}/, startPosition + 6);
|
112 | app.testOutput.assert(/^ {2}scope.+"documentIds":\["document[0-9]\.xml"\]/, startPosition + 6);
|
113 | app.testOutput.assert(/^ {2}proxy.+\{"some-proxy":"http:\/\/some-proxy\.local\/"\}/, startPosition + 7);
|
114 | });
|
115 | });
|
116 |
|
117 | it('can handle the absence of an editor repository', () => {
|
118 | process.chdir(oldCwd);
|
119 |
|
120 | const appOutsideEditorRepository = new App({
|
121 | testMode: true,
|
122 | skipAddModules: true,
|
123 | skipWarnIfNotInsideEditorRepository: true,
|
124 | fotnoOptions: {
|
125 | appName: 'fontoxml-development-tools-test'
|
126 | }
|
127 | });
|
128 |
|
129 | loadedCoreModule = appOutsideEditorRepository.enableBuiltInModule(loadedCoreModulePath);
|
130 |
|
131 | return appOutsideEditorRepository.run(['who']).then(() => {
|
132 | const startPosition = appOutsideEditorRepository.testOutput.findOutputIndex('You\'re not running from inside an editor repository.') - 1;
|
133 |
|
134 | appOutsideEditorRepository.testOutput.assert(/^ {2}FontoXML/, startPosition + 0);
|
135 | appOutsideEditorRepository.testOutput.assert(/^ {2}You're not running from inside an editor repository./, startPosition + 1);
|
136 |
|
137 | assert.ok(!appOutsideEditorRepository.testOutput.outputContains('FontoXML config'), 'Outputting config caption, while there is no configuration');
|
138 | });
|
139 | });
|
140 | });
|
141 | });
|