Skip to content

Commit

Permalink
feat: update readme v4 (#1312)
Browse files Browse the repository at this point in the history
* feat: update readme v4

* chore: update @verdaccio/ui-theme@0.1.9

* chore: update @verdaccio/ui-theme@0.1.10
  • Loading branch information
juanpicado committed May 17, 2019
1 parent a588588 commit 7686417
Show file tree
Hide file tree
Showing 7 changed files with 206 additions and 38 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"dependencies": {
"@verdaccio/local-storage": "2.1.0",
"@verdaccio/streams": "2.0.0",
"@verdaccio/ui-theme": "0.1.7",
"@verdaccio/readme": "1.0.3",
"@verdaccio/ui-theme": "0.1.10",
"JSONStream": "1.3.5",
"async": "3.0.1-0",
"body-parser": "1.19.0",
Expand All @@ -41,7 +42,7 @@
"mkdirp": "0.5.1",
"mv": "2.1.1",
"pkginfo": "0.4.1",
"request": "2.88.0",
"request": "2.87.0",

This comment has been minimized.

Copy link
@zkochan

zkochan Aug 4, 2019

Collaborator

@juanpicado why was the version of request downgraded?

This comment has been minimized.

Copy link
@juanpicado

juanpicado Aug 4, 2019

Author Member

@zkochan The next version 2.88.0 makes fail all the test, few months ago I did a research and there was a regression issue, so, for such reason I keep it in 2.87.0 until next release is shipped. Unfortunately I did not remember the issue.

"semver": "6.0.0",
"verdaccio-audit": "1.2.0",
"verdaccio-htpasswd": "2.0.0"
Expand Down
9 changes: 5 additions & 4 deletions src/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import semver from 'semver';
import YAML from 'js-yaml';
import URL from 'url';
import createError from 'http-errors';
import marked from 'marked';
// $FlowFixMe
import sanitizyReadme from '@verdaccio/readme';

import { HTTP_STATUS, API_ERROR, DEFAULT_PORT, DEFAULT_DOMAIN, DEFAULT_PROTOCOL, CHARACTER_ENCODING, HEADERS, DIST_TAGS, DEFAULT_USER } from './constants';
import { generateGravatarUrl, GENERIC_AVATAR } from '../utils/user';
Expand Down Expand Up @@ -487,14 +488,14 @@ export function addGravatarSupport(pkgInfo: Object, online: boolean = true): Obj
* @return {String} converted html template
*/
export function parseReadme(packageName: string, readme: string): string {
if (readme) {
return marked(readme);
if (_.isEmpty(readme) === false) {
return sanitizyReadme(readme);
}

// logs readme not found error
Logger.logger.error({ packageName }, '@{packageName}: No readme found');

return marked('ERROR: No README data found!');
return sanitizyReadme('ERROR: No README data found!');
}

export function buildToken(type: string, token: string): string {
Expand Down
10 changes: 6 additions & 4 deletions test/functional/readme/readme.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export default function (server, server2) {
describe('should test readme', () => {
const README_PKG1 = 'readme-test';
const README_PKG2 = 'readme-test-no-readme';
const README_MESSAGE = 'this is a readme';

beforeAll(async function() {
await server.putPackage('readme-test', require('./pkg-readme.json'))
Expand All @@ -16,20 +17,21 @@ export default function (server, server2) {
test('add pkg', () => {});

describe('should check readme file', () => {
const matchReadme = (serverRef, pkgName = README_PKG1, readmeMessage = 'this is a readme') => {
const matchReadme = (serverRef, pkgName = README_PKG1, readmeMessage = README_MESSAGE) => {
return serverRef.request({
uri: `/-/verdaccio/package/readme/${pkgName}`
}).status(HTTP_STATUS.OK).then(function(body) {
expect(body).toEqual(`<p>${readmeMessage}</p>\n`);

expect(body).toEqual(`<p>${readmeMessage}</p>`);
});
};

test('should fetch server2 over uplink server1', () => {
return matchReadme(server, README_PKG1, 'this is a readme');
return matchReadme(server, README_PKG1, README_MESSAGE);
});

test('should fetch package on local server1', () => {
return matchReadme(server2, README_PKG1, 'this is a readme');
return matchReadme(server2, README_PKG1, README_MESSAGE);
});

test('should fetch not found readme server2 over uplink server1', () => {
Expand Down
3 changes: 1 addition & 2 deletions test/unit/api/__snapshots__/utils.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,5 @@ exports[`Utilities parseReadme should parse makrdown text to html template 1`] =
<li>Hat tip to anyone whose code was used</li>
<li>Inspiration</li>
<li>etc</li>
</ul>
"
</ul>"
`;
10 changes: 5 additions & 5 deletions test/unit/api/utils.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ describe('Utilities', () => {
test('should parse makrdown text to html template', () => {
const markdown = '# markdown';
expect(parseReadme('testPackage', markdown)).toEqual(
'<h1 id="markdown">markdown</h1>\n'
'<h1 id="markdown">markdown</h1>'
);
expect(
parseReadme('testPackage', String(readmeFile('markdown.md')))
Expand All @@ -387,21 +387,21 @@ describe('Utilities', () => {
const randomTextMarkdown = 'simple text \n # markdown';

expect(parseReadme('testPackage', randomText)).toEqual(
'<p>%%%%%**##==</p>\n'
'<p>%%%%%**##==</p>'
);
expect(parseReadme('testPackage', simpleText)).toEqual(
'<p>simple text</p>\n'
'<p>simple text</p>'
);
expect(parseReadme('testPackage', randomTextMarkdown)).toEqual(
'<p>simple text </p>\n<h1 id="markdown">markdown</h1>\n'
'<p>simple text </p>\n<h1 id="markdown">markdown</h1>'
);
});

test('should show error for no readme data', () => {
const noData = '';
const spy = jest.spyOn(Logger.logger, 'error');
expect(parseReadme('testPackage', noData)).toEqual(
'<p>ERROR: No README data found!</p>\n'
'<p>ERROR: No README data found!</p>'
);
expect(spy).toHaveBeenCalledWith(
{ packageName: 'testPackage' },
Expand Down
2 changes: 1 addition & 1 deletion test/unit/partials/config-unit-mock-server-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ auth:
password: test

logs:
- { type: stdout, format: pretty, level: warn }
- { type: stdout, format: pretty, level: trace }

packages:
'@*/*':
Expand Down
Loading

0 comments on commit 7686417

Please sign in to comment.