Skip to content
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
4 changes: 4 additions & 0 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ Makes sure all files are properly formatted, rewriting them if necessary. Usuall

Lints files! Currently ESLint is the only linter, but it would be nice to have more. Perhaps you'd like to [add another one](CONTRIBUTING.md)?

### `yarn test`

For the packages that have tests, runs those tests!

### `yarn typecheck`

Checks the type correctness of the code. Currently only TypeScript files are checked, using the TypeScript compiler. Java and Kotlin code in the [Adventure Pack](workspaces/adventure-pack/) is checked indirectly, when we attempt to compile it.
2 changes: 1 addition & 1 deletion workspaces/repository-scripts/src/scripts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const SCRIPTS = {
for await (const modifiedFile of getCurrentGitRepositoryStatusPaths()) {
++modifiedFileCount;

// TODO: utility
// Documentation: https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/workflow-commands-for-github-actions#setting-an-error-message
console.log(
`::error file=${modifiedFile},title=Formatting error::This file does not respect the repository's formatting rules.%0ARun \`yarn format\` in the repository root to auto-fix it.`,
Expand Down Expand Up @@ -75,5 +76,4 @@ export const SCRIPTS_TO_SKIP_BY_WORKSPACE: Readonly<
"leetcode-api": new Set(["test"]),
"post-leetcode-potd-to-discord": new Set(["test"]),
"repository-scripts": new Set(["test"]),
util: new Set(["test"]),
};
2 changes: 1 addition & 1 deletion workspaces/util/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ console.log(stripPrefix("hello", "how"));

Like the rest of the [Code Chronicles Leetcode ecosystem](../../), this package is structured as a Node module, using [classic Yarn](https://classic.yarnpkg.com/) as the package manager.

You can install dependencies by running `yarn`, either in this package's directory, or in the repository root. The usual `yarn format`, `yarn lint`, and `yarn typecheck` scripts are available to aid in development and occasionally to annoy.
You can install dependencies by running `yarn`, either in this package's directory, or in the repository root. The usual `yarn format`, `yarn lint`, and `yarn typecheck` scripts are available to aid in development and occasionally to annoy. `yarn test` is also available, though we could definitely use more tests!

See also the repository's general [development guide](../../DEVELOPMENT.md).
8 changes: 8 additions & 0 deletions workspaces/util/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 = {
preset: "ts-jest",
testEnvironment: "node",
};

export default config;
7 changes: 6 additions & 1 deletion workspaces/util/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
"url": "https://github.com/miorel"
},
"exports": {
"./*": "./src/*.ts"
"./*": "./src/*.ts",
"./__tests__/*": null
},
"scripts": {
"format": "prettier --color --write .",
"lint": "eslint --color --max-warnings=0 .",
"test": "jest --color .",
"typecheck": "tsc --pretty --project ."
},
"dependencies": {
Expand All @@ -27,9 +29,12 @@
},
"devDependencies": {
"@code-chronicles/eslint-config": "0.0.1",
"@jest/globals": "29.7.0",
"@types/node": "22.1.0",
"eslint": "9.8.0",
"jest": "29.7.0",
"prettier": "3.3.3",
"ts-jest": "29.2.4",
"type-fest": "4.23.0",
"typescript": "5.5.4"
}
Expand Down
50 changes: 50 additions & 0 deletions workspaces/util/src/__tests__/stripPrefix-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { describe, expect, it } from "@jest/globals";

import { stripPrefix } from "../stripPrefix";

describe("stripPrefix", () => {
it("removes the prefix if it exists", () => {
expect(stripPrefix("hello world", "hello")).toBe(" world");
});

it("returns an unmodified string if the prefix doesn't exist", () => {
expect(stripPrefix("hello world", "goodbye")).toBe("hello world");
});

it("returns an empty string if the entire string is the prefix", () => {
expect(stripPrefix("hello", "hello")).toBe("");
});

it("tolerates an empty string", () => {
expect(stripPrefix("", "prefix")).toBe("");
});

it("complains about an empty prefix", () => {
expect(() => stripPrefix("hello", "")).toThrow();
});

it("respects case", () => {
expect(stripPrefix("Hello World", "hello")).toBe("Hello World");
});

it("tolerates prefixes that are longer than the string", () => {
expect(stripPrefix("hi", "hello")).toBe("hi");
});

it("works with multiline strings", () => {
expect(stripPrefix("hello\nworld\nhow\nare\nyou", "hello\nwo")).toBe(
"rld\nhow\nare\nyou",
);
});

it("only removes the prefix once", () => {
expect(stripPrefix("hahaha", "ha")).toBe("haha");
});

it("works with emojis", () => {
expect(stripPrefix("🍎apple", "🍎")).toBe("apple");
expect(stripPrefix("🍌banana", "🍌")).toBe("banana");
expect(stripPrefix("grapes🍇🍇", "grapes")).toBe("🍇🍇");
expect(stripPrefix("🍉watermelon🍉", "🍉watermelon")).toBe("🍉");
});
});
15 changes: 15 additions & 0 deletions yarn.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.