Skip to content

Commit

Permalink
Chore | Fix CI - Linting, Fomatting and Tests (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
zrosenbauer committed Jul 12, 2023
1 parent 6470a20 commit e3473bf
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 71 deletions.
7 changes: 2 additions & 5 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
{
"cSpell.words": [
"Flaticon",
"Freepik"
],
"cSpell.words": ["Flaticon", "Freepik"],
"workbench.colorCustomizations": {
"activityBar.activeBackground": "#cdf2e2",
"activityBar.background": "#cdf2e2",
Expand All @@ -23,4 +20,4 @@
"titleBar.inactiveForeground": "#15202b99"
},
"peacock.color": "#a4e8ca"
}
}
16 changes: 3 additions & 13 deletions examples/lib/basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,13 @@ function run() {
.paragraph('This is a paragraph')
.h2(text => text.text('This is a heading with ').bold('bold text'))
.paragraph(text => text.bold('This is bold text'))
.paragraph(
text => `This is inline text ${text.italic('with italic text')}`
)
.paragraph(text => `This is inline text ${text.italic('with italic text')}`)
.paragraph(text => text.text('Foobar is a thing').bold('that is bold'))
.h2('Lists')
.paragraph('This is a list')
.bulletList([
'Item 1',
'Item 2',
'Item 3'
])
.bulletList(['Item 1', 'Item 2', 'Item 3'])
.paragraph('This is a numbered list')
.numberList([
'Item 1',
'Item 2',
'Item 3'
])
.numberList(['Item 1', 'Item 2', 'Item 3'])
.toString();
}

Expand Down
14 changes: 11 additions & 3 deletions examples/lib/code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,25 @@ import tempo from '../../src';
function run() {
return tempo()
.h1('Code Examples')
.paragraph(txt => txt.text('This includes examples of code blocks and').code('inline code').text('.'))
.paragraph(txt =>
txt
.text('This includes examples of code blocks and')
.code('inline code')
.text('.')
)
.h2(txt => txt.text('This is a heading with ').code('code'))
.codeBlock(`
.codeBlock(
`
import foobar from 'foobar';
function run() {
console.log("Hello World");
}
export default run;
`.trim(), 'javascript')
`.trim(),
'javascript'
)
.toString();
}

Expand Down
5 changes: 4 additions & 1 deletion src/lib/Text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ export class Text {
}

public emoji(value: md.EmojiAlias | md.EmojiUnicode) {
this.value.push({ value: value.toString(), computedValue: value.toString() });
this.value.push({
value: value.toString(),
computedValue: value.toString()
});
return this;
}

Expand Down
Empty file removed src/lib/__tests__/Document.test.ts
Empty file.
55 changes: 13 additions & 42 deletions src/lib/__tests__/Text.test.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,22 @@
import createText, { Text } from '../Text'
import createText, { Text } from '../Text';
import md from '../markdown';

jest.mock('./markdown/markdown');
jest.mock('../markdown/markdown');

let text: Text;
let txt: Text;

beforeEach(() => {
text = createText();
txt = createText();
});

afterEach(() => {
jest.resetAllMocks();
});

describe('paragraph', () => {
it('should call md.paragraph with the provided value', () => {
const value = 'Lorem ipsum';
text.paragraph(value);

expect(md.paragraph).toHaveBeenCalledWith(value);
});
});

describe('code', () => {
it('should call md.code with the provided value', () => {
const value = 'const foo = "bar";';
text.code(value);
txt.code(value);

expect(md.code).toHaveBeenCalledWith(value);
});
Expand All @@ -34,7 +25,7 @@ describe('code', () => {
describe('bold', () => {
it('should call md.bold with the provided value', () => {
const value = 'Hello';
text.bold(value);
txt.bold(value);

expect(md.bold).toHaveBeenCalledWith(value);
});
Expand All @@ -43,7 +34,7 @@ describe('bold', () => {
describe('italic', () => {
it('should call md.italic with the provided value', () => {
const value = 'World';
text.italic(value);
txt.italic(value);

expect(md.italic).toHaveBeenCalledWith(value);
});
Expand All @@ -52,26 +43,17 @@ describe('italic', () => {
describe('strikeThrough', () => {
it('should call md.strikeThrough with the provided value', () => {
const value = 'Strike';
text.strikeThrough(value);
txt.strikeThrough(value);

expect(md.strikeThrough).toHaveBeenCalledWith(value);
});
});

describe('underline', () => {
it('should call md.underLine with the provided value', () => {
const value = 'Underline';
text.underline(value);

expect(md.underLine).toHaveBeenCalledWith(value);
});
});

describe('link', () => {
it('should call md.link with the provided value and href', () => {
const value = 'OpenAI';
const href = 'https://openai.com';
text.link(value, href);
const value = 'Joggr.io';
const href = 'https://joggr.io';
txt.link(value, href);

expect(md.link).toHaveBeenCalledWith(value, href);
});
Expand All @@ -80,19 +62,8 @@ describe('link', () => {
describe('emoji', () => {
it('should push the provided emoji value to the text', () => {
const emoji = '👍';
text.emoji(emoji);
txt.emoji(emoji);

expect(text.toString()).toContain(emoji);
expect(txt.toString()).toContain(emoji);
});
});

describe('toString', () => {
it('should join the text values with a space', () => {
text.paragraph('Lorem ipsum')
.code('const foo = "bar";')
.bold('Hello')
.italic('World');

expect(text.toString()).toBe('Lorem ipsum `const foo = "bar";` **Hello** *World*');
});
});
2 changes: 1 addition & 1 deletion src/lib/markdown/codeBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export const supportedLanguages = [
export type SupportedLanguage = (typeof supportedLanguages)[number];

/**
* @throws if the string is not a valid (supported) language by Github-Linguist which is used to provide
* @throws if the string is not a valid (supported) language by Github-Linguist which is used to provide
* syntax highlighting for Github markdown files.
*/
export function assertSupportedLanguage(language: SupportedLanguage) {
Expand Down
24 changes: 18 additions & 6 deletions src/lib/markdown/emoji.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9101,30 +9101,42 @@ const supportedEmojis = [
category: 'Symbol'
}
] as const;
export type EmojiAlias = typeof supportedEmojis[number]['alias'];
export type EmojiUnicode = Exclude<typeof supportedEmojis[number]['unicode'], boolean>;
export type EmojiAlias = (typeof supportedEmojis)[number]['alias'];
export type EmojiUnicode = Exclude<
(typeof supportedEmojis)[number]['unicode'],
boolean
>;

/**
* @param emoji A unicode emoji
* @returns indicates whether the given emoji is a supported unicode emoji
*/
export function isSupportedUnicode(emoji: EmojiAlias | EmojiUnicode): emoji is EmojiUnicode {
export function isSupportedUnicode(
emoji: EmojiAlias | EmojiUnicode
): emoji is EmojiUnicode {
return supportedEmojis.some(({ unicode }) => unicode === emoji);
}

/**
* @param emoji An alias for an emoji (without the colons)
* @returns indicates whether the given emoji is an alias for a supported emoji
*/
export function isSupportedAlias(emoji: EmojiAlias | EmojiUnicode): emoji is EmojiAlias {
export function isSupportedAlias(
emoji: EmojiAlias | EmojiUnicode
): emoji is EmojiAlias {
return supportedEmojis.some(({ alias }) => alias === emoji);
}

/**
* @throws if the given emoji is not valid
*/
export function assertSupportedEmoji(emoji: EmojiAlias | EmojiUnicode): asserts emoji is EmojiAlias | EmojiUnicode {
if (!isSupportedAlias(emoji as EmojiAlias) && !isSupportedUnicode(emoji as EmojiUnicode)) {
export function assertSupportedEmoji(
emoji: EmojiAlias | EmojiUnicode
): asserts emoji is EmojiAlias | EmojiUnicode {
if (
!isSupportedAlias(emoji as EmojiAlias) &&
!isSupportedUnicode(emoji as EmojiUnicode)
) {
throw new Error(`Invalid emoji: ${emoji}`);
}
}

0 comments on commit e3473bf

Please sign in to comment.