Skip to content

Commit 8d9fba8

Browse files
committed
add tests --log-error
1 parent 3b3bc3a commit 8d9fba8

File tree

6 files changed

+43
-3
lines changed

6 files changed

+43
-3
lines changed

test/fixture/.rcfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
console.log('NO EXT')
2+
3+
exports.x = 1

test/fixture/file.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"file": "json"
3+
}

test/fixture/folder2/nest/other-file

Whitespace-only changes.

test/fixture/js-module.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,9 @@ import { fn } from './dep'
22

33
console.log(fn(1))
44

5+
require('./.rcfile')
6+
7+
const json = require('./file.json')
8+
9+
console.log('json',json)
510
console.log('JS MODULE')

test/index.ts

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ test('It should report an error on start', async (t) => {
7777
const ps = spawnTsNodeDev('--respawn with-error.ts')
7878
await ps.waitForLine(/[ERROR]/)
7979
const out = ps.getStdout()
80-
t.ok(/Compilation error in/.test(out), 'Report error file')
80+
t.ok(/Compilation error in/.test(out), 'Reports error file')
8181
t.ok(/[ERROR].*Unable to compile TypeScript/.test(out), 'Report TS error')
8282
t.ok(/Argument of type/.test(out), 'Report TS error diagnostics')
8383

@@ -92,6 +92,22 @@ test('It should report an error on start', async (t) => {
9292
await replaceText('with-error.ts', '1', `'1'`)
9393
})
9494

95+
test.only('It should report an error with --log-error and continue to work', async (t) => {
96+
const ps = spawnTsNodeDev('--respawn --log-error with-error.ts') //.turnOnOutput()
97+
await ps.waitForErrorLine(/error/)
98+
99+
const out = ps.getStderr()
100+
t.ok(/error.*Argument of type/.test(out), 'Reports error in stderr')
101+
102+
setTimeout(() => replaceText('with-error.ts', `'1'`, '1'), 250)
103+
104+
await ps.waitForLine(/Restarting:/)
105+
await ps.waitForLine(/v1/)
106+
t.pass('Restarted successfully after error fixed.')
107+
await ps.exit()
108+
await replaceText('with-error.ts', '1', `'1'`)
109+
})
110+
95111
test('It should restart on adding not imported module', async (t) => {
96112
const ps = spawnTsNodeDev('--respawn --error-recompile with-error.ts', {
97113
// stdout: true,
@@ -136,10 +152,11 @@ test('It handles allowJs option and loads JS modules', async (t) => {
136152
[
137153
`--respawn`,
138154
`--compiler ttypescript`,
139-
`--compilerOptions=${JSON.stringify(cOptions)}`,
155+
`--compiler-options=${JSON.stringify(cOptions)}`,
156+
//'--ignore .rcfile',
140157
`js-module.js`,
141158
].join(' ')
142-
) //.turnOnOutput()
159+
).turnOnOutput()
143160
await ps.waitForLine(/JS MODULE/)
144161
await ps.exit()
145162
})

test/spawn.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,18 @@ export const spawnTsNodeDev = (
6060
ps.stdout.on('data', listener)
6161
})
6262
},
63+
waitForErrorLine: (pattern: string | RegExp) => {
64+
return new Promise((resolve) => {
65+
const listener = (data: string) => {
66+
const line = data.toString()
67+
if (testPattern(pattern, line)) {
68+
ps.stderr.removeListener('data', listener)
69+
resolve(line)
70+
}
71+
}
72+
ps.stderr.on('data', listener)
73+
})
74+
},
6375
exit: () => {
6476
return new Promise((resolve) => {
6577
ps.stdout.removeAllListeners('data')

0 commit comments

Comments
 (0)