Skip to content

Commit

Permalink
test(convert): Added vitest, tests and tsconfig settings
Browse files Browse the repository at this point in the history
Merge pull request #3 from itpropro/feat/test
  • Loading branch information
Intevel committed Jul 5, 2022
2 parents cc435d7 + bcd8fd9 commit 1945f0b
Show file tree
Hide file tree
Showing 8 changed files with 611 additions and 33 deletions.
9 changes: 9 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"parserOptions": {
"ecmaVersion": 2021,
"sourceType": "module"
},
"env": {
"es6": true
}
}
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,16 @@
"scripts": {
"build": "unbuild",
"lint": "eslint --ext .ts .",
"release": "yarn build && standard-version && git push --follow-tags && npm publish"
},
"dependencies": {
"typescript": "^4.6.3"
"release": "yarn build && standard-version && git push --follow-tags && npm publish",
"typecheck": "tsc --noEmit",
"test": "vitest"
},
"devDependencies": {
"@types/node": "^17.0.23",
"eslint": "^8.12.0",
"standard-version": "^9.3.2",
"unbuild": "^0.7.4"
"typescript": "^4.6.3",
"unbuild": "^0.7.4",
"vitest": "^0.17.0"
}
}
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,4 @@ export function convert(content: string, withSpace?: boolean) {
return gitmojis[matched.toLowerCase()];
}
})
}
}
329 changes: 329 additions & 0 deletions test/convert.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,329 @@
import { describe, expect, it } from 'vitest';
import { convert } from '../src';

const gitmojis = [
{
emoji: "🎨",
code: ":art:",
},
{
emoji: "⚡️",
code: ":zap:",
},
{
emoji: "🔥",
code: ":fire:",
},
{
emoji: "🐛",
code: ":bug:",
},
{
emoji: "🚑️",
code: ":ambulance:",
},
{
emoji: "✨",
code: ":sparkles:",
},
{
emoji: "📝",
code: ":memo:",
},
{
emoji: "🚀",
code: ":rocket:",
},
{
emoji: "💄",
code: ":lipstick:",
},
{
emoji: "🎉",
code: ":tada:",
},
{
emoji: "✅",
code: ":white_check_mark:",
},
{
emoji: "🔒️",
code: ":lock:",
},
{
emoji: "🔐",
code: ":closed_lock_with_key:",
},
{
emoji: "🔖",
code: ":bookmark:",
},
{
emoji: "🚨",
code: ":rotating_light:",
},
{
emoji: "🚧",
code: ":construction:",
},
{
emoji: "💚",
code: ":green_heart:",
},
{
emoji: "⬇️",
code: ":arrow_down:",
},
{
emoji: "⬆️",
code: ":arrow_up:",
},
{
emoji: "📌",
code: ":pushpin:",
},
{
emoji: "👷",
code: ":construction_worker:",
},
{
emoji: "📈",
code: ":chart_with_upwards_trend:",
},
{
emoji: "♻️",
code: ":recycle:",
},
{
emoji: "➕",
code: ":heavy_plus_sign:",
},
{
emoji: "➖",
code: ":heavy_minus_sign:",
},
{
emoji: "🔧",
code: ":wrench:",
},
{
emoji: "🔨",
code: ":hammer:",
},
{
emoji: "🌐",
code: ":globe_with_meridians:",
},
{
emoji: "✏️",
code: ":pencil2:",
},
{
emoji: "💩",
code: ":poop:",
},
{
emoji: "⏪️",
code: ":rewind:",
},
{
emoji: "🔀",
code: ":twisted_rightwards_arrows:",
},
{
emoji: "📦️",
code: ":package:",
},
{
emoji: "👽️",
code: ":alien:",
},
{
emoji: "🚚",
code: ":truck:",
},
{
emoji: "📄",
code: ":page_facing_up:",
},
{
emoji: "💥",
code: ":boom:",
},
{
emoji: "🍱",
code: ":bento:",
},
{
emoji: "♿️",
code: ":wheelchair:",
},
{
emoji: "💡",
code: ":bulb:",
},
{
emoji: "🍻",
code: ":beers:",
},
{
emoji: "💬",
code: ":speech_balloon:",
},
{
emoji: "🗃️",
code: ":card_file_box:",
},
{
emoji: "🔊",
code: ":loud_sound:",
},
{
emoji: "🔇",
code: ":mute:",
},
{
emoji: "👥",
code: ":busts_in_silhouette:",
},
{
emoji: "🚸",
code: ":children_crossing:",
},
{
emoji: "🏗️",
code: ":building_construction:",
},
{
emoji: "📱",
code: ":iphone:",
},
{
emoji: "🤡",
code: ":clown_face:",
},
{
emoji: "🥚",
code: ":egg:",
},
{
emoji: "🙈",
code: ":see_no_evil:",
},
{
emoji: "📸",
code: ":camera_flash:",
},
{
emoji: "⚗️",
code: ":alembic:",
},
{
emoji: "🔍️",
code: ":mag:",
},
{
emoji: "🏷️",
code: ":label:",
},
{
emoji: "🌱",
code: ":seedling:",
},
{
emoji: "🚩",
code: ":triangular_flag_on_post:",
},
{
emoji: "🥅",
code: ":goal_net:",
},
{
emoji: "💫",
code: ":dizzy:",
},
{
emoji: "🗑️",
code: ":wastebasket:",
},
{
emoji: "🛂",
code: ":passport_control:",
},
{
emoji: "🩹",
code: ":adhesive_bandage:",
},
{
emoji: "🧐",
code: ":monocle_face:",
},
{
emoji: "⚰️",
code: ":coffin:",
},
{
emoji: "🧪",
code: ":test_tube:",
},
{
emoji: "👔",
code: ":necktie:",
},
{
emoji: "🩺",
code: ":stethoscope:",
},
{
emoji: "🧱",
code: ":bricks:",
},
{
emoji: "🧑‍💻",
code: ":technologist:",
},
{
emoji: "💸",
code: ":money_with_wings:",
}
];

const content = ":arrow_up: bump qs from 6.10.3 to 6.10.4 (xxx) - **helper:** :zap: Updated TSDoc (xxx) ";
const contentWithGitmoji = "⬆️ bump qs from 6.10.3 to 6.10.4 (xxx) - **helper:** ⚡️ Updated TSDoc (xxx) ";

const pencil = "this is :pencil: 1 and this is :pencil2:"
const pencilWithGitmoji = "this is ✏️ 1 and this is ✏️"

describe('convert', () => {
it('should be defined', () => {
expect(convert).toBeDefined;
});

it('should return the correct gitmoji for every string', () => {
let gitmojisEqual = true;
for (const gitmoji of gitmojis) {
gitmojisEqual = convert(gitmoji.code) === gitmoji.emoji || gitmojisEqual;
}
expect(gitmojisEqual).toBe(true);
});

it('should generate space', () => {
const gitmojiWithSpace = convert(gitmojis[0].code, true);
expect(gitmojiWithSpace).toBe(`${gitmojis[0].emoji} `);
});

it('should not generate space', () => {
const gitmojiWithSpace = convert(gitmojis[0].code, false);
expect(gitmojiWithSpace).toBe(`${gitmojis[0].emoji}`);
});

it('should replace multiple strings', () => {
const result = convert(content);
expect(result).toBe(contentWithGitmoji);
});

it('should replace pencil and pencil2', () => {
const result = convert(pencil);
expect(result).toBe(pencilWithGitmoji);
});
});
7 changes: 0 additions & 7 deletions test/index.js

This file was deleted.

15 changes: 0 additions & 15 deletions test/package.json

This file was deleted.

Loading

0 comments on commit 1945f0b

Please sign in to comment.