diff --git a/.autod.conf b/.autod.conf index d5d0bbd3..1ca8ef14 100644 --- a/.autod.conf +++ b/.autod.conf @@ -13,9 +13,11 @@ module.exports = { 'co-mocha', 'intelli-espower-loader', 'power-assert', + 'espower-typescript', 'ypkgfiles', ], devdep: [ + 'egg', 'autod', 'eslint-config-egg', 'egg-ci', diff --git a/.gitignore b/.gitignore index 348042ed..f22ee7c5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,10 +1,18 @@ node_modules/ coverage/ -!test/fixtures/custom-framework-app/node_modules/ +test/fixtures/custom-framework-app/node_modules/ + +test/fixtures/demo-app/node_modules/aliyun-egg/ !test/fixtures/demo-app/node_modules/aliyun-egg/node_modules/ + +test/fixtures/ts/node_modules/aliyun-egg/ +!test/fixtures/ts/node_modules/aliyun-egg/node_modules/ + !test/fixtures/test-files-glob/** !test/fixtures/test-files-stack/node_modules/ !test/fixtures/example/node_modules/ + + **/run/*.json .tmp .vscode diff --git a/.travis.yml b/.travis.yml index 47cc542e..7212f2a9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,9 +3,19 @@ language: node_js node_js: - '6' - '8' +env: + - EGG_VERSION=1 + - EGG_VERSION=2 +matrix: + exclude: + - node_js: '6' + env: EGG_VERSION=2 install: - - npm i npminstall && npminstall + - npm i npminstall + - sed -i.bak '/"egg":/d' package.json + - npminstall -d script: + - eval "npminstall -d egg@$EGG_VERSION" - npm run ci after_script: - npminstall codecov && codecov diff --git a/README.md b/README.md index 3e10ed6f..c7637d8d 100644 --- a/README.md +++ b/README.md @@ -80,6 +80,8 @@ $ egg-bin dev - `--port` server port, default to `7001`. - `--cluster` worker process number, skip this argvs will start only `1` worker, provide this without value will start `cpu` count worker. - `--sticky` start a sticky cluster server, default to `false`. +- `--typescript` / `--ts` enable typescript support, default to `false`. +- `--require` will add to `execArgv`, support multiple. ### debug @@ -130,6 +132,7 @@ You can pass any mocha argv. - `--grep` only run tests matching - `--timeout` milliseconds, default to 30000 - `--full-trace` display the full stack trace, default to false. +- `--typescript` / `--ts` enable typescript support, default to `false`. - see more at https://mochajs.org/#usage #### environment diff --git a/appveyor.yml b/appveyor.yml index 3d15e523..c274b7d3 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,6 +1,5 @@ environment: matrix: - - nodejs_version: '6' - nodejs_version: '8' install: diff --git a/lib/cmd/dev.js b/lib/cmd/dev.js index a187ee26..3ae25083 100644 --- a/lib/cmd/dev.js +++ b/lib/cmd/dev.js @@ -33,6 +33,11 @@ class DevCommand extends Command { description: 'specify framework that can be absolute path or npm package', type: 'string', }, + require: { + description: 'will add to execArgv --require', + type: 'array', + alias: 'r', + }, }; } @@ -40,6 +45,18 @@ class DevCommand extends Command { return 'Start server at local dev mode'; } + get context() { + const context = super.context; + const { argv, execArgvObj } = context; + execArgvObj.require = execArgvObj.require || []; + // add require to execArgv + if (argv.require) { + execArgvObj.require.push(...argv.require); + argv.require = undefined; + } + return context; + } + * run(context) { const devArgs = yield this.formatArgs(context); const env = { diff --git a/lib/cmd/test.js b/lib/cmd/test.js index dd04ef6a..c14b1efd 100644 --- a/lib/cmd/test.js +++ b/lib/cmd/test.js @@ -85,13 +85,19 @@ class TestCommand extends Command { requireArr.push(require.resolve('intelli-espower-loader')); } + // for power-assert + if (testArgv.typescript) { + requireArr.push(require.resolve('espower-typescript/guess')); + } + testArgv.require = requireArr; // collect test files let files = testArgv._.slice(); if (!files.length) { - files = [ process.env.TESTS || 'test/**/*.test.js' ]; + files = [ process.env.TESTS || `test/**/*.test.${testArgv.typescript ? 'ts' : 'js'}` ]; } + // expand glob and skip node_modules and fixtures files = globby.sync(files.concat('!test/**/{fixtures, node_modules}/**/*.test.js')); files.sort(); @@ -108,6 +114,7 @@ class TestCommand extends Command { testArgv.r = undefined; testArgv.t = undefined; testArgv.g = undefined; + testArgv.typescript = undefined; return this.helper.unparseArgv(testArgv); } diff --git a/lib/command.js b/lib/command.js index 096a9966..a52b8758 100644 --- a/lib/command.js +++ b/lib/command.js @@ -1,5 +1,6 @@ 'use strict'; +const path = require('path'); const BaseCommand = require('common-bin'); class Command extends BaseCommand { @@ -9,16 +10,33 @@ class Command extends BaseCommand { execArgv: true, removeAlias: true, }; + + // common-bin setter, don't care about override at sub class + // https://github.com/node-modules/common-bin/blob/master/lib/command.js#L158 + this.options = { + typescript: { + description: 'whether enable typescript support, will load `ts-node/register` etc', + type: 'boolean', + alias: 'ts', + }, + }; } get context() { const context = super.context; + const { argv, debugPort, execArgvObj } = context; // compatible - if (context.debugPort) context.debug = context.debugPort; + if (debugPort) context.debug = debugPort; // remove unuse args - context.argv.$0 = undefined; + argv.$0 = undefined; + + // execArgv + if (argv.typescript) { + execArgvObj.require = execArgvObj.require || []; + execArgvObj.require.push(path.join(__dirname, './ts-helper.js')); + } return context; } diff --git a/lib/ts-helper.js b/lib/ts-helper.js new file mode 100644 index 00000000..e43dfa76 --- /dev/null +++ b/lib/ts-helper.js @@ -0,0 +1,5 @@ +'use strict'; + +require('ts-node').register({ + typeCheck: true, +}); diff --git a/package.json b/package.json index 60159475..4dbdcad6 100644 --- a/package.json +++ b/package.json @@ -9,33 +9,36 @@ }, "dependencies": { "autod": "^3.0.1", - "chalk": "^2.3.1", - "co-mocha": "^1.2.1", - "common-bin": "^2.7.1", + "chalk": "^2.3.2", + "co-mocha": "^1.2.2", + "common-bin": "^2.7.2", "debug": "^3.1.0", "detect-port": "^1.2.2", "egg-utils": "^2.3.0", + "espower-typescript": "^8.1.3", "globby": "^8.0.1", "inspector-proxy": "^1.2.1", "intelli-espower-loader": "^1.0.1", - "mocha": "^5.0.1", + "mocha": "^5.0.5", "mz-modules": "^2.1.0", - "nyc": "^11.4.1", + "nyc": "^11.6.0", "power-assert": "^1.4.4", "semver": "^5.5.0", - "test-exclude": "^4.2.0", + "test-exclude": "^4.2.1", + "ts-node": "^5.0.1", "ypkgfiles": "^1.5.0" }, "devDependencies": { + "@types/mocha": "^5.0.0", "autod": "^3.0.1", "babel": "^6.3.26", "babel-preset-airbnb": "^1.0.1", "babel-register": "^6.4.3", "coffee": "^4.1.0", "cross-env": "^3.1.3", - "egg": "^1.8.0", + "egg": "^2.5.0", "egg-ci": "^1.8.0", - "egg-mock": "^3.14.0", + "egg-mock": "^3.15.1", "enzyme": "^2.0.0", "eslint": "^4.12.1", "eslint-config-egg": "^7.0.0", @@ -45,7 +48,8 @@ "react": "^0.14.7", "react-addons-test-utils": "^0.14.7", "react-dom": "^0.14.7", - "semver": "^5.4.1" + "semver": "^5.4.1", + "typescript": "^2.7.2" }, "repository": { "type": "git", @@ -63,7 +67,7 @@ "test-local": "node bin/egg-bin.js test -t 3600000", "cov": "nyc -r lcov -r text-summary npm run test-local", "ci-test-only": "TESTS=test/lib/cmd/cov.test.js npm run test-local", - "ci": "npm run lint && npm run pkgfiles -- --check && npm run autod -- --check && npm run ci-test-only && npm run cov", + "ci": "npm run lint && npm run pkgfiles -- --check && npm run ci-test-only && npm run cov", "autod": "node bin/egg-bin.js autod" }, "engines": { diff --git a/test/fixtures/example-ts/app.ts b/test/fixtures/example-ts/app.ts new file mode 100644 index 00000000..a063672b --- /dev/null +++ b/test/fixtures/example-ts/app.ts @@ -0,0 +1,7 @@ +'use strict'; + +import { Application } from 'egg'; + +export default (app: Application) => { + console.log(`hi, egg, ${app.config.keys}`); +}; diff --git a/test/fixtures/example-ts/app/router.ts b/test/fixtures/example-ts/app/router.ts new file mode 100644 index 00000000..46c83b7d --- /dev/null +++ b/test/fixtures/example-ts/app/router.ts @@ -0,0 +1,9 @@ +'use strict'; + +import { Application, Context } from 'egg'; + +export default (app: Application) => { + app.router.get('/', function* (this: Context) { + this.body = `hi, egg`; + }); +}; \ No newline at end of file diff --git a/test/fixtures/example-ts/config/config.default.ts b/test/fixtures/example-ts/config/config.default.ts new file mode 100644 index 00000000..446264a9 --- /dev/null +++ b/test/fixtures/example-ts/config/config.default.ts @@ -0,0 +1,7 @@ +'use strict'; + +export default () => { + const config: any = {}; + config.keys = '123456'; + return config; +}; diff --git a/test/fixtures/example-ts/node_modules/egg/index.js b/test/fixtures/example-ts/node_modules/egg/index.js new file mode 100644 index 00000000..d1757bf0 --- /dev/null +++ b/test/fixtures/example-ts/node_modules/egg/index.js @@ -0,0 +1,8 @@ +'use strict'; + +module.exports = require('../../../../../node_modules/egg'); + +setTimeout(() => { + console.log('exit by master test end') + process.exit(0); +}, 6000); diff --git a/test/fixtures/example-ts/node_modules/egg/package.json b/test/fixtures/example-ts/node_modules/egg/package.json new file mode 100644 index 00000000..6697ad3f --- /dev/null +++ b/test/fixtures/example-ts/node_modules/egg/package.json @@ -0,0 +1,3 @@ +{ + "name": "egg" +} diff --git a/test/fixtures/example-ts/package.json b/test/fixtures/example-ts/package.json new file mode 100644 index 00000000..1ab2c3f9 --- /dev/null +++ b/test/fixtures/example-ts/package.json @@ -0,0 +1,3 @@ +{ + "name": "example-ts" +} \ No newline at end of file diff --git a/test/fixtures/example-ts/test/index.test.ts b/test/fixtures/example-ts/test/index.test.ts new file mode 100644 index 00000000..25c83639 --- /dev/null +++ b/test/fixtures/example-ts/test/index.test.ts @@ -0,0 +1,21 @@ +'use strict'; + +import { Application, Context } from 'egg'; +import { default as mock, MockOption, BaseMockApplication } from 'egg-mock'; +import * as path from 'path'; + +describe('test/index.test.ts', () => { + let app: BaseMockApplication; + before(() => { + app = mock.app({ typescript: true } as MockOption); + return app.ready(); + }); + after(() => app.close()); + it('should work', async () => { + await app + .httpRequest() + .get('/') + .expect('hi, egg') + .expect(200); + }); +}); diff --git a/test/fixtures/example-ts/tsconfig.json b/test/fixtures/example-ts/tsconfig.json new file mode 100644 index 00000000..4f10abf7 --- /dev/null +++ b/test/fixtures/example-ts/tsconfig.json @@ -0,0 +1,19 @@ +{ + "compilerOptions": { + "target": "es2017", + "module": "commonjs", + "strict": true, + "noImplicitAny": false, + "moduleResolution": "node", + "experimentalDecorators": true, + "emitDecoratorMetadata": true, + "pretty": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noFallthroughCasesInSwitch": true, + "skipLibCheck": true, + "skipDefaultLibCheck": true, + "inlineSourceMap": true, + "importHelpers": true + }, +} \ No newline at end of file diff --git a/test/fixtures/require-script.js b/test/fixtures/require-script.js new file mode 100644 index 00000000..00d46285 --- /dev/null +++ b/test/fixtures/require-script.js @@ -0,0 +1,3 @@ +'use strict'; + +console.log('hey, you require me by --require'); diff --git a/test/fixtures/ts/app.js b/test/fixtures/ts/app.js new file mode 100644 index 00000000..e46106f7 --- /dev/null +++ b/test/fixtures/ts/app.js @@ -0,0 +1,6 @@ +'use strict'; + + +module.exports = app => { + app.logger.info('###', require('./test.ts').default.name); +}; diff --git a/test/fixtures/ts/config/config.default.js b/test/fixtures/ts/config/config.default.js new file mode 100644 index 00000000..762c2647 --- /dev/null +++ b/test/fixtures/ts/config/config.default.js @@ -0,0 +1,3 @@ +'use strict'; + +exports.key = '12345'; diff --git a/test/fixtures/ts/node_modules/aliyun-egg/index.js b/test/fixtures/ts/node_modules/aliyun-egg/index.js new file mode 100644 index 00000000..c1500965 --- /dev/null +++ b/test/fixtures/ts/node_modules/aliyun-egg/index.js @@ -0,0 +1,20 @@ +'use strict'; + +const egg = require('../../../../../node_modules/egg'); + +module.exports = Object.assign({}, egg); + +module.exports.startCluster = options => { + console.log('options.typescript=%s', options.typescript); + console.log('options: %j', options); + if (process.execArgv.length) { + console.log('process.execArgv:', process.execArgv); + } + + // make sure exit + setTimeout(() => { + console.log('exit by master test end') + process.exit(0); + }, 5000); + return egg.startCluster(options); +}; diff --git a/test/fixtures/ts/node_modules/aliyun-egg/package.json b/test/fixtures/ts/node_modules/aliyun-egg/package.json new file mode 100644 index 00000000..4e36e661 --- /dev/null +++ b/test/fixtures/ts/node_modules/aliyun-egg/package.json @@ -0,0 +1,6 @@ +{ + "name": "aliyun-egg", + "dependencies": { + "egg": "*" + } +} diff --git a/test/fixtures/ts/package.json b/test/fixtures/ts/package.json new file mode 100644 index 00000000..3cb71fd5 --- /dev/null +++ b/test/fixtures/ts/package.json @@ -0,0 +1,6 @@ +{ + "name": "ts", + "egg": { + "framework": "aliyun-egg" + } +} \ No newline at end of file diff --git a/test/fixtures/ts/test.ts b/test/fixtures/ts/test.ts new file mode 100644 index 00000000..61519692 --- /dev/null +++ b/test/fixtures/ts/test.ts @@ -0,0 +1,3 @@ +'use strict'; + +export default { name: 'egg from ts' }; diff --git a/test/fixtures/ts/test/a.test.js b/test/fixtures/ts/test/a.test.js new file mode 100644 index 00000000..32c1eddc --- /dev/null +++ b/test/fixtures/ts/test/a.test.js @@ -0,0 +1,7 @@ +'use strict'; + +describe('a.test.js', () => { + it('should success', () => { + throw 'should not load js files'; + }); +}); diff --git a/test/fixtures/ts/test/sub.ts b/test/fixtures/ts/test/sub.ts new file mode 100644 index 00000000..61519692 --- /dev/null +++ b/test/fixtures/ts/test/sub.ts @@ -0,0 +1,3 @@ +'use strict'; + +export default { name: 'egg from ts' }; diff --git a/test/fixtures/ts/test/typescript.test.ts b/test/fixtures/ts/test/typescript.test.ts new file mode 100644 index 00000000..afe066d7 --- /dev/null +++ b/test/fixtures/ts/test/typescript.test.ts @@ -0,0 +1,17 @@ +'use strict'; + +const assert = require('assert'); + +describe('typescript.test.ts', () => { + it('should success', () => { + const obj = require('./sub'); + console.log('###', obj.default.name); + assert(obj.default.name === 'egg from ts'); + }); + + it('should fail', () => { + const obj = require('./sub'); + console.log('###', obj.default.name); + assert(obj.default.name === 'wrong assert ts'); + }); +}); diff --git a/test/fixtures/ts/tsconfig.json b/test/fixtures/ts/tsconfig.json new file mode 100644 index 00000000..4f10abf7 --- /dev/null +++ b/test/fixtures/ts/tsconfig.json @@ -0,0 +1,19 @@ +{ + "compilerOptions": { + "target": "es2017", + "module": "commonjs", + "strict": true, + "noImplicitAny": false, + "moduleResolution": "node", + "experimentalDecorators": true, + "emitDecoratorMetadata": true, + "pretty": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noFallthroughCasesInSwitch": true, + "skipLibCheck": true, + "skipDefaultLibCheck": true, + "inlineSourceMap": true, + "importHelpers": true + }, +} \ No newline at end of file diff --git a/test/lib/cmd/cov.test.js b/test/lib/cmd/cov.test.js index 727ebe81..16064e51 100644 --- a/test/lib/cmd/cov.test.js +++ b/test/lib/cmd/cov.test.js @@ -14,7 +14,14 @@ describe('test/lib/cmd/cov.test.js', () => { beforeEach(() => rimraf(path.join(cwd, 'coverage'))); afterEach(mm.restore); - it('should success', done => { + function assertCoverage(cwd) { + assert.ok(fs.existsSync(path.join(cwd, 'coverage/coverage-final.json'))); + assert.ok(fs.existsSync(path.join(cwd, 'coverage/coverage-summary.json'))); + assert.ok(fs.existsSync(path.join(cwd, 'coverage/lcov-report/index.html'))); + assert.ok(fs.existsSync(path.join(cwd, 'coverage/lcov.info'))); + } + + it('should success', function* () { mm(process.env, 'TESTS', 'test/**/*.test.js'); mm(process.env, 'NYC_CWD', cwd); const child = coffee.fork(eggBin, [ 'cov' ], { cwd }) @@ -29,18 +36,12 @@ describe('test/lib/cmd/cov.test.js', () => { child.expect('stdout', /Statements {3}: 80% \( 4[\/|\\]5 \)/); } - child.expect('code', 0) - .end(err => { - assert.ifError(err); - assert.ok(fs.existsSync(path.join(cwd, 'coverage/coverage-final.json'))); - assert.ok(fs.existsSync(path.join(cwd, 'coverage/coverage-summary.json'))); - assert.ok(fs.existsSync(path.join(cwd, 'coverage/lcov-report/index.html'))); - assert.ok(fs.existsSync(path.join(cwd, 'coverage/lcov.info'))); - done(); - }); + yield child.expect('code', 0).end(); + // only test on npm run test + if (!process.env.NYC_ROOT_ID) assertCoverage(cwd); }); - it('should hotfixSpawnWrap success on mock windows', done => { + it('should hotfixSpawnWrap success on mock windows', function* () { mm(process.env, 'TESTS', 'test/**/*.test.js'); mm(process.env, 'NYC_CWD', cwd); const child = coffee.fork(eggBin, [ 'cov' ], { cwd }) @@ -55,15 +56,10 @@ describe('test/lib/cmd/cov.test.js', () => { if (!process.env.NYC_ROOT_ID) { child.expect('stdout', /Statements {3}: 80% \( 4[\/|\\]5 \)/); } - child.expect('code', 0) - .end(err => { - assert.ifError(err); - assert.ok(fs.existsSync(path.join(cwd, 'coverage/coverage-final.json'))); - assert.ok(fs.existsSync(path.join(cwd, 'coverage/coverage-summary.json'))); - assert.ok(fs.existsSync(path.join(cwd, 'coverage/lcov-report/index.html'))); - assert.ok(fs.existsSync(path.join(cwd, 'coverage/lcov.info'))); - done(); - }); + + yield child.expect('code', 0).end(); + // only test on npm run test + if (!process.env.NYC_ROOT_ID) assertCoverage(cwd); }); it('should success with COV_EXCLUDES', function* () { @@ -82,11 +78,12 @@ describe('test/lib/cmd/cov.test.js', () => { } yield child.expect('code', 0).end(); - assert(fs.existsSync(path.join(cwd, 'coverage/coverage-final.json'))); - assert(fs.existsSync(path.join(cwd, 'coverage/lcov-report/index.html'))); - assert(fs.existsSync(path.join(cwd, 'coverage/lcov.info'))); - const lcov = fs.readFileSync(path.join(cwd, 'coverage/lcov.info'), 'utf8'); - assert(!/ignore[\/|\\]a.js/.test(lcov)); + // only test on npm run test + if (!process.env.NYC_ROOT_ID) { + assertCoverage(cwd); + const lcov = fs.readFileSync(path.join(cwd, 'coverage/lcov.info'), 'utf8'); + assert(!/ignore[\/|\\]a.js/.test(lcov)); + } }); it('should success with -x to ignore one dirs', function* () { @@ -103,11 +100,12 @@ describe('test/lib/cmd/cov.test.js', () => { } yield child.expect('code', 0).end(); - assert(fs.existsSync(path.join(cwd, 'coverage/coverage-final.json'))); - assert(fs.existsSync(path.join(cwd, 'coverage/lcov-report/index.html'))); - assert(fs.existsSync(path.join(cwd, 'coverage/lcov.info'))); - const lcov = fs.readFileSync(path.join(cwd, 'coverage/lcov.info'), 'utf8'); - assert(!/ignore[\/|\\]a.js/.test(lcov)); + // only test on npm run test + if (!process.env.NYC_ROOT_ID) { + assertCoverage(cwd); + const lcov = fs.readFileSync(path.join(cwd, 'coverage/lcov.info'), 'utf8'); + assert(!/ignore[\/|\\]a.js/.test(lcov)); + } }); it('should success with -x to ignore multi dirs', function* () { @@ -124,11 +122,12 @@ describe('test/lib/cmd/cov.test.js', () => { } yield child.expect('code', 0).end(); - assert(fs.existsSync(path.join(cwd, 'coverage/coverage-final.json'))); - assert(fs.existsSync(path.join(cwd, 'coverage/lcov-report/index.html'))); - assert(fs.existsSync(path.join(cwd, 'coverage/lcov.info'))); - const lcov = fs.readFileSync(path.join(cwd, 'coverage/lcov.info'), 'utf8'); - assert(!/ignore[\/|\\]a.js/.test(lcov)); + // only test on npm run test + if (!process.env.NYC_ROOT_ID) { + assertCoverage(cwd); + const lcov = fs.readFileSync(path.join(cwd, 'coverage/lcov.info'), 'utf8'); + assert(!/ignore[\/|\\]a.js/.test(lcov)); + } }); it('should fail when test fail', done => { diff --git a/test/lib/cmd/dev.test.js b/test/lib/cmd/dev.test.js index cdaf7c13..230d5dca 100644 --- a/test/lib/cmd/dev.test.js +++ b/test/lib/cmd/dev.test.js @@ -137,4 +137,14 @@ describe('test/lib/cmd/dev.test.js', () => { .expect('code', 0) .end(done); }); + + it('should support --require', () => { + const script = path.join(__dirname, '../../fixtures/require-script'); + mm(process.env, 'NODE_ENV', 'development'); + return coffee.fork(eggBin, [ 'dev', '--require', script ], { cwd }) + // .debug() + .expect('stdout', /hey, you require me by --require/) + .expect('code', 0) + .end(); + }); }); diff --git a/test/ts.test.js b/test/ts.test.js new file mode 100644 index 00000000..3993cd02 --- /dev/null +++ b/test/ts.test.js @@ -0,0 +1,64 @@ +'use strict'; + +const path = require('path'); +const coffee = require('coffee'); +const mm = require('mm'); + +describe('test/ts.test.js', () => { + const eggBin = require.resolve('../bin/egg-bin'); + let cwd; + + afterEach(mm.restore); + + it('should support ts', () => { + cwd = path.join(__dirname, './fixtures/ts'); + mm(process.env, 'NODE_ENV', 'development'); + return coffee.fork(eggBin, [ 'dev', '--typescript' ], { cwd }) + .debug() + .expect('stdout', /### egg from ts/) + .expect('stdout', /options.typescript=true/) + .expect('stdout', /started/) + .expect('code', 0) + .end(); + }); + + it('should support ts test', () => { + cwd = path.join(__dirname, './fixtures/ts'); + mm(process.env, 'NODE_ENV', 'development'); + return coffee.fork(eggBin, [ 'test', '--typescript' ], { cwd }) + .debug() + .notExpect('stdout', /false == true/) + .notExpect('stdout', /should not load js files/) + .expect('stdout', /--- \[string\] 'wrong assert ts'/) + .expect('code', 1) + .end(); + }); + + it('should start app', () => { + if (process.env.EGG_VERSION && process.env.EGG_VERSION === '1') { + console.log('skip egg@1'); + return; + } + cwd = path.join(__dirname, './fixtures/example-ts'); + return coffee.fork(eggBin, [ 'dev', '--ts' ], { cwd }) + .debug() + .expect('stdout', /hi, egg, 12345/) + .expect('stdout', /started/) + .expect('code', 0) + .end(); + }); + + it('should test app', () => { + if (process.env.EGG_VERSION && process.env.EGG_VERSION === '1') { + console.log('skip egg@1'); + return; + } + cwd = path.join(__dirname, './fixtures/example-ts'); + return coffee.fork(eggBin, [ 'test', '--ts' ], { cwd }) + .debug() + .expect('stdout', /hi, egg, 123456/) + .expect('stdout', /should work/) + .expect('code', 0) + .end(); + }); +});