fix: Add tests for the linter
This commit is contained in:
committed by
mrugesh
parent
db69c9b071
commit
b440851381
38
curriculum/tools/fixtures/badFencing.md
Normal file
38
curriculum/tools/fixtures/badFencing.md
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
---
|
||||||
|
id: ''
|
||||||
|
title: ''
|
||||||
|
challengeType: 0
|
||||||
|
videoUrl: ''
|
||||||
|
---
|
||||||
|
|
||||||
|
## Description
|
||||||
|
<section id='description'>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
## Instructions
|
||||||
|
<section id='instructions'>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
## Tests
|
||||||
|
<section id='tests'>
|
||||||
|
```yml
|
||||||
|
tests:
|
||||||
|
- text: text
|
||||||
|
testString: testString
|
||||||
|
|
||||||
|
```
|
||||||
|
</section>
|
||||||
|
|
||||||
|
## Challenge Seed
|
||||||
|
<section id='challengeSeed'>
|
||||||
|
|
||||||
|
<div id='html-seed'>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</section>
|
||||||
|
|
||||||
|
## Solution
|
||||||
|
<section id='solution'>
|
||||||
|
</section>
|
40
curriculum/tools/fixtures/badYML.md
Normal file
40
curriculum/tools/fixtures/badYML.md
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
---
|
||||||
|
id: ''
|
||||||
|
title: ''
|
||||||
|
challengeType: 0
|
||||||
|
videoUrl: ''
|
||||||
|
---
|
||||||
|
|
||||||
|
## Description
|
||||||
|
<section id='description'>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
## Instructions
|
||||||
|
<section id='instructions'>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
## Tests
|
||||||
|
<section id='tests'>
|
||||||
|
|
||||||
|
```yml
|
||||||
|
tests:
|
||||||
|
- text: text
|
||||||
|
testString: testString
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
</section>
|
||||||
|
|
||||||
|
## Challenge Seed
|
||||||
|
<section id='challengeSeed'>
|
||||||
|
|
||||||
|
<div id='html-seed'>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</section>
|
||||||
|
|
||||||
|
## Solution
|
||||||
|
<section id='solution'>
|
||||||
|
</section>
|
40
curriculum/tools/fixtures/good.md
Normal file
40
curriculum/tools/fixtures/good.md
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
---
|
||||||
|
id: ''
|
||||||
|
title: ''
|
||||||
|
challengeType: 0
|
||||||
|
videoUrl: ''
|
||||||
|
---
|
||||||
|
|
||||||
|
## Description
|
||||||
|
<section id='description'>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
## Instructions
|
||||||
|
<section id='instructions'>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
## Tests
|
||||||
|
<section id='tests'>
|
||||||
|
|
||||||
|
```yml
|
||||||
|
tests:
|
||||||
|
- text: text
|
||||||
|
testString: testString
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
</section>
|
||||||
|
|
||||||
|
## Challenge Seed
|
||||||
|
<section id='challengeSeed'>
|
||||||
|
|
||||||
|
<div id='html-seed'>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</section>
|
||||||
|
|
||||||
|
## Solution
|
||||||
|
<section id='solution'>
|
||||||
|
</section>
|
@ -1,7 +1,7 @@
|
|||||||
const markdownlint = require('markdownlint');
|
const markdownlint = require('markdownlint');
|
||||||
|
|
||||||
const lintYAML = require('./markdown-yaml');
|
const lintYAML = require('./markdown-yaml');
|
||||||
const lintConfig = require('./.markdownlintrc.js');
|
const lintConfig = require('./.markdownlintrc');
|
||||||
const argv = require('yargs').argv;
|
const argv = require('yargs').argv;
|
||||||
|
|
||||||
const isMDRE = /.*\.md$/;
|
const isMDRE = /.*\.md$/;
|
||||||
|
57
curriculum/tools/lint.test.js
Normal file
57
curriculum/tools/lint.test.js
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
/* global describe it expect jest beforeEach */
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
const lint = require('./lint');
|
||||||
|
|
||||||
|
describe('markdown linter', () => {
|
||||||
|
let good = { path: path.join(__dirname, './fixtures/good.md') };
|
||||||
|
let badYML = { path: path.join(__dirname, './fixtures/badYML.md') };
|
||||||
|
let badFencing = { path: path.join(__dirname, './fixtures/badFencing.md') };
|
||||||
|
beforeEach(() => {
|
||||||
|
console.log = jest.fn();
|
||||||
|
// the linter signals that a file failed by setting
|
||||||
|
// exitCode to 1, so it needs (re)setting to 0
|
||||||
|
process.exitCode = 0;
|
||||||
|
});
|
||||||
|
afterEach(() => {
|
||||||
|
process.exitCode = 0;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should pass `good` markdown', done => {
|
||||||
|
function callback() {
|
||||||
|
expect(process.exitCode).toBe(0);
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
lint(good, callback);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should fail invalid YML blocks', done => {
|
||||||
|
function callback() {
|
||||||
|
expect(process.exitCode).toBe(1);
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
lint(badYML, callback);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should fail when code fences are not surrounded by newlines', done => {
|
||||||
|
function callback() {
|
||||||
|
expect(process.exitCode).toBe(1);
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
lint(badFencing, callback);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should write to the console describing the problem', done => {
|
||||||
|
function callback() {
|
||||||
|
const expected =
|
||||||
|
// eslint-disable-next-line max-len
|
||||||
|
'fixtures/badYML.md: 19: yaml-linter YAML code blocks must be valid [bad indentation of a mapping entry at line 3, column 17:\n testString: testString\n ^] [Context: "```yml"]';
|
||||||
|
expect(console.log.mock.calls.length).toBe(1);
|
||||||
|
expect(console.log.mock.calls[0][0]).toEqual(
|
||||||
|
expect.stringContaining(expected)
|
||||||
|
);
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
lint(badYML, callback);
|
||||||
|
});
|
||||||
|
});
|
@ -75,7 +75,7 @@
|
|||||||
"eslint --fix",
|
"eslint --fix",
|
||||||
"git add"
|
"git add"
|
||||||
],
|
],
|
||||||
"*.md": [
|
"./curriculum/challenges/**/*.md": [
|
||||||
"node ./curriculum/tools/lint",
|
"node ./curriculum/tools/lint",
|
||||||
"git add"
|
"git add"
|
||||||
]
|
]
|
||||||
|
Reference in New Issue
Block a user