Skip to content

Commit 7f32b81

Browse files
committed
tests: added & modified test in package.json
1 parent 0d0e2ef commit 7f32b81

File tree

4 files changed

+29
-4
lines changed

4 files changed

+29
-4
lines changed

run/markdown-preview/editor/main.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,5 +78,6 @@ app.listen(port, err => {
7878
// Exports for testing purposes.
7979
module.exports = {
8080
app,
81+
buildService,
8182
buildTemplate
8283
}

run/markdown-preview/editor/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"main": "main.js",
1616
"scripts": {
1717
"start": "node main.js",
18-
"test": "mocha test/*.test.js"
18+
"test": "mocha test/*.test.js --exit"
1919
},
2020
"dependencies": {
2121
"express": "^4.17.1",

run/markdown-preview/editor/test/main.test.js

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,15 @@ const assert = require('assert');
1818
const path = require('path');
1919
const supertest = require('supertest');
2020

21-
let request, template, htmlString, markdownString, falseString;
21+
const env = Object.assign({}, process.env);
22+
23+
let request, service, template, htmlString, markdownString, falseString;
2224

2325
describe('Editor unit tests', () => {
2426
before(async () => {
25-
const {app, buildTemplate} = require(path.join(__dirname, '..', 'main'));
27+
const {app, buildService, buildTemplate} = require(path.join(__dirname, '..', 'main'));
2628
request = supertest(app);
29+
service = async () => { return await buildService()};
2730
template = await buildTemplate();
2831
});
2932

@@ -57,4 +60,25 @@ describe('Editor unit tests', () => {
5760
await request.post('/render').type('json').send('{"markdown":"valid string"}').expect(200);
5861
});
5962
});
63+
64+
describe('Service builder', () => {
65+
it('should respond with an error for no EDITOR_UPSTREAM_RENDER_URL var', async () => {
66+
assert.rejects(await service, 'Error')
67+
});
68+
69+
// Reload the server with updated env vars.
70+
before(async () => {
71+
process.env.EDITOR_UPSTREAM_RENDER_URL = 'https://www.example.com/';
72+
const {app, buildService} = require(path.join(__dirname, '..', 'main'));
73+
request = supertest(app);
74+
service = async () => { return await buildService()};
75+
})
76+
77+
it('should return an object with an EDITOR_UPSTREAM_RENDER_URL var', async () => {
78+
const response = await service();
79+
assert.equal(response.url, process.env.EDITOR_UPSTREAM_RENDER_URL);
80+
assert.equal(response.url, 'https://www.example.com/');
81+
assert.equal(response.isAuthenticated, true);
82+
})
83+
})
6084
});

run/markdown-preview/renderer/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"main": "main.js",
1616
"scripts": {
1717
"start": "node main.js",
18-
"test": "mocha test/*.test.js"
18+
"test": "mocha test/*.test.js --exit"
1919
},
2020
"dependencies": {
2121
"express": "^4.17.1",

0 commit comments

Comments
 (0)