Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add web tests #20

Merged
merged 4 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
build
.eslintignore
.eslintignore
babel.config.js
36 changes: 36 additions & 0 deletions .github/workflows/web.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Web

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

jobs:
build:
name: Validate Web
runs-on: ubuntu-latest

concurrency:
# When running on main, use the sha to allow all runs of this workflow to run concurrently.
# Otherwise only allow a single run of this workflow on each branch, automatically cancelling older runs.
group: ${{ github.workflow }}
cancel-in-progress: ${{ github.ref_name != 'main' }}

steps:
- uses: actions/checkout@v3

- uses: actions/setup-node@v3
with:
cache: "yarn"

- name: Setup
run: "./scripts/setup.sh"

- name: Build(typescript) check
run: yarn build

- name: Lint check
run: yarn lint

- name: Test check
run: yarn test
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ build/
DerivedData/
.swiftpm
.build/
*.js
node_modules
platforms/android/.idea/
platforms/android/.gradle
Expand Down
5 changes: 5 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
presets: [['@babel/preset-env', {targets: {node: `current`}}],
'@babel/preset-typescript',
],
};
8 changes: 8 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import type { Config } from "jest";

const config: Config = {
testEnvironment: "jsdom",
testMatch: ["<rootDir>/test/**/*-test.[jt]s?(x)"],
};

export default config;
10 changes: 9 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,27 @@
"build": "tsc",
"start": "ts-node ./src/build.ts",
"prepare": "yarn build && yarn start",
"lint": "eslint ."
"lint": "eslint .",
"test": "jest"
},
"devDependencies": {
"@babel/core": "^7.25.2",
"@babel/preset-env": "^7.25.4",
"@babel/preset-typescript": "^7.24.7",
"@types/jest": "^29.5.13",
"@types/node": "^20.4.7",
"@typescript-eslint/eslint-plugin": "^8.7.0",
"@typescript-eslint/parser": "^8.7.0",
"babel-jest": "^29.7.0",
"eslint": "8.57.1",
"eslint-config-google": "^0.14.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-import": "^2.30.0",
"eslint-plugin-matrix-org": "^1.2.1",
"eslint-plugin-prettier": "^5.2.1",
"eslint-plugin-unicorn": "^55.0.0",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"prettier": "^3.3.3",
"ts-node": "^10.9.1",
"typescript": "^5.1.6"
Expand Down
33 changes: 33 additions & 0 deletions test/emoji-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import {
DATA_BY_CATEGORY,
EMOJI,
EMOTICON_TO_EMOJI,
getEmojiFromUnicode,
} from "../src/emoji";

describe("Emojis", () => {
it("specific emoji", async () => {
const people = DATA_BY_CATEGORY.people;
const emoji = people.find((emoji) => emoji.label == "OK hand");
expect(emoji?.tags).toStrictEqual(["hand", "ok"]);
expect(emoji?.shortcodes).toStrictEqual(["ok_hand"]);
expect(emoji?.skins?.length).toBe(5);
expect(emoji?.skins?.slice(-1)?.pop()?.unicode).toBe("👌🏿");
});

it("that all emojis have shortcodes", async () => {
expect(
EMOJI.every((emoji) => emoji.shortcodes.pop() !== undefined),
).toBeTruthy();
});

it("that we can get an emoji by unicode", async () => {
expect(getEmojiFromUnicode("🙂")?.hexcode).toBe("1F642");
});
});

describe("Emoticons", () => {
it("should return an emoji", async () => {
expect(EMOTICON_TO_EMOJI.get(":)")?.hexcode).toBe("1F642");
});
});
Loading
Loading