Skip to content

Commit 9d34682

Browse files
committed
fixed lint issues and added unit tests
1 parent a8c234b commit 9d34682

34 files changed

+5414
-4809
lines changed

jest.config.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// jest.config.js
2+
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
3+
4+
module.exports = {
5+
preset: 'ts-jest',
6+
roots: [
7+
'<rootDir>'
8+
],
9+
moduleDirectories: ["node_modules", "<rootDir>"],
10+
modulePaths: ["<rootDir>"],
11+
transform: {
12+
'^.+\\.ts$': [
13+
'ts-jest',
14+
{
15+
tsconfig: '<rootDir>/tsconfig.json',
16+
},
17+
],
18+
},
19+
testEnvironment: "jsdom",
20+
moduleFileExtensions: ['js', 'ts', 'tsx', 'd.ts'],
21+
transformIgnorePatterns: ['node_modules'],
22+
testMatch: ['**/*.test.ts'],
23+
moduleNameMapper: {
24+
"^.+\\.(css|less|scss)$": "babel-jest"
25+
}
26+
};

package.json

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,15 @@
4343
"devDependencies": {
4444
"@babel/core": "^7.22.11",
4545
"@babel/plugin-external-helpers": "^7.22.5",
46-
"@babel/preset-env": "^7.22.10",
46+
"@babel/preset-env": "^7.26.8",
4747
"@babel/preset-typescript": "^7.22.11",
4848
"@rollup/plugin-babel": "^5.3.1",
4949
"@rollup/plugin-commonjs": "^19.0.2",
5050
"@rollup/plugin-node-resolve": "^13.3.0",
5151
"@rollup/plugin-replace": "^2.4.2",
52+
"@types/jest": "^29.5.14",
53+
"@types/mocha": "^10.0.10",
54+
"@types/node": "^22.13.4",
5255
"@typescript-eslint/eslint-plugin": "^5.62.0",
5356
"@typescript-eslint/parser": "^5.62.0",
5457
"eslint": "^8.48.0",
@@ -57,6 +60,9 @@
5760
"eslint-plugin-node": "^8.0.1",
5861
"eslint-plugin-promise": "^4.3.1",
5962
"eslint-plugin-standard": "^4.1.0",
63+
"jest": "^29.7.0",
64+
"jest-environment-jsdom": "^29.7.0",
65+
"jsdom": "^26.0.0",
6066
"rollup": "^2.79.1",
6167
"rollup-plugin-eslint": "^5.1.0",
6268
"rollup-plugin-filesize": "^9.1.2",
@@ -66,15 +72,17 @@
6672
"rollup-plugin-sizes": "^0.4.2",
6773
"rollup-plugin-terser": "^7.0.2",
6874
"rollup-plugin-typescript2": "^0.34.1",
69-
"sass": "^1.66.1"
75+
"sass": "^1.66.1",
76+
"ts-jest": "^29.2.5"
7077
},
7178
"commonjs": [
7279
"node_modules/**"
7380
],
7481
"scripts": {
7582
"build": "rollup -c rollup.config.js",
7683
"devw": "rollup -w -c rollup.config.js",
77-
"test": "npm run test --prefix ./test"
84+
"test": "jest --config jest.config.js",
85+
"lint": "eslint src --ext .js,.ts"
7886
},
7987
"browserslist": "> 0.25%, not dead"
8088
}

src/Tour.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
import u, { U } from "umbrellajs";
22

3-
import { AbstractStep, StepData } from "../@types/Step";
43
import MemoryCacheManager from "./cachemanager/InMemoryCacheManager";
54
import Guidedtour, {
65
CacheKeys,
76
KeyboardNavigationOptions,
8-
StepsSource, TourOptions,
7+
TourOptions,
98
TourStyle,
109
TourAction,
1110
Helpers,
1211
CacheManager,
1312
Direction,
14-
TourStopState
15-
} from "../@types";
13+
TourStopState,
14+
AbstractStep,
15+
StepData,
16+
StepsSource,
17+
} from "@types";
1618
import { assert, clamp, getMaxZIndex, Style, Scroll, Color } from "./utils";
1719
import * as Utils from "./utils";
1820
import * as Abstracts from "./abstracts";
@@ -27,7 +29,7 @@ import CardStep from "./step/CardStep";
2729
import BaseStyle from "./Tour.scss";
2830
import { getDataContents } from "./utils/dom";
2931

30-
const defaultKeyNavOptions: KeyboardNavigationOptions = {
32+
export const defaultKeyNavOptions: KeyboardNavigationOptions = {
3133
next: "ArrowRight",
3234
prev: "ArrowLeft",
3335
first: "Home",
@@ -36,7 +38,7 @@ const defaultKeyNavOptions: KeyboardNavigationOptions = {
3638
stop: "Escape",
3739
};
3840

39-
const defaultStyle: TourStyle = {
41+
export const defaultStyle: TourStyle = {
4042
fontFamily: "sans-serif",
4143
fontSize: "14px",
4244

@@ -57,7 +59,7 @@ const defaultStyle: TourStyle = {
5759
stepCardPadding: "5px",
5860
};
5961

60-
const defaultOptions: TourOptions = {
62+
export const defaultOptions: TourOptions = {
6163
identifier: "default",
6264
root: "body",
6365
selector: "[data-tour]",

src/abstracts/CacheManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { CacheManager } from "../../@types";
1+
import { CacheManager } from "@types";
22

33
export abstract class AbstractCacheManager implements CacheManager {
44
constructor(identifier = "") {

src/abstracts/Step.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Element } from "umbrellajs";
22
import {GUID} from "../utils/guid";
3-
import Tour, { AbstractStep, StepData } from "../../@types";
3+
import Tour, { AbstractStep, StepData } from "@types";
44

55
export abstract class Step<StepDataType = StepData> implements AbstractStep<StepDataType> {
66
static Type = "default";

src/decorator/ContentDecorator.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Tour from "../../@types";
1+
import Tour from "@types";
22

33
export interface Match {
44
match: string;
@@ -62,4 +62,4 @@ export class ContentDecorator {
6262
return text;
6363
}
6464
}
65-
}
65+
}

src/handler/ActionHandler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Tour, { ActionHandlerType, TourAction } from "../../@types";
1+
import Tour, { ActionHandlerType, TourAction } from "@types";
22

33
export type ActionHandlerFn = (event: Event, action: TourAction, context: Tour) => void;
44

src/lib/snarkdown.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,17 @@ function encodeAttr(str: string): string {
5454
* Parse Markdown into an HTML String.
5555
*/
5656
export default function parse(md: string, prevLinks?: Record<string, string>): string {
57-
let tokenizer = /((?:^|\n+)(?:\n---+|\* \*(?: \*)+)\n)|(?:^``` *(\w*)\n([\s\S]*?)\n```$)|((?:(?:^|\n+)(?:\t| {2,}).+)+\n*)|((?:(?:^|\n)([>*+-]|\d+\.)\s+.*)+)|(?:!\[([^\]]*?)\]\(([^)]+?)\))|(\[)|(\](?:\(([^)]+?)\))?)|(?:(?:^|\n+)([^\s].*)\n(-{3,}|={3,})(?:\n+|$))|(?:(?:^|\n+)(#{1,6})\s*(.+)(?:\n+|$))|(?:`([^`].*?)`)|( \n\n*|\n{2,}|__|\*\*|[_*]|~~)/gm;
58-
let context: string[] = [];
59-
let out: string = '';
60-
let links: Record<string, string> = prevLinks || {};
61-
let last: number = 0;
57+
// eslint-disable-next-line no-regex-spaces
58+
const tokenizer = /((?:^|\n+)(?:\n---+|\* \*(?: \*)+)\n)|(?:^``` *(\w*)\n([\s\S]*?)\n```$)|((?:(?:^|\n+)(?:\t| {2,}).+)+\n*)|((?:(?:^|\n)([>*+-]|\d+\.)\s+.*)+)|(?:!\[([^\]]*?)\]\(([^)]+?)\))|(\[)|(\](?:\(([^)]+?)\))?)|(?:(?:^|\n+)([^\s].*)\n(-{3,}|={3,})(?:\n+|$))|(?:(?:^|\n+)(#{1,6})\s*(.+)(?:\n+|$))|(?:`([^`].*?)`)|( \n\n*|\n{2,}|__|\*\*|[_*]|~~)/gm;
59+
const context: string[] = [];
60+
let out = '';
61+
const links: Record<string, string> = prevLinks || {};
62+
let last = 0;
6263
let chunk: string | null = null;
63-
let prev: string = '';
64+
let prev = '';
6465
let token: RegExpExecArray | null = null;
65-
let inner: string = ''
66-
let t: string = '';
66+
let inner = ''
67+
let t = '';
6768

6869
function tag(token: string): string {
6970
const desc: string[] = TAGS[token[1] || ''];
@@ -76,7 +77,7 @@ export default function parse(md: string, prevLinks?: Record<string, string>): s
7677
}
7778

7879
function flush(): string {
79-
let str: string = '';
80+
let str = '';
8081
while (context.length > 0) str += tag(context[context.length - 1]);
8182
return str;
8283
}
@@ -94,6 +95,7 @@ export default function parse(md: string, prevLinks?: Record<string, string>): s
9495
// escaped
9596
}
9697
// Code/Indent blocks:
98+
// eslint-disable-next-line no-cond-assign
9799
else if (t = (token[3] || token[4])) {
98100
chunk = '<pre class="code '
99101
+ (token[4]
@@ -110,6 +112,7 @@ export default function parse(md: string, prevLinks?: Record<string, string>): s
110112
+ '</code></pre>';
111113
}
112114
// > Quotes, -* lists:
115+
// eslint-disable-next-line no-cond-assign
113116
else if (t = token[6]) {
114117
if (t.match(/\./)) {
115118
token[5] = token[5].replace(/^\d+/gm, '');

src/step/PopoverStep.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// import scrollIntoView from "scroll-into-view";
2-
import Tour, { AbstractStep, StepData } from "../../@types";
2+
import Tour, { AbstractStep, StepData } from "@types";
33
import { Element, U } from "umbrellajs";
44

55
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
@@ -20,7 +20,7 @@ export interface PopoverStepData extends StepData {
2020
navigation: boolean;
2121
}
2222

23-
const popoverStepDataDefaults: PopoverStepData = {
23+
export const popoverStepDataDefaults: PopoverStepData = {
2424
layout: "vertical",
2525
image: "",
2626
title: "",

src/utils/clamp.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export function clamp(value: number, min: number, max = NaN): number {
1+
export function clamp(value: number, min = NaN, max = NaN): number {
22
min = isNaN(min) ? value : min;
33
max = isNaN(max) ? value : max;
44
return Math.max(min, Math.min(value, max));

0 commit comments

Comments
 (0)