Skip to content

Commit

Permalink
Refactor code-style
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Jun 26, 2022
1 parent 7bd9b71 commit c3f827f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
5 changes: 1 addition & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,8 @@
"xo": {
"prettier": true,
"rules": {
"no-await-in-loop": "off",
"no-control-regex": "off",
"n/file-extension-in-import": "off",
"unicorn/no-this-assignment": "off",
"unicorn/prefer-node-protocol": "off"
"unicorn/no-this-assignment": "off"
}
},
"remarkConfig": {
Expand Down
34 changes: 24 additions & 10 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {URL} from 'node:url'
import fs from 'fs'
import path from 'path'
import fs from 'node:fs/promises'
import path from 'node:path'
import test from 'tape'
import {micromark} from 'micromark'
import {rehype} from 'rehype'
Expand Down Expand Up @@ -211,13 +211,28 @@ test('fixtures', async (t) => {

await createGfmFixtures(base)

const files = fs.readdirSync(base).filter((d) => /\.md$/.test(d))
const allFiles = await fs.readdir(base)
const files = allFiles.filter((d) => /\.md$/.test(d))

t.plan(files.length)

let index = -1

while (++index < files.length) {
const name = path.basename(files[index], '.md')
const input = fs.readFileSync(new URL(name + '.md', base))
let expected = String(fs.readFileSync(new URL(name + '.html', base)))
testOne(t, files[index])
}
})

/**
* @param {import('tape').Test} t
* @param {string} basename
*/
function testOne(t, basename) {
const base = new URL('fixtures/', import.meta.url)
const name = path.basename(basename, '.md')
t.test(basename, async (t) => {
const input = await fs.readFile(new URL(name + '.md', base))
let expected = String(await fs.readFile(new URL(name + '.html', base)))
let actual = micromark(input, {
extensions: [syntax],
htmlExtensions: [html]
Expand All @@ -231,6 +246,7 @@ test('fixtures', async (t) => {
)

// GH replaces some control codes.
// eslint-disable-next-line no-control-regex
actual = actual.replace(/[\u001F\u0085]/g, '�')

// GH strips images that point to just a search or hash.
Expand All @@ -257,7 +273,5 @@ test('fixtures', async (t) => {
}

t.deepEqual(actual, expected, name)
}

t.end()
})
})
}

0 comments on commit c3f827f

Please sign in to comment.