@boostest/cli v0.8.0
TL;DR
Japanese(日本語)→README-ja.md
- Instantly create test data from TypeScript
type,interface, orclass📝 - Partially overwrite test data in
typeorinterface🏗️ - Test data is output as actual code, becoming a user asset 💸
Installation
# global
npm install -g @boostest/cli
# repo
npm install --save-dev @boostest/cli
pnpm add -D @boostest/cli
yarn add -D @boostest/cliInit
Go to the root directory of the project where tsconfig.json and other files are located.
npx boostest initThe following file boostest.setting.json will be created
{
"target_pattern": ["src/**/*.ts"],
"name": "boostest",
"tsconfig": "./tsconfig.json",
"output": {
"single": true
},
"initial_value": {
"string": "init string value",
"number": 10000,
"bigint": "556455199254740991n",
"any": "any value"
}
}Add BoostestFuntion
Define a function that includes the contents described in name in boostest.setting.json as shown below, and specify the Type, etc. in Generic. You can leave the function undefined.
type User = {
name: string;
age: number;
// ...more complex types
};
interface Job {
name: string
// ...more complex types
}
class Test {
constructor(public name: string) {
}
}
const user = boostestUser<User>(); // Cannot find name 'boostestUser'
const job = boostestJob<Job>(); // Cannot find name 'boostestJob'.
const test = boostestTest<Test>(); // Cannot find name 'boostestTest'.Generate
The following commands will automatically generate functions that were undefined.
npx boostestImport boostestUser, boostestJob and boostestTest from the automatically generated directories.
import { boostestJob } from "../boostest_output/boostestJob";
import { boostestTest } from "../boostest_output/boostestTest";
import { boostestUser } from "../boostest_output/boostestUser";When the file is executed, the contents of type are available as values.
console.log("user", user);
// user { name: "init string value", age: 10000 }
console.log("job", job);
// job { name: "init string value" }
console.log("test class prop name", test.name);
// test class prop name init string valueoverwrite
type User = {
name: string;
age: number;
// ...more complex types
};
const user = boostestUser<User>({ age: 30 }); // overwrites the default value age
console.log("user", user);
// user { name: "init string value", age: 30 }Introduction 🚀
boostest.setting.json
target_pattern
Specify the target files in glob format.
"target_pattern": ["src/**/*.{ts,tsx}"],Internally https://github.com/Gilnaa/globwalk is used.
name
Normally, functions containing boostest like the following are targeted, but you can freely change it using name.
// boostest[FreeName]<[TypeName or InterfaceName or ClassName]>();
const testData = boostestTest<TypeName>();If you set name as follows, functions containing hoge will be targeted.
// "name": "hoge",
const testData = hogeTest<TypeName>();output
If single is set to true, the test data will be output to a single directory.
project root
├── boostest_output
│ ├── boostestGeneric.ts
│ ├── boostestGenericsAliasType.ts
│ ├── boostestGenericsInterfaceType.ts
│ └── boostestGenericsTypeClass.tsIf single is set to false, the test data will be output to a separate file.
something
├── dir1
│ ├── boostest_output
│ │ ├── boostestFile1.ts
│ │ └── boostestFile1-2.ts
│ └── targetFile1.ts
├── dir2
│ ├── boostest_output
│ │ └── boostestFile2.ts
│ └── targetFile2.ts
├── dir3
│ ├── boostest_output
│ │ └── boostestFile3.ts
│ └── targetFile3.tstsconfig
Specify the path to tsconfig.json.
This is useful for module resolution, such as being able to use aliases like import {hoge} from "@alias/somethis...".
initial_value
You can set the initial value for each type.
"initial_value": {
"string": "init string value",
"number": 10000,
"bigint": "556455199254740991n",
"any": "any value"
}string -> "init string value"
number -> 10000
bigint -> 556455199254740991n
any -> "any value"Supports
Types
| type | support | example | default result val |
|---|---|---|---|
| string | ○ | string | "test string data" |
| number | ○ | number | 10 |
| bigint | ○ | 100n | 9007199254740991 |
| boolean | ○ | boolean | true |
| undefined | ○ | undefined | undefined |
| null | ○ | null | null |
| any | ○ | any | "any" |
| unknown | ○ | unknown | undefined |
| never | ○ | never | null |
| object | ○ | object | {} |
| void | ○ | void | null |
| function | ○ | ()=>void | ()=>{} |
| array | ○ | string[] | [] |
| union | ○ | string \| number | "test string data" |
| conditional | ○ | string extends number ? true : false; | false (Condition Result) |
| symbol | ○ | symbol | Symbol() |
| tuple type | ○ | [string, number] | ["test string data", 10] |
| named tuple type | ○ | [name: string, age: number] | ["test string data", 10] |
| intersection type | ○ | {name: string} & {age: number} | { name: "init string value", age: 10000 } |
| keyof | ○ | keyof { name: string } | name |
| typeof | ○ | typeof Hoge // const Hoge = { name: "hoge" }; | user { name: "init string value" } |
| infer | ○ | - | - |
| mapped type | ○ | - | - |
| namespace | ○ | - | - |
| constructor type | ○ | - | - |
| index accessor | ○ | - | - |
| template | ○ | - | - |
Utilities type
| type | support |
|---|---|
ThisType<T> | ○ |
Array<T> | ○ |
Partial<T> | ○ |
Required<T> | ○ |
Readonly<T> | ○ |
Pick<T, K> | ○ |
Omit<T, K> | ○ |
Extract<T, U> | ○ |
Exclude<T, U> | ○ |
NonNullable<T> | ○ |
Parameters<T> | ○ |
ConstructorParameters<T> | ○ |
ReturnType<T> | ○ |
InstanceType<T> | ○ |
Promise<T> | ○ |
Import/Export
ESM
| kind | support | example |
|---|---|---|
| default import | ○ | import Hoge from '@/hoge'; |
| import | ○ | import { Hoge } from '@/hoge'; |
| default export | ○ | export default Hoge; |
| named export | ○ | export type { Hoge as AnotherName } |
| named default export | ○ | export type { Hoge as default } |
| export decl | ○ | export interface Hoge { name: string; } |
| default export decl | ○ | export default interface Hoge { name: string; } |
| export with import | ○ | export type { Hoge } from './index'; |
| named export with import | ○ | export type { Hoge as AnotherName } from './index'; |
CommonJS
| kind | support | example |
|---|---|---|
| export assignment | ○ | export = Hoge; |
| require | × | const hoge = require('./hoge.js'); |
declaration
namespace
Not supported in some cases