Skip to content

Commit

Permalink
Merge pull request #61 from empress/mocha-lint
Browse files Browse the repository at this point in the history
Add Mocha test linting
  • Loading branch information
mansona authored Sep 25, 2021
2 parents 7e5aade + 802a3ab commit c5f5fe6
Show file tree
Hide file tree
Showing 10 changed files with 138 additions and 51 deletions.
9 changes: 8 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
},
"overrides": [{
"files": ["test/**/*.js"],
"plugins": [
"mocha"
],
"extends": [
"plugin:mocha/recommended"
],
"env": {
"mocha": true
},
Expand All @@ -25,7 +31,8 @@
"import/no-extraneous-dependencies": [0],
"prefer-arrow-callback": [0],
"arrow-body-style": [0],
"no-unused-expressions": [0]
"no-unused-expressions": [0],
"mocha/no-exclusive-tests": "error"
}
}]
}
1 change: 0 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const TableOfContents = require('./lib/table-of-contents');
const CollateJsonApiBlobs = require('./lib/collate-and-paginate');
const MarkdownToJsonApi = require('./lib/markdown-to-jsonapi');


class EmptyNode extends Plugin {
constructor() {
super([]);
Expand Down
1 change: 0 additions & 1 deletion lib/table-of-contents.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ function subpageUrls(parentUrl, currentPage, childPages) {
}
}


class TableOfContentsExtractor extends PersistentFilter {
constructor(folder, options) {
super(folder, options);
Expand Down
89 changes: 85 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"eslint": "^6.8.0",
"eslint-config-airbnb-base": "^14.0.0",
"eslint-plugin-import": "^2.19.1",
"eslint-plugin-mocha": "^9.0.0",
"mocha": "^7.0.0",
"nyc": "^15.0.0",
"release-it": "^14.4.1",
Expand Down
36 changes: 18 additions & 18 deletions test/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ async function buildSingleFile(fileContents, options) {
return indexJSON.data;
}

describe('JSONAPI attributes', () => {
beforeEach(async () => {
describe('JSONAPI attributes', function () {
beforeEach(async function () {
input = await createTempDir();
});

afterEach(async () => {
afterEach(async function () {
try {
await input.dispose();
} finally {
Expand All @@ -38,7 +38,7 @@ describe('JSONAPI attributes', () => {
}
});

it('should not include title if the frontmatter is included but no options passed', async () => {
it('should not include title if the frontmatter is included but no options passed', async function () {
const result = await buildSingleFile(`---
title: a lovely title
---
Expand All @@ -48,7 +48,7 @@ title: a lovely title
expect(result.attributes).have.property('content', '# Hello world');
});

it('should include title if the frontmatter is included and title is in attributes', async () => {
it('should include title if the frontmatter is included and title is in attributes', async function () {
const result = await buildSingleFile(`---
title: a lovely title
---
Expand All @@ -60,7 +60,7 @@ title: a lovely title
expect(result.attributes).have.property('content', '# Hello world');
});

it('should not inlude any extra frontmatter that is not defined in attributes', async () => {
it('should not inlude any extra frontmatter that is not defined in attributes', async function () {
const result = await buildSingleFile(`---
unknown: some unknown frontmatter
---
Expand All @@ -69,7 +69,7 @@ unknown: some unknown frontmatter
expect(result.attributes).to.not.have.property('unknown');
});

it('should allow you to specify attributes and for them to be included in the output', async () => {
it('should allow you to specify attributes and for them to be included in the output', async function () {
const result = await buildSingleFile(`---
known: some frontmatter
---
Expand All @@ -80,7 +80,7 @@ known: some frontmatter
expect(result.attributes).to.have.property('known', 'some frontmatter');
});

it('should make the frontmatter description take precedent if attribute description is specified', async () => {
it('should make the frontmatter description take precedent if attribute description is specified', async function () {
const result = await buildSingleFile(`---
description: use me instead
---
Expand All @@ -91,7 +91,7 @@ description: use me instead
expect(result.attributes).to.have.property('description', 'use me instead');
});

it('should make the frontmatter description take precedent if contentType description is specified', async () => {
it('should make the frontmatter description take precedent if contentType description is specified', async function () {
const result = await buildSingleFile(`---
description: use me instead
---
Expand All @@ -102,37 +102,37 @@ description: use me instead
expect(result.attributes).to.have.property('description', 'use me instead');
});

it('should only include html and content with basic config', async () => {
it('should only include html and content with basic config', async function () {
const result = await buildSingleFile('# Hello world');

expect(result.attributes).have.keys(['html', 'content']);
});

it('should not include html if it is not in the content types', async () => {
it('should not include html if it is not in the content types', async function () {
const result = await buildSingleFile('# Hello world', {
contentTypes: ['content'],
});

expect(result.attributes).have.keys(['content']);
});

it('should not include markdown if it is not in the content types', async () => {
it('should not include markdown if it is not in the content types', async function () {
const result = await buildSingleFile('# Hello world', {
contentTypes: ['html'],
});

expect(result.attributes).have.keys(['html']);
});

it('should include description if it is defined in config', async () => {
it('should include description if it is defined in config', async function () {
const result = await buildSingleFile('# Hello world', {
contentTypes: ['html', 'content', 'description'],
});

expect(result.attributes).have.keys(['html', 'content', 'description']);
});

it('should limit description to 260 characters', async () => {
it('should limit description to 260 characters', async function () {
const result = await buildSingleFile(`# Hello world
This is where I write my really long essay to the world. I will start off bing **super** important and then _slow down_ to a stop.
Expand All @@ -146,7 +146,7 @@ I really like programming. I could do this all day long without ever stooopping,
expect(result.attributes.description).to.have.lengthOf.at.most(260);
});

it('should end the description with ... when the content is limited', async () => {
it('should end the description with ... when the content is limited', async function () {
const result = await buildSingleFile(`# Hello world
This is where I write my really long essay to the world. I will start off bing **super** important and then _slow down_ to a stop.
Expand All @@ -160,7 +160,7 @@ I really like programming. I could do this all day long without ever stooopping,
expect(result.attributes.description).to.match(/\.\.\.$/);
});

it('should not end the description with ... when the content is not limited', async () => {
it('should not end the description with ... when the content is not limited', async function () {
const result = await buildSingleFile(`# Hello world
This is where I write my really long essay to the world. I will start off bing **super** important and then _slow down_ to a stop.
Expand All @@ -171,7 +171,7 @@ This is where I write my really long essay to the world. I will start off bing *
expect(result.attributes.description).to.not.match(/\.\.\.$/);
});

it('should throw an error if there is an unknown content type', async () => {
it('should throw an error if there is an unknown content type', async function () {
let error;

try {
Expand All @@ -186,7 +186,7 @@ This is where I write my really long essay to the world. I will start off bing *
expect(error.message).to.equal('Unknown content type: faceyFace');
});

it.only('should include page table of contents if included in contentTypes', async () => {
it('should include page table of contents if included in contentTypes', async function () {
const result = await buildSingleFile(`# Hello world
This is the first part
Expand Down
14 changes: 7 additions & 7 deletions test/collections.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ async function buildFiles(files, options) {
return outputFiles;
}

describe('collections', () => {
beforeEach(async () => {
describe('collections', function () {
beforeEach(async function () {
input = await createTempDir();
});

afterEach(async () => {
afterEach(async function () {
try {
await input.dispose();
} finally {
Expand All @@ -46,7 +46,7 @@ describe('collections', () => {
}
});

it('should have the same ids for collection objects as it does for individual objects', async () => {
it('should have the same ids for collection objects as it does for individual objects', async function () {
const files = await buildFiles({
'index.md': `---
title: a lovely title
Expand Down Expand Up @@ -74,7 +74,7 @@ title: more words
expect(files['all.json'].find((obj) => obj.id === 'double-word')).to.be.ok;
});

it('should allow you to define a collection and for the specified content folder to be exported as an single JSONAPI array response', async () => {
it('should allow you to define a collection and for the specified content folder to be exported as an single JSONAPI array response', async function () {
const subject = new StaticSiteJson(input.path(), {
attributes: ['title'],
type: 'page',
Expand Down Expand Up @@ -131,7 +131,7 @@ title: more words
});
});

it('should still generate the all.json even if there is only one input file', async () => {
it('should still generate the all.json even if there is only one input file', async function () {
const subject = new StaticSiteJson(input.path(), {
attributes: ['title'],
type: 'page',
Expand Down Expand Up @@ -165,7 +165,7 @@ title: a lovely title
});
});

it('should work if a broccoli plugin is passed in instead of a folder', async () => {
it('should work if a broccoli plugin is passed in instead of a folder', async function () {
const mdFiles = new Funnel(input.path(), { destDir: 'face' });

const subject = new StaticSiteJson(mdFiles, {
Expand Down
Loading

0 comments on commit c5f5fe6

Please sign in to comment.