'use strict';

const request = require('supertest');
const mm = require('egg-mock');
const runscript = require('runscript');
const path = require('path');
const utils = require('../utils');
const baseDir = path.join(__dirname, '../fixtures/apps/app-ts');

describe('test/ts/index.test.js', () => {
  before(function* () {
    if (process.env.CI) {
      yield runscript('tsc && npmlink ../../../../', { cwd: baseDir });
    } else {
      yield runscript('tsc && npm link ../../../../', { cwd: baseDir });
    }
  });

  describe('compiler code', () => {

    afterEach(mm.restore);
    let app;
    before(function* () {
      app = utils.app('apps/app-ts');
      yield app.ready();
    });
    after(function* () {
      yield app.close();
    });

    it('controller run ok', done => {
      request(app.callback())
        .get('/foo')
        .expect(200)
        .expect({ env: 'unittest' })
        .end(done);
    });
  });

});


@@ -252,264 +252,400 @@
 ');%0A
-%0Adescribe('test/ts/index.test.js', () =%3E %7B%0A  before(function* () %7B%0A    if (process.env.CI) %7B%0A      yield runscript('tsc && npmlink ../../../../', %7B cwd: baseDir %7D);%0A    %7D else %7B
+const fs = require('fs');%0Aconst mkdirp = require('mz-modules/mkdirp');%0Aconst rimraf = require('mz-modules/rimraf');%0A%0Adescribe('test/ts/index.test.js', () =%3E %7B%0A  before(function* () %7B%0A    yield runscript('tsc', %7B cwd: baseDir %7D);%0A    const dest = path.join(baseDir, 'node_modules/egg');
 %0A    
-  
 yield r
-unscript('tsc && npm link ../../../../', %7B cwd: baseDir %7D);%0A    %7D
+imraf(dest);%0A    yield mkdirp(path.dirname(dest));%0A    fs.symlinkSync('../../../../../', dest);
 %0A  %7D
@@ -1063,13 +1063,12 @@
 %0A  %7D);%0A%0A%7D);%0A
-%0A

fix tsc test case (#1620)