Skip to content

Commit

Permalink
fix(project): Throws error when README does not contain a summary
Browse files Browse the repository at this point in the history
  • Loading branch information
mfdebian authored and lupomontero committed Aug 31, 2023
1 parent b3edc28 commit 899e801
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1 +1,15 @@
# A project

## Índice

Blah blah blah

***

## 1. Preámbulo

Blah blah blah

## 2. Resumen del proyecto

Blah blah blah
Original file line number Diff line number Diff line change
@@ -1 +1,15 @@
# Foo
# A project

## Índice

Blah blah blah

***

## 1. Preámbulo

Blah blah blah

## 2. Resumen del proyecto

Blah blah blah
Original file line number Diff line number Diff line change
@@ -1 +1,15 @@
# A project

## Índice

Blah blah blah

***

## 1. Preámbulo

Blah blah blah

## 2. Resumen del proyecto

Blah blah blah
11 changes: 11 additions & 0 deletions lib/__tests__/__fixtures__/01-a-project-without-summary/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# A project

## Índice

Blah blah blah

***

## 1. Preámbulo

Blah blah blah
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
learningObjectives:
- html/semantics
- css/selectors
- dom/selectors
- dom/events
- dom/manipulation
- js/data-types/primitive-vs-non-primitive
- js/data-types/strings
- js/variables
- js/conditionals
- js/functions
- js/semantics
- ux/user-understanding
- ux/prototyping
14 changes: 13 additions & 1 deletion lib/__tests__/__fixtures__/01-a-project-without-track/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
# A project

BLah blah blah.
## Índice

Blah blah blah

***

## 1. Preámbulo

Blah blah blah

## 2. Resumen del proyecto

Blah blah blah
4 changes: 2 additions & 2 deletions lib/__tests__/__snapshots__/project.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ exports[`parseProject > parses a project with learning objectives validating aga
"cover": null,
"intl": {
"es": {
"summary": null,
"summary": "<p>Blah blah blah</p>",
"title": "A project",
},
},
Expand Down Expand Up @@ -75,7 +75,7 @@ exports[`parseProject > parses a project with learning objectives without valida
"cover": null,
"intl": {
"es": {
"summary": null,
"summary": "<p>Blah blah blah</p>",
"title": "A project",
},
},
Expand Down
14 changes: 14 additions & 0 deletions lib/__tests__/project.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ describe('parseProject', () => {

it('extracts first paragraph of _resumen del proyecto_ as summary', () => {
const p = resolveFixturePath('01-a-project-with-summary');
expect.assertions(2);
return parseProject(p, {
repo: 'Laboratoria/bootcamp',
version: '1.0.0',
Expand All @@ -172,6 +173,19 @@ describe('parseProject', () => {
});
});

it('when no summary in project', () => {
const p = resolveFixturePath('01-a-project-without-summary');
expect.assertions(1);
return parseProject(p, {
repo: 'Laboratoria/bootcamp',
version: '1.0.0',
lo: path.join(__dirname, '__fixtures__', 'learning-objectives'),
}, pkg)
.catch((err) => {
expect(err.message).toBe('No project summary found');
});
});

it('creates a thumbnail when file not present and has cover', () => {
const p = resolveFixturePath('01-a-project-without-thumb');
const thumbPath = path.join(p, 'thumb.png');
Expand Down
2 changes: 1 addition & 1 deletion lib/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const getSummary = (rootNode) => {
));

if (headingIdx === -1 || rootNode.children[headingIdx + 1].type !== 'paragraph') {
return null;
throw new Error('No project summary found');
}

return parser.stringify(parser.runSync(rootNode.children[headingIdx + 1]));
Expand Down

0 comments on commit 899e801

Please sign in to comment.