-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: using ts-node in app should check tscompiler and deps (#170)
* fix: local ts-node * fix: local ts node * fix: ci * fix: ci * fix: ci * test: add more test cases * fix: remove useless code * fix: ci * chore: update comment * chore: use cpy
- Loading branch information
Showing
11 changed files
with
110 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
test/fixtures/example-ts-custom-compiler-2/config/config.default.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
'use strict'; | ||
|
||
export const key = '12345'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"name": "example-ts-custom-compiler-2" | ||
} |
8 changes: 0 additions & 8 deletions
8
test/fixtures/example-ts-custom-compiler/node_modules/egg/index.js
This file was deleted.
Oops, something went wrong.
3 changes: 0 additions & 3 deletions
3
test/fixtures/example-ts-custom-compiler/node_modules/egg/package.json
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
{ | ||
"name": "example-ts-custom-compiler" | ||
} | ||
"name": "example-ts-custom-compiler", | ||
"dependencies": { | ||
"ts-node": "^8.10.2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
describe('test', () => { | ||
it('should ok', () => { | ||
console.info(process.argv); | ||
console.info(process.execArgv); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ const path = require('path'); | |
const coffee = require('coffee'); | ||
const mm = require('mm'); | ||
const fs = require('fs'); | ||
const cpy = require('cpy'); | ||
const rimraf = require('mz-modules/rimraf'); | ||
const exec = require('mz/child_process').exec; | ||
const os = require('os'); | ||
|
@@ -209,22 +210,73 @@ describe('test/ts.test.js', () => { | |
const cwd = path.join(__dirname, './fixtures/example-ts-custom-compiler'); | ||
|
||
// install custom ts-node | ||
await exec('npx cnpm install [email protected]', { cwd: path.join(__dirname, './fixtures') }); | ||
await rimraf(path.join(cwd, 'node_modules')); | ||
await exec('npx cnpm install', { cwd }); | ||
|
||
// copy egg to node_modules | ||
await cpy( | ||
path.join(__dirname, './fixtures/example-ts-cluster/node_modules/egg'), | ||
path.join(cwd, './node_modules/egg') | ||
); | ||
|
||
const { stderr, code } = await coffee.fork(eggBin, [ 'dev', '--ts' ], { cwd, env: { DEBUG: 'egg-bin' } }) | ||
.debug() | ||
// .debug() | ||
.end(); | ||
assert(/ts-node@8\.10\.2/.test(stderr)); | ||
assert.equal(code, 0); | ||
}); | ||
|
||
it('should load custom ts compiler with tscompiler args', async () => { | ||
const cwd = path.join(__dirname, './fixtures/example-ts-custom-compiler-2'); | ||
|
||
// install custom ts-node | ||
await rimraf(path.join(cwd, 'node_modules')); | ||
await exec('npx cnpm install [email protected] --no-save', { cwd }); | ||
|
||
// copy egg to node_modules | ||
await cpy( | ||
path.join(__dirname, './fixtures/example-ts-cluster/node_modules/egg'), | ||
path.join(cwd, './node_modules/egg') | ||
); | ||
|
||
const { stderr, code } = await coffee.fork(eggBin, [ | ||
'dev', '--ts', '--tscompiler=ts-node/register', | ||
], { cwd, env: { DEBUG: 'egg-bin' } }) | ||
// .debug() | ||
.end(); | ||
assert(/ts-node@8\.10\.2/.test(stderr)); | ||
assert.equal(code, 0); | ||
}); | ||
|
||
it('should not load custom ts compiler without tscompiler args', async () => { | ||
const cwd = path.join(__dirname, './fixtures/example-ts-custom-compiler-2'); | ||
|
||
// install custom ts-node | ||
await rimraf(path.join(cwd, 'node_modules')); | ||
await exec('npx cnpm install [email protected] --no-save', { cwd }); | ||
|
||
// copy egg to node_modules | ||
await cpy( | ||
path.join(__dirname, './fixtures/example-ts-cluster/node_modules/egg'), | ||
path.join(cwd, './node_modules/egg') | ||
); | ||
|
||
const { stderr, code } = await coffee.fork(eggBin, [ 'dev', '--ts' ], { cwd, env: { DEBUG: 'egg-bin' } }) | ||
// .debug() | ||
.end(); | ||
assert(!/ts-node@8\.10\.2/.test(stderr)); | ||
assert(/ts-node@7\.\d+\.\d+/.test(stderr)); | ||
assert.equal(code, 0); | ||
}); | ||
|
||
it('should start app with other tscompiler without error', () => { | ||
return coffee.fork(eggBin, [ 'dev', '--ts', '--tscompiler=esbuild-register' ], { | ||
cwd: path.join(__dirname, './fixtures/example-ts'), | ||
}) | ||
// .debug() | ||
.expect('stdout', /agent.options.typescript = true/) | ||
.expect('stdout', /agent.options.tscompiler = esbuild-register/) | ||
.expect('stdout', /agent.options.tscompiler =/) | ||
.expect('stdout', /esbuild-register/) | ||
.expect('stdout', /started/) | ||
.expect('code', 0) | ||
.end(); | ||
|
@@ -236,7 +288,8 @@ describe('test/ts.test.js', () => { | |
}) | ||
// .debug() | ||
.expect('stdout', /agent.options.typescript = true/) | ||
.expect('stdout', /agent.options.tscompiler = esbuild-register/) | ||
.expect('stdout', /agent.options.tscompiler =/) | ||
.expect('stdout', /esbuild-register/) | ||
.expect('stdout', /started/) | ||
.expect('code', 0) | ||
.end(); | ||
|
@@ -251,6 +304,27 @@ describe('test/ts.test.js', () => { | |
.end(); | ||
}); | ||
|
||
it('should test with custom ts compiler without error', async () => { | ||
const cwd = path.join(__dirname, './fixtures/example-ts-custom-compiler'); | ||
|
||
// install custom ts-node | ||
await rimraf(path.join(cwd, 'node_modules')); | ||
await exec('npx cnpm install', { cwd }); | ||
|
||
// copy egg to node_modules | ||
await cpy( | ||
path.join(__dirname, './fixtures/example-ts-cluster/node_modules/egg'), | ||
path.join(cwd, './node_modules/egg') | ||
); | ||
|
||
const { stdout, code } = await coffee.fork(eggBin, [ 'test', '--ts' ], { cwd, env: { DEBUG: 'egg-bin' } }) | ||
// .debug() | ||
.end(); | ||
assert(/ts-node@8\.10\.2/.test(stdout)); | ||
assert(!/ts-node@7\.\d+\.\d+/.test(stdout)); | ||
assert.equal(code, 0); | ||
}); | ||
|
||
it('should cov app', () => { | ||
return coffee.fork(eggBin, [ 'cov' ], { cwd }) | ||
// .debug() | ||
|