Skip to content

Commit 4e97863

Browse files
committed
add --prefer-ts adn --prefer-ts-exts tests
1 parent bbdfc4c commit 4e97863

File tree

7 files changed

+52
-4
lines changed

7 files changed

+52
-4
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ tsnd --respawn server.ts
3939

4040
**Also there are additional options specific to `ts-node-dev`:**
4141

42-
- `--prefer-ts` (default: false) - for each `.js` file (that is not in `node_modules`) will try to check if corresponding `.ts` version exists and require it.
43-
- `--ignore-watch` (default: []) - files/folders to be [ignored by `node-dev`](https://github.com/fgnass/node-dev#ignore-paths). **But also this behaviour enhanced:** it will also make up `new RegExp` of passed ignore string and check absolute paths of required files for match.
42+
- `--prefer-ts` (`--prefer-ts-exts`) - (default: false) - For each `.js` file (that is not in `node_modules`) will try to check if corresponding `.ts` version exists and require it.
43+
- `--ignore-watch` - (default: []) - files/folders to be [ignored by `node-dev`](https://github.com/fgnass/node-dev#ignore-paths). **But also this behaviour enhanced:** it will also make up `new RegExp` of passed ignore string and check absolute paths of required files for match.
4444
So, to ignore everything in `node_modules`, just pass `--ignore-watch node_modules`, or us `--no-deps` for the same effect.
4545

4646
- `--debug` - Some additional debug output.

lib/compiler.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ var compiler = {
7070
if (compiler.allowJs) {
7171
fileData = fileData.replace('allowJs = false', 'allowJs = true')
7272
}
73-
if (options['prefer-ts']) {
73+
if (options['prefer-ts'] || options['prefer-ts-exts']) {
7474
fileData = fileData.replace('preferTs = false', 'preferTs = true')
7575
}
7676
if (options['exec-check']) {
@@ -199,7 +199,7 @@ var compiler = {
199199
options['ignoreDiagnostics'] || options['ignore-diagnostics'],
200200
logError: options['log-error'],
201201
disableWarnings: options['disableWarnings'],
202-
preferTsExts: options['prefer-ts-exts'],
202+
preferTsExts: options['prefer-ts-exts'] || options['prefer-ts'],
203203
compilerOptions: compilerOptions,
204204
files: options['files'] || true,
205205
}

test/fixture/prefer/prefer-dep.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log('PREFER DEP JS')

test/fixture/prefer/prefer-dep.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log('PREFER DEP TS')

test/fixture/prefer/prefer.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
require('./prefer-dep')
2+
console.log('PREFER JS')

test/fixture/prefer/prefer.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import './prefer-dep'
2+
console.log('PREFER TS')

test/index.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,3 +189,45 @@ test('It allows to use custom TS Transformers', async (t) => {
189189
await ps.waitForLine(/transformed/)
190190
await ps.exit()
191191
})
192+
//
193+
test.only('It should --prefer-ts', async (t) => {
194+
t.test('Should require JS by default', async (t) => {
195+
const ps = spawnTsNodeDev(
196+
[
197+
`--respawn`,
198+
//`--prefer-ts-exts`,
199+
`prefer/prefer.js`,
200+
].join(' ')
201+
).turnOnOutput()
202+
await ps.waitForLine(/PREFER DEP JS/)
203+
await ps.waitForLine(/PREFER JS/)
204+
await ps.exit()
205+
t.pass()
206+
})
207+
t.test('SHould require JS deps by default', async (t) => {
208+
const ps = spawnTsNodeDev(
209+
[
210+
`--respawn`,
211+
//`--prefer-ts`,
212+
`prefer/prefer`,
213+
].join(' ')
214+
).turnOnOutput()
215+
await ps.waitForLine(/PREFER DEP JS/)
216+
await ps.waitForLine(/PREFER TS/)
217+
await ps.exit()
218+
t.pass()
219+
})
220+
t.test('Use require all TS with --ts-prefer', async (t) => {
221+
const ps = spawnTsNodeDev(
222+
[
223+
`--respawn`,
224+
`--prefer-ts-exts`,
225+
`prefer/prefer.js`,
226+
].join(' ')
227+
).turnOnOutput()
228+
await ps.waitForLine(/PREFER DEP TS/)
229+
await ps.waitForLine(/PREFER TS/)
230+
await ps.exit()
231+
t.pass()
232+
})
233+
})

0 commit comments

Comments
 (0)