egg developer tool, extends @artus-cli/artus-cli.
npm i egg-bin --save-devAdd egg-bin to package.json scripts:
{
"scripts": {
"dev": "egg-bin dev",
"test-local": "egg-bin test",
"test": "npm run lint -- --fix && npm run test-local",
"cov": "egg-bin cov",
"lint": "eslint .",
"ci": "npm run lint && npm run cov"
}
}All the commands support these specific options:
--inspect--inspect-brk--typescript/--tsenable typescript support. Auto detect frompackage.json'spkg.egg.typescript, orpkg.dependencies.typescript/pkg.devDependencies.typescript.--base/--baseDirapplication's root path, default toprocess.cwd().--requirewill add toexecArgv, support multiple. Also support read frompackage.json'spkg.egg.require--dry-run/-dwhether dry-run the test command, just show the command
egg-bin [command] --inspect
egg-bin [command] --inspect-brk
egg-bin [command] --typescript
egg-bin [command] --base /foo/barStart dev cluster on local env, it will start a master, an agent and a worker.
egg-bin dev--frameworkegg web framework root path.--portserver port. If not specified, the port is obtained in the following order: egg.js configurationconfig/config.*.js>process.env.EGG_BIN_DEFAULT_PORT> 7001 > other available ports.--workersworker process number, default to1worker at local mode.--stickystart a sticky cluster server, default tofalse.
Create .vscode/launch.json file:
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Egg Debug",
"runtimeExecutable": "npm",
"runtimeArgs": [
"run",
"dev",
"--",
"--inspect-brk"
],
"console": "integratedTerminal",
"restart": true,
"protocol": "auto",
"port": 9229,
"autoAttachChildProcesses": true
},
{
"type": "node",
"request": "launch",
"name": "Egg Test",
"runtimeExecutable": "npm",
"runtimeArgs": [
"run",
"test-local",
"--",
"--inspect-brk"
],
"protocol": "auto",
"port": 9229,
"autoAttachChildProcesses": true
}
]
}Using mocha to run test.
egg-bin test [...files] [options]filesis optional, default totest/**/*.test.tstest/fixtures,test/node_modulesis always exclude.
If test/.setup.ts file exists, it will be auto require as the first test file.
test
├── .setup.ts
└── foo.test.tsYou can pass any mocha argv.
--timeoutmilliseconds, default to 60000--changed/-conly test changed test files(test files means files that match${pwd}/test/**/*.test.(js|ts))--parallelenable mocha parallel mode, default tofalse.--auto-agentauto start agent in mocha master agent.--jobsnumber of jobs to run in parallel, default toos.cpus().length - 1.--mochawesomeenable mochawesome reporter, default totrue.
Environment is also support, will use it if options not provide.
You can set TESTS env to set the tests directory, it support glob grammar.
TESTS=test/a.test.ts egg-bin testAnd the reporter can set by the TEST_REPORTER env, default is spec.
TEST_REPORTER=doc egg-bin testThe test timeout can set by TEST_TIMEOUT env, default is 60000 ms.
TEST_TIMEOUT=2000 egg-bin testUsing mocha and [c8] to run code coverage, it support all test params above.
Coverage reporter will output text-summary, json and lcov.
You can pass any mocha argv.
-xadd dir ignore coverage, support multiple argv--prerequireprerequire files for coverage instrument, you can use this options if load files slowly when callmm.appormm.cluster--typescript/--tsenable typescript support. If true, will auto add.tsextension and ignoretypingsandd.ts.--c8c8 instruments passthrough. you can use this to overwrite egg-bin's default c8 instruments and add additional ones.- egg-bin have some default instruments passed to c8 like
-rand--temp-directory egg-bin cov --c8="-r teamcity -r text" --c8-report=true
- egg-bin have some default instruments passed to c8 like
- also support all test params above.
You can set COV_EXCLUDES env to add dir ignore coverage.
COV_EXCLUDES="app/plugins/c*,app/autocreate/**" egg-bin covSee https://artus-cli.github.io
Made with contributors-img.