Skip to content

Commit

Permalink
add initial tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ishubham21 committed Jul 24, 2022
1 parent 70f4d98 commit b5bc742
Show file tree
Hide file tree
Showing 11 changed files with 2,706 additions and 28 deletions.
13 changes: 13 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"presets": [
[
"@babel/preset-env",
{
"targets": {
"node": "current"
}
}
],
"@babel/preset-typescript"
]
}
3 changes: 2 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/node_modules
/dist
/build
/public
/public
/tests
31 changes: 31 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Runs all the tests
name: Test Pull Requests

on:
pull_request:
branches: [ ]
push:
branches: [ main ]

jobs:
build:
name: Run tests
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x]

steps:
- uses: actions/checkout@v3

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'yarn'

- name: Install dependencies
run: yarn --frozen-lockfile

- name: Run tests
run: yarn test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ yarn-debug.log*
yarn-error.log*
lerna-debug.log*

/dist
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

Expand Down
2 changes: 1 addition & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
/dist
/public
/public
5 changes: 5 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
testEnvironment: "node", //deafult is jsdom i.e test envrionment
testRegex: "/tests/.*\\.(test|spec)?\\.(ts)$", //under test folder, file names should be tests/newTest.test(spec).ts
moduleFileExtensions: ["ts", "js", "json", "node"],
};
14 changes: 12 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@
"name": "cube-markdown-parser",
"version": "0.0.1",
"description": "This package provide function that help in parsing markdown files",
"main": "index.js",
"main": "./src/index.ts",
"repository": {
"type": "git",
"url": "git+https://github.com/ishubham21/cube-package.git"
},
"author": "Shubham Gautam <https://meshubham.live>",
"license": "MIT",
"scripts": {
"test": "jest",
"test:coverage": "jest --coverage",
"build:tsc": "rm -rf ./dist && tsc",
"build:sucrase": "rm -rf ./dist && sucrase ./src -d ./dist --transforms typescript,imports",
"format": "prettier --write \"**/*.{js,ts}\"",
Expand All @@ -23,13 +25,21 @@
"typescript": "^4.7.4"
},
"devDependencies": {
"@babel/core": "^7.18.9",
"@babel/preset-env": "^7.18.9",
"@babel/preset-typescript": "^7.18.6",
"@types/node": "^18.0.6",
"@typescript-eslint/eslint-plugin": "^5.30.7",
"@typescript-eslint/parser": "^5.30.7",
"babel-jest": "^28.1.3",
"eslint": "^8.20.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-no-loops": "^0.3.0",
"jest": "^28.1.3",
"nodemon": "^2.0.19"
},
"publishConfig": {
"registry": "https://npm.pkg.github.com/@ishubham21"
}
}
}
1 change: 1 addition & 0 deletions src/core/parser-core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const parseMarkdownWithoutWrapper = (
* (##### => h5)
* (###### => h6)
*/
//TODO: Handling trailing white-spaces
.replace(/[\#]{6}(.+)/g, "<h6>$1</h6>")
.replace(/[\#]{5}(.+)/g, "<h5>$1</h5>")
.replace(/[\#]{4}(.+)/g, "<h4>$1</h4>")
Expand Down
63 changes: 63 additions & 0 deletions tests/parser-main.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import {
Markdown,
ParsedMarkdown,
parseMarkdownWithoutWrapper,
} from "../src/index";

describe("parser behaviour over different markdown commands", () => {
describe("parse headings", () => {
it("should parse h1", () => {
const markdown: Markdown = "#h1";
const expectedParsedMarkdown: Markdown = `<h1>h1</h1>`;

expect(parseMarkdownWithoutWrapper(markdown)).toEqual(
expectedParsedMarkdown,
);
});

it("should parse h2", () => {
const markdown: Markdown = "##h2";
const expectedParsedMarkdown: Markdown = `<h2>h2</h2>`;

expect(parseMarkdownWithoutWrapper(markdown)).toEqual(
expectedParsedMarkdown,
);
});

it("should parse h3", () => {
const markdown: Markdown = "###h3";
const expectedParsedMarkdown: Markdown = `<h3>h3</h3>`;

expect(parseMarkdownWithoutWrapper(markdown)).toEqual(
expectedParsedMarkdown,
);
});

it("should parse h4", () => {
const markdown: Markdown = "####h4";
const expectedParsedMarkdown: Markdown = `<h4>h4</h4>`;

expect(parseMarkdownWithoutWrapper(markdown)).toEqual(
expectedParsedMarkdown,
);
});

it("should parse h5", () => {
const markdown: Markdown = "#####h5";
const expectedParsedMarkdown: Markdown = `<h5>h5</h5>`;

expect(parseMarkdownWithoutWrapper(markdown)).toEqual(
expectedParsedMarkdown,
);
});

it("should parse h6", () => {
const markdown: Markdown = "######h6";
const expectedParsedMarkdown: Markdown = `<h6>h6</h6>`;

expect(parseMarkdownWithoutWrapper(markdown)).toEqual(
expectedParsedMarkdown,
);
});
});
});
5 changes: 4 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
"strict": true,
},
"exclude": [
"./node_modules"
"./node_modules",
"tests",
"**/*.spec.ts",
"**/*.test.ts"
]
}
Loading

0 comments on commit b5bc742

Please sign in to comment.