Skip to content

Commit

Permalink
test: use node --test
Browse files Browse the repository at this point in the history
Don't install another devDependency for something that is built in now
  • Loading branch information
EdJoPaTo committed Nov 27, 2023
1 parent a4da7a2 commit 00d5756
Show file tree
Hide file tree
Showing 5 changed files with 211 additions and 193 deletions.
17 changes: 8 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"scripts": {
"build": "del-cli dist && tsc",
"prepack": "npm run build",
"test": "tsc --sourceMap && xo && c8 --all ava"
"test": "tsc --sourceMap && xo && c8 --all node --test --enable-source-maps"
},
"type": "module",
"engines": {
Expand All @@ -38,26 +38,25 @@
},
"devDependencies": {
"@sindresorhus/tsconfig": "^5.0.0",
"@types/node": "^14.18.22",
"ava": "^5.0.1",
"@types/node": "^18.18.13",
"c8": "^8.0.1",
"del-cli": "^5.0.0",
"grammy": "^1.10.1",
"typescript": "^5.0.2",
"xo": "^0.56.0"
},
"files": [
"dist/source",
"!*.test.*"
"dist",
"!*.test.*",
"!test.*"
],
"main": "./dist/source/index.js",
"types": "./dist/source/index.d.ts",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"xo": {
"space": 2,
"rules": {
"@typescript-eslint/naming-convention": "off",
"@typescript-eslint/prefer-readonly-parameter-types": "off",
"ava/no-ignored-test-files": "off"
"@typescript-eslint/prefer-readonly-parameter-types": "off"
},
"overrides": [
{
Expand Down
66 changes: 66 additions & 0 deletions source/identifier.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import {strictEqual} from 'node:assert';
import {test} from 'node:test';
import {suffixHTML, suffixMarkdown, suffixMarkdownV2} from './identifier.js';

await test('messageSuffixMarkdown', () => {
strictEqual(
suffixMarkdown('unicorns', undefined),
'[\u200C](http://t.me/#unicorns#)',
);
});

await test('messageSuffixMarkdown with additional state', () => {
strictEqual(
suffixMarkdown('unicorns', 'explode'),
'[\u200C](http://t.me/#unicorns#explode)',
);
});

await test('messageSuffixMarkdown additional state gets url encoded correctly', () => {
strictEqual(
suffixMarkdown('unicorns', 'foo bar'),
'[\u200C](http://t.me/#unicorns#foo%20bar)',
);
});

await test('messageSuffixMarkdownV2', () => {
strictEqual(
suffixMarkdownV2('unicorns', undefined),
'[\u200C](http://t.me/#unicorns#)',
);
});

await test('messageSuffixMarkdownV2 with additional state', () => {
strictEqual(
suffixMarkdownV2('unicorns', 'explode'),
'[\u200C](http://t.me/#unicorns#explode)',
);
});

await test('messageSuffixMarkdownV2 additional state gets url encoded correctly', () => {
strictEqual(
suffixMarkdownV2('unicorns', 'foo bar'),
'[\u200C](http://t.me/#unicorns#foo%20bar)',
);
});

await test('messageSuffixHTML', () => {
strictEqual(
suffixHTML('unicorns', undefined),
'<a href="http://t.me/#unicorns#">\u200C</a>',
);
});

await test('messageSuffixHTML with additional state', () => {
strictEqual(
suffixHTML('unicorns', 'explode'),
'<a href="http://t.me/#unicorns#explode">\u200C</a>',
);
});

await test('messageSuffixHTML additional state gets url encoded correctly', () => {
strictEqual(
suffixHTML('unicorns', 'foo bar'),
'<a href="http://t.me/#unicorns#foo%20bar">\u200C</a>',
);
});
9 changes: 5 additions & 4 deletions source/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ import {
} from './identifier.js';

type ConstOrPromise<T> = T | Promise<T>;
export type AnswerFunction<Context extends BaseContext> = (
context: ReplyToMessageContext<Context>,
additionalState: string,
) => ConstOrPromise<void>;

export class StatelessQuestion<Context extends BaseContext> {
constructor(
public readonly uniqueIdentifier: string,
private readonly answer: (
context: ReplyToMessageContext<Context>,
additionalState: string,
) => ConstOrPromise<void>,
private readonly answer: AnswerFunction<Context>,
) {}

middleware(): (context: Context, next: () => Promise<void>) => Promise<void> {
Expand Down
Loading

0 comments on commit 00d5756

Please sign in to comment.