diff --git a/node test.js b/node test.js deleted file mode 100644 index eb69f93ba..000000000 --- a/node test.js +++ /dev/null @@ -1,86 +0,0 @@ -require('tap').mochaGlobals() -const assert = require('assert') -import remark from 'remark' -const frontmatter = require('remark-frontmatter') -const extract = require('remark-extract-frontmatter') -const yaml = require('yaml').parse -const strip = require('strip-markdown') -const vfile = require('to-vfile') -const syllable = require('syllable') -const fs = require('fs') - -const dir = './_haikus/' -const blockList = ['haikus.md'] - -const files = fs.readdirSync(dir) - -files.forEach(async (file) => { - if (!blockList.includes(file)) { - const [text, meta] = await processMarkdown(dir + file) - const lines = text.split('\n').filter((line) => line !== '') - - if (meta.test !== false) { - validateHaiku(file, lines, meta) - } - } -}) - -async function processMarkdown(filename) { - return new Promise((resolve, reject) => { - remark() - .use(frontmatter) - .use(extract, { yaml: yaml }) - .use(strip) - .process(vfile.readSync(filename), (err, file) => { - if (err) { - reject(err) - } else { - resolve([file.toString(), file.data]) - } - }) - }) -} - -function validateHaiku(filename, lines, meta) { - describe(filename, () => { - it("should have a '.md' file extension", () => { - assert.ok(/\.md$/.test(filename), "extension does not match '.md'") - }) - - describe('file metadata', () => { - it("should have layout equal to 'haiku'", () => { - assert.equal( - meta.layout, - 'haiku', - "layout metadata should equal 'haiku'" - ) - }) - - it('should have non-blank title', () => { - assert.equal(typeof meta.title, 'string', 'title metadata is missing') - }) - - it('should have non-blank author', () => { - assert.equal(typeof meta.author, 'string', 'author metadata is missing') - }) - }) - - describe('haiku structure', () => { - it('should have three lines', () => { - assert.equal(lines.length, 3) - }) - - it('should have five syllables on the first line', () => { - assert.equal(syllable(lines[0]), 5) - }) - - it('should have seven syllables on the second line', () => { - assert.equal(syllable(lines[1]), 7) - }) - - it('should have five syllables on the third line', () => { - assert.equal(syllable(lines[2]), 5) - }) - }) - }) -} diff --git a/package.json b/package.json index adfe7e299..6a6b2a8b3 100644 --- a/package.json +++ b/package.json @@ -1,30 +1,31 @@ { - "name": "cloud_haiku", - "version": "1.0.0", - "description": "Haiku structure testing for cloud_haiku repo", - "main": "node test.js", - "scripts": { - "test": "tap node test.js -R min --no-coverage-report --timeout=300" - }, - "repository": { - "type": "git", - "url": "git+https://github.com/do-community/cloud_haiku.git" - }, - "author": "DigitalOcean Community Team", - "license": "MIT", - "bugs": { - "url": "https://github.com/do-community/cloud_haiku/issues" - }, - "homepage": "https://github.com/do-community/cloud_haiku#readme", - "dependencies": { - "node-fetch": "^2.6.1", - "remark": "^14.0.2", - "remark-extract-frontmatter": "^2.0.0", - "remark-frontmatter": "^1.3.2", - "strip-markdown": "^3.1.1", - "syllable": "^4.0.0", - "tap": "^14.6.9", - "to-vfile": "^6.0.0", - "yaml": "^1.7.0" - } -} + "name": "cloud_haiku", + "version": "1.0.0", + "description": "Haiku structure testing for cloud_haiku repo", + "main": "node test.js", + "scripts": { + "test": "tap node test.js -R min --no-coverage-report --timeout=300" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/do-community/cloud_haiku.git" + }, + "author": "DigitalOcean Community Team", + "license": "MIT", + "bugs": { + "url": "https://github.com/do-community/cloud_haiku/issues" + }, + "homepage": "https://github.com/do-community/cloud_haiku#readme", + "dependencies": { + "append-transform": "^latest", + "node-fetch": "^2.6.1", + "remark": "^14.0.2", + "remark-extract-frontmatter": "^2.0.0", + "remark-frontmatter": "^1.3.2", + "strip-markdown": "^3.1.1", + "syllable": "^4.0.0", + "tap": "^14.6.9", + "to-vfile": "^6.0.0", + "yaml": "^1.7.0" + } +} \ No newline at end of file diff --git a/test.js b/test.js new file mode 100644 index 000000000..6d40a7d10 --- /dev/null +++ b/test.js @@ -0,0 +1,41 @@ +const assert = require('assert'); +import remark from 'remark'; +import { validateHaiku } from './validateHaiku'; +const frontmatter = require('remark-frontmatter'); +const extract = require('remark-extract-frontmatter'); +const yaml = require('yaml').parse; +const strip = require('strip-markdown'); +const vfile = require('to-vfile'); +const fs = require('fs'); + +const dir = './_haikus/'; +const blockList = ['haikus.md']; + +const files = fs.readdirSync(dir); + +files.forEach(async(file) => { + if (!blockList.includes(file)) { + const [text, meta] = await processMarkdown(dir + file); + const lines = text.split('\n').filter((line) => line !== ''); + + if (meta.test !== false) { + validateHaiku(file, lines, meta); + } + } +}); + +async function processMarkdown(filename) { + return new Promise((resolve, reject) => { + remark() + .use(frontmatter) + .use(extract, { yaml: yaml }) + .use(strip) + .process(vfile.readSync(filename), (err, file) => { + if (err) { + reject(err); + } else { + resolve([file.toString(), file.data]); + } + }); + }); +} \ No newline at end of file diff --git a/validateHaiku.js b/validateHaiku.js new file mode 100644 index 000000000..6e0da2178 --- /dev/null +++ b/validateHaiku.js @@ -0,0 +1,36 @@ +const tap = require('tap'); +const syllable = require('syllable'); + +export function validateHaiku(filename, lines, meta) { + tap.test(filename, () => { + tap.test('should have a '.md, ' file extension', () => { + tap.ok(/\.md$/.test(filename), 'extension does not match '.md, ''); + }); + + tap.test('file metadata', () => { + tap.test('should have layout equal to \'haiku\'', () => { + tap.equal(meta.layout, 'haiku', 'layout metadata should equal \'haiku\''); + }); + + tap.test('should have non-blank title', () => { + tap.equal(typeof meta.title, 'string', 'title metadata is missing'); + }); + + tap.test('should have non-blank author', () => { + tap.equal(typeof meta.author, 'string', 'author metadata is missing'); + }); + }); + + tap.test('haiku structure', () => { + tap.test('should have three lines', () => { + tap.equal(lines.length, 3); + }); + + tap.test('should have five syllables on the first line', () => { + tap.equal(syllable(lines[0]), 5); + }); + + tap.test('should have seven syllables on the second line', () => {}); + }); + }); +} \ No newline at end of file