Skip to content

Commit

Permalink
test: fix test case error.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Sep 28, 2023
1 parent 4f7fbf4 commit ec428b8
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 33 deletions.
12 changes: 7 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
"prepack": "npm run build",
"start": "node lib/index.js",
"watch": "tsbb watch",
"build": "tsbb build && npm run esm-fix",
"esm-fix": "tsc-esm-fix --target='lib' --ext='.js'",
"build": "tsbb build",
"type-check": "tsc --noEmit",
"test": "tsbb test",
"coverage": "tsbb test --coverage"
Expand All @@ -37,12 +36,16 @@
"unified"
],
"jest": {
"extensionsToTreatAsEsm": [".ts"],
"moduleNameMapper": {
"^(\\.{1,2}/.*)\\.js$": "$1"
},
"transformIgnorePatterns": [
"<rootDir>/node_modules/?!(.*)"
]
},
"engines": {
"node": ">=16.0.0"
"node": ">=16"
},
"dependencies": {
"unified": "~11.0.0",
Expand All @@ -55,7 +58,6 @@
"remark-gfm": "~4.0.0",
"remark-parse": "~11.0.0",
"remark-rehype": "~11.0.0",
"tsc-esm-fix": "~2.20.0",
"tsbb": "^4.0.5"
"tsbb": "^4.2.3"
}
}
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Plugin } from 'unified';
import { Root, Element, Comment, Properties, Literal } from 'hast';
import type { Plugin } from 'unified';
import type { Root, Element, Comment, Properties, Literal } from 'hast';
import { visit } from 'unist-util-visit';
import { propertiesHandle, nextChild, prevChild, getCommentObject } from './utils';
import { propertiesHandle, nextChild, prevChild, getCommentObject } from './utils.js';

export type RehypeAttrsOptions = {
/**
Expand Down
4 changes: 2 additions & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Element, Comment, Literal, ElementContent, RootContent, Properties } from 'hast';
import { RehypeAttrsOptions } from './index';
import type { Element, Comment, Literal, ElementContent, RootContent, Properties } from 'hast';
import type { RehypeAttrsOptions } from './index.js';

export const getURLParameters = (url: string = '') =>
((url.match(/([^?=&]+)(=([^&]*))/g) || []) as string[]).reduce(
Expand Down
23 changes: 2 additions & 21 deletions test/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { unified, Plugin } from 'unified';
import { Comment, Literal, ElementContent } from 'hast';
import { Parent, NodeData } from 'unist';
import { rehype } from 'rehype';
import gfm from 'remark-gfm';
import rehypeRaw from 'rehype-raw';
import remark2rehype from 'remark-rehype';
import remarkParse from 'remark-parse';
import stringify from 'rehype-stringify';
import rehypeAttrs from '../src/index';
import * as utils from '../src/utils';
import rehypeAttrs from '../src/index.js';
import * as utils from '../src/utils.js';

const mrkStr = "<!--rehype:title=Rehype Attrs-->\n```js\nconsole.log('')\n```"

Expand Down Expand Up @@ -42,24 +41,6 @@ describe('rehype-attr type raw test case', () => {
})

describe('rehype-attr function test case', () => {
it('visit', async () => {
const node: NodeData<Parent> = {
"type": "root",
"children": [
{
"type": "element",
"tagName": "p",
"properties": {},
"children": [
{ "type": "text", "value": "This is a " },
{ "type": "element", "tagName": "del", "properties": {}, "children": [ { "type": "text", "value": "title" } ] },
{ "type": "comment", "value": "rehype:style=color:pink;" }
]
}
],
"data": { "quirksMode": false }
}
});
it('getCommentObject', async () => {
expect(utils.getCommentObject({} as Comment)).toEqual({ });
expect(utils.getCommentObject({ value: 'rehype:title=Rehype Attrs' } as Comment)).toEqual({ title: 'Rehype Attrs' });
Expand Down
5 changes: 3 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"compilerOptions": {
"target": "ES2022",
"module": "Node16",
"module": "node16",
"moduleResolution": "node16",
"sourceMap": true,
"declaration": true,
"noFallthroughCasesInSwitch": true,
Expand All @@ -11,7 +12,7 @@
"strictPropertyInitialization": true,
"stripInternal": true,
"skipLibCheck": true,
"esModuleInterop": false,
"esModuleInterop": true,
"noImplicitAny": true,
"outDir": "lib",
"baseUrl": "."
Expand Down

0 comments on commit ec428b8

Please sign in to comment.