Skip to content

Commit

Permalink
tests: added & modified test in package.json
Browse files Browse the repository at this point in the history
  • Loading branch information
kelsk committed Apr 27, 2020
1 parent 0d0e2ef commit 7f32b81
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 4 deletions.
1 change: 1 addition & 0 deletions run/markdown-preview/editor/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,6 @@ app.listen(port, err => {
// Exports for testing purposes.
module.exports = {
app,
buildService,
buildTemplate
}
2 changes: 1 addition & 1 deletion run/markdown-preview/editor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"main": "main.js",
"scripts": {
"start": "node main.js",
"test": "mocha test/*.test.js"
"test": "mocha test/*.test.js --exit"
},
"dependencies": {
"express": "^4.17.1",
Expand Down
28 changes: 26 additions & 2 deletions run/markdown-preview/editor/test/main.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@ const assert = require('assert');
const path = require('path');
const supertest = require('supertest');

let request, template, htmlString, markdownString, falseString;
const env = Object.assign({}, process.env);

let request, service, template, htmlString, markdownString, falseString;

describe('Editor unit tests', () => {
before(async () => {
const {app, buildTemplate} = require(path.join(__dirname, '..', 'main'));
const {app, buildService, buildTemplate} = require(path.join(__dirname, '..', 'main'));
request = supertest(app);
service = async () => { return await buildService()};
template = await buildTemplate();
});

Expand Down Expand Up @@ -57,4 +60,25 @@ describe('Editor unit tests', () => {
await request.post('/render').type('json').send('{"markdown":"valid string"}').expect(200);
});
});

describe('Service builder', () => {
it('should respond with an error for no EDITOR_UPSTREAM_RENDER_URL var', async () => {
assert.rejects(await service, 'Error')
});

// Reload the server with updated env vars.
before(async () => {
process.env.EDITOR_UPSTREAM_RENDER_URL = 'https://www.example.com/';
const {app, buildService} = require(path.join(__dirname, '..', 'main'));
request = supertest(app);
service = async () => { return await buildService()};
})

it('should return an object with an EDITOR_UPSTREAM_RENDER_URL var', async () => {
const response = await service();
assert.equal(response.url, process.env.EDITOR_UPSTREAM_RENDER_URL);
assert.equal(response.url, 'https://www.example.com/');
assert.equal(response.isAuthenticated, true);
})
})
});
2 changes: 1 addition & 1 deletion run/markdown-preview/renderer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"main": "main.js",
"scripts": {
"start": "node main.js",
"test": "mocha test/*.test.js"
"test": "mocha test/*.test.js --exit"
},
"dependencies": {
"express": "^4.17.1",
Expand Down

0 comments on commit 7f32b81

Please sign in to comment.