Skip to content

Commit

Permalink
try try
Browse files Browse the repository at this point in the history
  • Loading branch information
upendranayanajith committed Oct 29, 2023
1 parent e5a8308 commit 1ceb3c0
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 115 deletions.
86 changes: 0 additions & 86 deletions node test.js

This file was deleted.

59 changes: 30 additions & 29 deletions package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
41 changes: 41 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
@@ -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]);
}
});
});
}
36 changes: 36 additions & 0 deletions validateHaiku.js
Original file line number Diff line number Diff line change
@@ -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', () => {});
});
});
}

0 comments on commit 1ceb3c0

Please sign in to comment.