8000 test: convert type tests to vitest syntax by luc122c Β· Pull Request #61 Β· unjs/scule Β· GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

test: convert type tests to vitest syntax #61

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

Merged
merged 4 commits into from
Nov 15, 2023
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ jobs:
- run: pnpm install
- run: pnpm lint
- run: pnpm build
- run: pnpm vitest --coverage
- run: pnpm vitest --coverage --typecheck
- uses: codecov/codecov-action@v3
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ types
*.log*
*.conf*
*.env*
tsconfig.vitest-temp.json
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,22 @@
],
"scripts": {
"build": "unbuild",
"dev": "vitest dev",
"dev": "vitest dev --typecheck",
"lint": "eslint --cache --ext .ts,.js,.mjs,.cjs . && prettier -c src test",
"lint:fix": "eslint --cache --ext .ts,.js,.mjs,.cjs . --fix && prettier -c src test -w",
"prepack": "pnpm run build",
"release": "pnpm test && changelogen --release --push && npm publish",
"test": "pnpm lint && vitest run --coverage"
"test": "pnpm lint && vitest run --typecheck --coverage"
},
"devDependencies": {
"@types/node": "^20.9.0",
"@vitest/coverage-v8": "^0.34.6",
"@vitest/coverage-v8": "^1.0.0-beta.4",
"eslint": "^8.53.0",
"eslint-config-unjs": "^0.2.1",
"prettier": "^3.1.0",
"typescript": "^5.2.2",
"unbuild": "^2.0.0",
"vitest": "^0.34.6"
"vitest": "^1.0.0-beta.4"
},
"packageManager": "pnpm@8.10.5"
}
96 changes: 39 additions & 57 deletions pnpm-lock.yaml

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

71 changes: 1 addition & 70 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
type Assert<T extends true> = T;
type Equal<X, Y> = (<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y
? 1
: 2
? true
: false;

type Splitter = "-" | "_" | "/" | ".";
type FirstOfString<S extends string> = S extends `${infer F}${string}`
? F
Expand Down Expand Up @@ -99,7 +92,7 @@ export type SplitByCase<
: string[]
: Accumulator;

type JoinByCase<T, Joiner extends string> = string extends T
export type JoinByCase<T, Joiner extends string> = string extends T
? string
: string[] extends T
? string
Expand Down Expand Up @@ -138,65 +131,3 @@ export type SnakeCase<T extends string | readonly string[]> = JoinByCase<
T,
"_"
>;

// eslint-disable-next-line @typescript-eslint/no-unused-vars
type __tests = [
// SplitByCase
Assert<Equal<SplitByCase<string>, string[]>>,
// default splitters
Assert<Equal<SplitByCase<"">, []>>,
Assert<Equal<SplitByCase<"foo">, ["foo"]>>,
Assert<Equal<SplitByCase<"foo_bar-baz/qux">, ["foo", "bar", "baz", "qux"]>>,
Assert<Equal<SplitByCase<"foo--bar-Baz">, ["foo", "", "bar", "Baz"]>>,
Assert<Equal<SplitByCase<"foo123-bar">, ["foo123", "bar"]>>,
Assert<Equal<SplitByCase<"fooBar">, ["foo", "Bar"]>>,
Assert<Equal<SplitByCase<"fooBARBaz">, ["foo", "BAR", "Baz"]>>,
Assert<Equal<SplitByCase<"FOOBar">, ["FOO", "Bar"]>>,
Assert<Equal<SplitByCase<"ALink">, ["A", "Link"]>>,
// custom splitters
Assert<
Equal<
SplitByCase<"foo\\Bar.fuzz-FIZz", "\\" | "." | "-">,
["foo", "Bar", "fuzz", "FI", "Zz"]
>
>,

// PascalCase
Assert<Equal<PascalCase<string>, string>>,
Assert<Equal<PascalCase<string[]>, string>>,
// string
Assert<Equal<PascalCase<"">, "">>,
Assert<Equal<PascalCase<"foo">, "Foo">>,
Assert<Equal<PascalCase<"foo-bAr">, "FooBAr">>,
Assert<Equal<PascalCase<"FooBARb">, "FooBARb">>,
Assert<Equal<PascalCase<"foo_bar-baz/qux">, "FooBarBazQux">>,
Assert<Equal<PascalCase<"foo--bar-Baz">, "FooBarBaz">>,
// array
Assert<Equal<PascalCase<["foo", "Bar"]>, "FooBar">>,
Assert<
Equal<PascalCase<["foo", "Bar", "fuzz", "FI", "Zz"]>, "FooBarFuzzFIZz">
>,

// CamelCase
Assert<Equal<CamelCase<string>, string>>,
Assert<Equal<CamelCase<string[]>, string>>,
// string
Assert<Equal<CamelCase<"">, "">>,
Assert<Equal<CamelCase<"foo">, "foo">>,
Assert<Equal<CamelCase<"FooBARb">, "fooBARb">>,
Assert<Equal<CamelCase<"foo_bar-baz/qux">, "fooBarBazQux">>,
// array
Assert<Equal<CamelCase<["Foo", "Bar"]>, "fooBar">>,

// JoinByCase
Assert<Equal<JoinByCase<string, "-">, string>>,
Assert<Equal<JoinByCase<string[], "-">, string>>,
// string
Assert<Equal<JoinByCase<"", "-">, "">>,
Assert<Equal<JoinByCase<"foo", "-">, "foo">>,
Assert<Equal<JoinByCase<"FooBARb", "-">, "foo-ba-rb">>,
Assert<Equal<JoinByCase<"foo_bar-baz/qux", "-">, "foo-bar-baz-qux">>,
// array
Assert<Equal<JoinByCase<["Foo", "Bar"], "-">, "foo-bar">>,
];
/* eslint-enable @typescript-eslint/no-unused-vars */
Loading
0