Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: coverage not reported AND wrong type #17

Merged
merged 5 commits into from
Jun 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .nycrc.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
extends: '@istanbuljs/nyc-config-typescript'
all: true
check-coverage: false
include:
- src/**/*.ts
- lib/src
- src
exclude:
- node_modules
- "**/*.d.ts"
sourceMap: true
extension:
- .ts
- .js
Expand Down
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
language: node_js
node_js:
- node
- lts/*
after_success:
- npm run coveralls
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,17 @@ import 'prismjs/plugins/line-numbers/prism-line-numbers.css'

// parse markdown to html
unified()
.use(markdown)
.use(remark2rehype)
.use(remarkParse)
.use(remarkRehype)
// it should be after rehype
.use(rehypePrism, { plugins: ['line-numbers'] })
.use(html)
.use(rehypeStringify)
.parse(/* markstring string */)

// parse code block in html string
rehyper()
.use(rehypePrism)
.use(html)
.use(rehypeStringify)
.parse(/* html string */)
```

Expand Down
11 changes: 7 additions & 4 deletions ava.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
export default {
files: ['tests/**/*.ts'],
extensions: { ts: 'module' },
nonSemVerExperiments: {
configurableModuleFormat: true,
files: ['tests/**/*.ts', '!tests/**/*.before-each.ts'],
// extensions: { ts: 'module' },
typescript: {
rewritePaths: {
'tests/': 'lib/tests/',
},
compile: false,
},
nodeArguments: [
'--loader=ts-node/esm',
Expand Down
12 changes: 12 additions & 0 deletions build/tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "../lib",
"sourceMap": true,
},
"include": [
"../src/**/*.ts",
"../tests/**/*.ts"
],
}

61 changes: 31 additions & 30 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,30 +1,28 @@
{
"name": "rehype-prism",
"type": "module",
"main": "lib/index.js",
"main": "lib/src/index.js",
"types": "lib/src/index.d.ts",
"scripts": {
"test": "ava",
"updateSnapshots": "ava -u",
"upgrade": "mili upgrade",
"clean": "rm -rf ./lib/*",
"build": "ttsc && npm run copyfile",
"prepublishOnly": "npm run build",
"test": "npm run build:test && c8 ava",
"test:debug": "ava --verbose",
"test:update": "ava -u",
"report": "npm run build:test && c8 --reporter=html --reporter=text-summary --skip-full ava",
"coveralls": "c8 report --reporter=text-lcov | coveralls",
"ci": "git-cz",
"ca": "git add -A && git-cz -av",
"commit": "git-cz",
"release": "standard-version",
"release:alpha": "standard-version --prerelease alpha",
"release:first": "standard-version --first-release",
"report": "nyc --reporter=html --reporter=text-summary --skip-full ava",
"coveralls": "nyc npm test && nyc report --reporter=text-lcov | coveralls",
"lint": "eslint \"src/**/*.ts\" \"tests/**/*.ts\" --fix",
"prepare": "is-ci || husky install",
"ci": "git-cz",
"test:debug": "ava --verbose",
"test:update": "ava -u",
"prebuild": "npm run clean",
"prepublishOnly": "npm run build",
"clean": "rm -rf ./lib/*",
"copyfile": "copyfiles -u 1 \"src/**/*.!(ts)\" lib/src",
"build": "npm run clean && ttsc && npm run copyfile",
"build:test": "npm run clean && ttsc -p build/tsconfig.test.json && npm run copyfile",
"prewatch": "npm run copyfile",
"watch": "NODE_ENV=development ttsc -w",
"copyfile": "copyfiles -e \"@(build|es|lib|node_modules|tests|doc)/**/*.!(ts)\" -e \"@(README.md|CHANGELOG.md|ava.config.js|backers.md)\" \"**/*.!(ts)\" lib"
"lint": "eslint \"src/**/*.ts\" \"test/**/*.ts\" --fix",
"prepare": "is-ci || husky install"
},
"description": "The unified plugin used to highlight code block in html with Prism",
"version": "2.1.2",
Expand Down Expand Up @@ -56,44 +54,47 @@
"homepage": "https://github.com/Val-istar-Guo/rehype-prism#readme",
"devDependencies": {
"@ava/babel": "^2.0.0",
"@commitlint/cli": "^12.1.4",
"@commitlint/config-conventional": "^12.1.4",
"@istanbuljs/nyc-config-typescript": "^1.0.1",
"@ava/typescript": "^3.0.1",
"@commitlint/cli": "^17.0.2",
"@commitlint/config-conventional": "^17.0.2",
"@typescript-eslint/eslint-plugin": "^4.15.2",
"@typescript-eslint/parser": "^4.15.2",
"ava": "^3.10.1",
"ajv": "8",
"ava": "^4.3.0",
"c8": "^7.11.3",
"commitizen": "^4.2.4",
"copyfiles": "^2.4.1",
"coveralls": "^3.1.0",
"cz-conventional-changelog": "^3.3.0",
"eslint": "^7.20.0",
"husky": "^5.2.0",
"husky": "7",
"is-ci": "^3.0.0",
"lint-staged": "^11.0.0",
"lint-staged": "^13.0.2",
"mili": "^4.7.4",
"nyc": "^15.1.0",
"rehype-stringify": "^8.0.0",
"remark-parse": "^9.0.0",
"remark-rehype": "^8.1.0",
"sinon": "^10.0.0",
"sinon": "^14.0.0",
"standard-version": "^9.3.0",
"ts-node": "^10.7.0",
"ts-node": "^10.8.1",
"ttypescript": "^1.5.12",
"typescript": "^4.2.2",
"typescript-transform-paths": "^2.2.3",
"typescript-transform-paths": "^3.3.1",
"unified": "^10.1.2"
},
"dependencies": {
"@types/hast": "*",
"@types/mdast": "*",
"@types/node": ">12",
"@types/prismjs": "^1.16.6",
"@types/unist": "*",
"prismjs": "^1.24.1",
"rehype-parse": "^7.0.1",
"rehype-parse": "^7 || ^ 8",
"unist-util-is": "^4 || ^5",
"unist-util-select": "^4",
"unist-util-visit": "^3 || ^4"
},
"peerDependencies": {
"unified": "^10"
},
"types": "lib/index.d.ts"
}
}
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const visitor = (preNode: hast.Element): void => {
const html = Prism.highlight(textNode.value, Prism.languages[lang], lang)
const tree = unified()
.use(parse, { fragment: true })
.parse(html) as hast.Element
.parse(html) as unknown as hast.Element

if (!preNode.properties) preNode.properties = {}
if (!preNode.properties.className) preNode.properties.className = []
Expand Down
18 changes: 14 additions & 4 deletions tests/index.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
import test from 'ava'
import { unified } from 'unified'
import markdown from 'remark-parse'
import remarkParse from 'remark-parse'
import remark2rehype from 'remark-rehype'
import html from 'rehype-stringify'
import rehypePrism from '../src/index.js'


test('rehype prism', t => {
test('rehype prism with language', t => {
const processor = unified()
.use(markdown)
.use(remarkParse)
.use(remark2rehype)
.use(rehypePrism, { plugins: ['toolbar', 'copy-to-clipboard'] })
.use(html)

t.snapshot(processor.processSync('```javascript\nconst a = 1\n```\n').value)
})

test('rehype prism without language', t => {
const processor = unified()
.use(remarkParse)
.use(remark2rehype)
.use(rehypePrism, { plugins: ['toolbar', 'copy-to-clipboard'] })
.use(html)

t.snapshot(processor.processSync('```javascript\nconst a = 1\n```').value)
t.snapshot(processor.processSync('```\nconst a = 1\n```\n').value)
})
16 changes: 15 additions & 1 deletion tests/snapshots/index.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,23 @@ The actual snapshot is saved in `index.ts.snap`.

Generated by [AVA](https://avajs.dev).

## rehype prism with language

> Snapshot 1

`<pre class="language-javascript"><code class="language-javascript"><span class="token keyword">const</span> a <span class="token operator">=</span> <span class="token number">1</span>␊
</code></pre>`

## rehype prism without language

> Snapshot 1

`<pre><code>const a = 1␊
</code></pre>`

## rehype prism

> Snapshot 1

`<pre><code class="language-javascript">const a = 1
`<pre class="language-javascript"><code class="language-javascript"><span class="token keyword">const</span> a <span class="token operator">=</span> <span class="token number">1</span>
</code></pre>`
Binary file modified tests/snapshots/index.ts.snap
Binary file not shown.
10 changes: 3 additions & 7 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
"noImplicitAny": false,
"declaration": true,
"baseUrl": "./",
"rootDir": "./",
"allowSyntheticDefaultImports": true,
"noEmitOnError": true,
"skipLibCheck": true,
"paths": {
"@/*": [
"src/*"
Expand All @@ -31,13 +33,7 @@
"exclude": [
"node_modules"
],
"files": [
"index.ts"
],
"include": [
"src/**/*.ts"
],
"ts-node": {
"compiler": "ttypescript"
}
]
}