Skip to content

Commit

Permalink
📦 NEW: [BREAKING] Only support Node.js 14 (#176)
Browse files Browse the repository at this point in the history
remove nyc
  • Loading branch information
fengmk2 committed Jun 4, 2022
1 parent f32030b commit 6fb02f9
Show file tree
Hide file tree
Showing 29 changed files with 237 additions and 281 deletions.
3 changes: 0 additions & 3 deletions .autod.conf
Expand Up @@ -8,9 +8,7 @@ module.exports = {
'test/fixtures',
],
dep: [
'nyc',
'mocha',
'co-mocha',
'intelli-espower-loader',
'power-assert',
'espower-typescript',
Expand All @@ -20,7 +18,6 @@ module.exports = {
'egg',
'autod',
'eslint-config-egg',
// 'egg-ci',
],
keep: [
],
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/nodejs.yml
Expand Up @@ -6,9 +6,11 @@ name: Node.js CI
on:
push:
branches:
- main
- master
pull_request:
branches:
- main
- master
schedule:
- cron: '0 2 * * *'
Expand All @@ -20,7 +22,7 @@ jobs:
strategy:
fail-fast: false
matrix:
node-version: [8, 10, 12, 14, 16]
node-version: [14, 16, 18]
os: [ubuntu-latest, windows-latest, macos-latest]

steps:
Expand All @@ -33,7 +35,7 @@ jobs:
node-version: ${{ matrix.node-version }}

- name: Install Dependencies
run: npm i -g npminstall && npminstall
run: npm i

- name: Continuous Integration
run: npm run ci
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Expand Up @@ -25,4 +25,5 @@ test/fixtures/example-ts-ets/typings/
*.log
package-lock.json
.nyc_output
yarn.lock
yarn.lock
.c8_output
4 changes: 2 additions & 2 deletions LICENSE
@@ -1,6 +1,6 @@
The MIT License (MIT)
MIT License

Copyright (c) Alibaba Group Holding Limited and other contributors.
Copyright (c) 2017-present Alibaba Group Holding Limited and other contributors.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
13 changes: 3 additions & 10 deletions README.md
Expand Up @@ -102,7 +102,7 @@ $ egg-bin debug --debug-port=9229 --proxy=9999

### test

Using [mocha] with [co-mocha] to run test.
Using [mocha] to run test.

[power-assert] is the default `assert` library, and [intelli-espower-loader] will be auto required.

Expand Down Expand Up @@ -161,7 +161,7 @@ TEST_TIMEOUT=2000 egg-bin test

### cov

Using [nyc] or [c8] to run code coverage, it support all test params above.
Using [c8] to run code coverage, it support all test params above.

Coverage reporter will output text-summary, json and lcov.

Expand All @@ -172,15 +172,10 @@ You can pass any mocha argv.
- `-x` add dir ignore coverage, support multiple argv
- `--prerequire` prerequire files for coverage instrument, you can use this options if load files slowly when call `mm.app` or `mm.cluster`
- `--typescript` / `--ts` enable typescript support, default to `false`, if true, will auto add `.ts` extension and ignore `typings` and `d.ts`.
- `--nyc` nyc instruments passthrough. you can use this to overwrite egg-bin's default nyc instruments and add additional ones.
> if you want to add addtional `nyc` reporters, you need to use this rather than add `reporter` key in `.nycrc` because:
> - when same key exists in `.nycrc` and cmd instruments, nyc prefers instrument.
> - egg-bin have some default instruments passed to nyc like `-r` and `--temp-directory`
> - `egg-bin cov --nyc="-r teamcity -r text"`
- `--c8` c8 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 `-r` and `--temp-directory`
> - `egg-bin cov --c8="-r teamcity -r text" --c8-report=true`
- `--c8-report` use c8 to report coverage not nyc, c8 uses native V8 coverage, make sure you're running Node.js >= 10.12.0, default to `false`.
- `--c8-report` use c8 to report coverage, c8 uses native V8 coverage, make sure you're running Node.js >= 10.12.0, default to `false`.

- also support all test params above.

Expand Down Expand Up @@ -298,9 +293,7 @@ This project follows the git-contributor [spec](https://github.com/xudafeng/git-
<!-- GITCONTRIBUTOR_END -->

[mocha]: https://mochajs.org
[co-mocha]: https://npmjs.com/co-mocha
[glob]: https://github.com/isaacs/node-glob
[istanbul]: https://github.com/gotwarlost/istanbul
[nsp]: https://npmjs.com/nsp
[iron-node]: https://github.com/s-a/iron-node
[intelli-espower-loader]: https://github.com/power-assert-js/intelli-espower-loader
Expand Down
4 changes: 2 additions & 2 deletions lib/cmd/autod.js
Expand Up @@ -17,11 +17,11 @@ class AutodCommand extends Command {
return 'Generate pkg.dependencies and pkg.devDependencies automatically';
}

* run({ cwd, argv }) {
async run({ cwd, argv }) {
const args = [];
if (argv.check) args.push('--check');
const autodBin = require.resolve('autod/bin/autod.js');
yield this.helper.forkNode(autodBin, args, { cwd });
await this.helper.forkNode(autodBin, args, { cwd });
}
}

Expand Down
41 changes: 14 additions & 27 deletions lib/cmd/cov.js
Expand Up @@ -3,7 +3,7 @@

const debug = require('debug')('egg-bin');
const path = require('path');
const rimraf = require('mz-modules/rimraf');
const fs = require('fs/promises');
const testExclude = require('test-exclude');

const Command = require('./test');
Expand All @@ -25,11 +25,6 @@ class CovCommand extends Command {
description: 'prerequire files for coverage instrument',
type: 'boolean',
},
nyc: {
description: 'nyc instruments passthrough',
type: 'string',
default: '--temp-directory ./node_modules/.nyc_output -r text-summary -r json-summary -r json -r lcov',
},
c8: {
description: 'c8 instruments passthrough',
type: 'string',
Expand All @@ -55,7 +50,7 @@ class CovCommand extends Command {
return 'Run test with coverage';
}

* run(context) {
async run(context) {
const { cwd, argv, execArgv, env } = context;
if (argv.prerequire) {
env.EGG_BIN_PREREQUIRE = 'true';
Expand Down Expand Up @@ -91,19 +86,15 @@ class CovCommand extends Command {
if (context.argv.typescript) {
opt.env.SPAWN_WRAP_SHIM_ROOT = path.join(cwd, 'node_modules');
}
let cli = require.resolve('nyc/bin/nyc.js');
let outputDir = path.join(cwd, 'node_modules/.nyc_output');
if (argv['c8-report']) {
cli = require.resolve('c8/bin/c8.js');
outputDir = path.join(cwd, 'node_modules/.c8_output');
}
yield rimraf(outputDir);
const cli = require.resolve('c8/bin/c8.js');
const outputDir = path.join(cwd, 'node_modules/.c8_output');
await fs.rm(outputDir, { force: true, recursive: true });
const coverageDir = path.join(cwd, 'coverage');
yield rimraf(coverageDir);
const covArgs = yield this.getCovArgs(context);
await fs.rm(coverageDir, { force: true, recursive: true });
const covArgs = await this.getCovArgs(context);
if (!covArgs) return;
debug('covArgs: %j', covArgs);
yield this.helper.forkNode(cli, covArgs, opt);
await this.helper.forkNode(cli, covArgs, opt);
}

/**
Expand All @@ -116,10 +107,10 @@ class CovCommand extends Command {
/**
* get coverage args
* @param {Object} context - { cwd, argv, ...}
* @return {Array} args for nyc
* @return {Array} args for c8
* @protected
*/
* getCovArgs(context) {
async getCovArgs(context) {
let covArgs = [
// '--show-process-tree',
];
Expand All @@ -131,13 +122,9 @@ class CovCommand extends Command {
this.addExclude('**/*.d.ts');
}

// nyc or c8 args passthrough
let passthroughArgs = context.argv.nyc;
if (context.argv['c8-report']) {
passthroughArgs = context.argv.c8;
context.argv['c8-report'] = undefined;
}
context.argv.nyc = undefined;
// c8 args passthrough
const passthroughArgs = context.argv.c8;
context.argv['c8-report'] = undefined;
context.argv.c8 = undefined;
if (passthroughArgs) {
covArgs = covArgs.concat(passthroughArgs.split(' '));
Expand All @@ -146,7 +133,7 @@ class CovCommand extends Command {
covArgs.push('-x');
covArgs.push(exclude);
}
const testArgs = yield this.formatTestArgs(context);
const testArgs = await this.formatTestArgs(context);
if (!testArgs) return;
covArgs.push(require.resolve('mocha/bin/_mocha'));
covArgs = covArgs.concat(testArgs);
Expand Down
4 changes: 2 additions & 2 deletions lib/cmd/debug.js
Expand Up @@ -45,11 +45,11 @@ class DebugCommand extends Command {
return 'Start server at local debug mode';
}

* run(context) {
async run(context) {
const proxyPort = context.argv.proxy;
context.argv.proxy = undefined;

const eggArgs = yield this.formatArgs(context);
const eggArgs = await this.formatArgs(context);
const options = {
execArgv: context.execArgv,
env: Object.assign({ NODE_ENV: 'development', EGG_DEBUG: true }, context.env),
Expand Down
10 changes: 5 additions & 5 deletions lib/cmd/dev.js
Expand Up @@ -58,8 +58,8 @@ class DevCommand extends Command {
return context;
}

* run(context) {
const devArgs = yield this.formatArgs(context);
async run(context) {
const devArgs = await this.formatArgs(context);
const env = {
NODE_ENV: 'development',
EGG_MASTER_CLOSE_TIMEOUT: 1000,
Expand All @@ -71,7 +71,7 @@ class DevCommand extends Command {
debug('%s %j %j, %j', this.serverBin, devArgs, options.execArgv, options.env.NODE_ENV);
const task = this.helper.forkNode(this.serverBin, devArgs, options);
this.proc = task.proc;
yield task;
await task;
}

/**
Expand All @@ -80,7 +80,7 @@ class DevCommand extends Command {
* @param {Object} context - { cwd, argv }
* @return {Array} pass to start-cluster, [ '{"port":7001,"framework":"egg"}' ]
*/
* formatArgs(context) {
async formatArgs(context) {
const { cwd, argv } = context;
/* istanbul ignore next */
argv.baseDir = argv.baseDir || cwd;
Expand All @@ -103,7 +103,7 @@ class DevCommand extends Command {
// auto detect available port
if (!argv.port) {
debug('detect available port');
const port = yield detect(this.defaultPort);
const port = await detect(this.defaultPort);
if (port !== this.defaultPort) {
argv.port = port;
console.warn(`[egg-bin] server port ${this.defaultPort} is in use, now using port ${port}\n`);
Expand Down
4 changes: 2 additions & 2 deletions lib/cmd/pkgfiles.js
Expand Up @@ -17,15 +17,15 @@ class PkgfilesCommand extends Command {
return 'Generate pkg.files automatically';
}

* run({ cwd, argv }) {
async run({ cwd, argv }) {
const args = [
'--entry', 'app',
'--entry', 'config',
'--entry', '*.js',
];
if (argv.check) args.push('--check');
const pkgfiles = require.resolve('ypkgfiles/bin/ypkgfiles.js');
yield this.helper.forkNode(pkgfiles, args, { cwd });
await this.helper.forkNode(pkgfiles, args, { cwd });
}
}

Expand Down
20 changes: 10 additions & 10 deletions lib/cmd/test.js
Expand Up @@ -4,8 +4,8 @@ const debug = require('debug')('egg-bin');
const fs = require('fs');
const path = require('path');
const globby = require('globby');
const Command = require('../command');
const changed = require('jest-changed-files');
const Command = require('../command');

class TestCommand extends Command {
constructor(rawArgv) {
Expand Down Expand Up @@ -52,15 +52,15 @@ class TestCommand extends Command {
return 'Run test with mocha';
}

* run(context) {
async run(context) {
const opt = {
env: Object.assign({
NODE_ENV: 'test',
}, context.env),
execArgv: context.execArgv,
};
const mochaFile = require.resolve('mocha/bin/_mocha');
const testArgs = yield this.formatTestArgs(context);
const testArgs = await this.formatTestArgs(context);
if (!testArgs) return;

if (context.argv['dry-run']) {
Expand All @@ -71,16 +71,18 @@ class TestCommand extends Command {
}

debug('run test: %s %s', mochaFile, testArgs.join(' '));
yield this.helper.forkNode(mochaFile, testArgs, opt);
await this.helper.forkNode(mochaFile, testArgs, opt);
}

/**
* format test args then change it to array style
* @param {Object} context - { cwd, argv, ...}
* @param context.argv
* @param context.debugOptions
* @return {Array} [ '--require=xxx', 'xx.test.js' ]
* @protected
*/
* formatTestArgs({ argv, debugOptions }) {
async formatTestArgs({ argv, debugOptions }) {
const testArgv = Object.assign({}, argv);

/* istanbul ignore next */
Expand All @@ -106,8 +108,6 @@ class TestCommand extends Command {
// [mocha built-in](https://github.com/mochajs/mocha/blob/master/lib/utils.js#L738) don't work with `[npminstall](https://github.com/cnpm/npminstall)`, so we will override it.
if (!testArgv.fullTrace) requireArr.unshift(require.resolve('../mocha-clean'));

requireArr.push(require.resolve('co-mocha'));

if (requireArr.includes('intelli-espower-loader')) {
console.warn('[egg-bin] don\'t need to manually require `intelli-espower-loader` anymore');
} else if (testArgv.espower) {
Expand All @@ -125,7 +125,7 @@ class TestCommand extends Command {
let pattern;
// changed
if (testArgv.changed) {
pattern = yield this._getChangedTestFiles();
pattern = await this._getChangedTestFiles();
if (!pattern.length) {
console.log('No changed test files');
return;
Expand Down Expand Up @@ -175,9 +175,9 @@ class TestCommand extends Command {
return this.helper.unparseArgv(testArgv);
}

* _getChangedTestFiles() {
async _getChangedTestFiles() {
const cwd = process.cwd();
const res = yield changed.getChangedFilesForRoots([ cwd ]);
const res = await changed.getChangedFilesForRoots([ cwd ]);
const changedFiles = res.changedFiles;
const files = [];
for (const file of changedFiles) {
Expand Down
1 change: 0 additions & 1 deletion lib/mocha-clean.js
Expand Up @@ -18,7 +18,6 @@ const internal = [
/node_modules\/.*empower-core\//,
/node_modules\/.*mocha\//,
/node_modules\/.*co\//,
/node_modules\/.*co-mocha\//,
/node_modules\/.*supertest\//,
];

Expand Down

0 comments on commit 6fb02f9

Please sign in to comment.