Skip to content

Commit 1a55643

Browse files
committed
parse relative img links; added tests
1 parent bb1f4a4 commit 1a55643

File tree

5 files changed

+30
-2
lines changed

5 files changed

+30
-2
lines changed

.babelrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"presets": ["es2015", "stage-0"]
3+
}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
node_modules/
22
.DS_Store
33
npm-debug.log
4+
coverage/

__tests__/index.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const m = require('../');
2+
3+
describe('module', () => {
4+
it('should retrieve some results', async () => {
5+
const results = await m.execute('dext');
6+
expect(results).toBeTruthy();
7+
});
8+
9+
it('should retrieve the readme contents', async () => {
10+
const details = await m.details.render({ title: 'vutran/dext' });
11+
expect(details).toBeTruthy();
12+
});
13+
});

index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ const makeRequest = (endpoint, options) => {
3434
const applyRelativeUrls = (html, fullName) => {
3535
const url = `https://github.com/${fullName}/blob/master`;
3636
// replace images
37-
let parsedImages = html.replace(/\(([\w\d\s]+\.(?:png|gif|jpg|jpeg)+.*)\)/g, `(${url}/$1)`);
38-
return parsedImages;
37+
let parsed = html.replace(/\(([\w\d\s]+\.(?:png|gif|jpg|jpeg)+.*)\)/g, `(${url}/$1)`);
38+
return parsed;
3939
};
4040

4141
/**

package.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,18 @@
1212
"main": "index.js",
1313
"author": "Vu Tran <vu@vu-tran.com>",
1414
"license": "MIT",
15+
"scripts": {
16+
"lint": "eslint .",
17+
"test": "jest --coverage"
18+
},
1519
"dependencies": {
1620
"got": "^6.3.0"
21+
},
22+
"devDependencies": {
23+
"babel-jest": "^15.0.0",
24+
"babel-polyfill": "^6.13.0",
25+
"babel-preset-es2015": "^6.14.0",
26+
"babel-preset-stage-0": "^6.5.0",
27+
"jest": "^15.1.1"
1728
}
1829
}

0 commit comments

Comments
 (0)