Skip to content

Commit

Permalink
Replace dependencies in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Feb 28, 2023
1 parent 7b0a03c commit 6f51f51
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 22 deletions.
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,19 @@
"c8": "^7.0.0",
"chalk": "^5.0.0",
"detab": "^3.0.0",
"hast-util-to-html": "^8.0.0",
"is-hidden": "^2.0.0",
"is-keyword": "^1.0.0",
"mdast-zone": "^5.0.0",
"patch-package": "^6.0.0",
"prettier": "^2.0.0",
"prismjs": "~1.29.0",
"rehype": "^12.0.0",
"remark-cli": "^11.0.0",
"remark-preset-wooorm": "^9.0.0",
"trim-lines": "^3.0.0",
"type-coverage": "^2.0.0",
"typescript": "^4.0.0",
"unist-builder": "^3.0.0",
"unist-util-remove-position": "^4.0.0",
"xo": "^0.53.0"
},
"scripts": {
Expand All @@ -83,7 +82,7 @@
"build": "tsc --build --clean && tsc --build && type-coverage",
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
"test-api": "node --conditions development test/index.js",
"test-coverage": "c8 -x \"lang/*.js\" -x \"lib/prism-core.js\" --check-coverage --100 --reporter lcov npm run test-api",
"test-coverage": "c8 -x \"lang/\" -x \"test/\" -x \"lib/prism-core.js\" --check-coverage --100 --reporter lcov npm run test-api",
"test": "npm run generate && npm run build && npm run format && npm run test-coverage"
},
"prettier": {
Expand Down
40 changes: 21 additions & 19 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

import assert from 'node:assert/strict'
import fs from 'node:fs/promises'
import process from 'node:process'
import test from 'node:test'
import {rehype} from 'rehype'
import {toHtml} from 'hast-util-to-html'
import {isHidden} from 'is-hidden'
import {removePosition} from 'unist-util-remove-position'
import {refractor} from '../lib/all.js'

/* eslint-disable no-await-in-loop */
Expand Down Expand Up @@ -150,7 +150,6 @@ test('.alias(name, alias)', () => {

test('fixtures', async () => {
const root = new URL('fixtures/', import.meta.url)
const processor = rehype().use({settings: {fragment: true}})
const files = await fs.readdir(root)
let index = -1

Expand All @@ -161,22 +160,25 @@ test('fixtures', async () => {
if (isHidden(name)) continue

const lang = name.split('-')[0]
const input = String(
await fs.readFile(new URL(name + '/input.txt', root))
).trim()
const expected = String(
await fs.readFile(new URL(name + '/output.html', root))
).trim()

assert.deepEqual(
Object.assign(refractor.highlight(input, lang), {
data: undefined
}),
Object.assign(removePosition(processor.parse(expected), true), {
data: undefined
}),
name
)
const inputUrl = new URL(name + '/input.txt', root)
const outputUrl = new URL(name + '/output.html', root)
const input = String(await fs.readFile(inputUrl)).trim()
const actual = toHtml(refractor.highlight(input, lang))
/** @type {string} */
let expected

try {
expected = String(await fs.readFile(outputUrl)).trim()

if ('UPDATE' in process.env) {
throw new Error('Update!')
}
} catch {
expected = actual
await fs.writeFile(outputUrl, actual + '\n')
}

assert.equal(actual, expected, name)
}
})

Expand Down

0 comments on commit 6f51f51

Please # to comment.