Skip to content
This repository was archived by the owner on Jan 15, 2025. It is now read-only.

Commit add7c62

Browse files
authored
Adding test to handle empty files and fixing error message (#269)
1 parent eee32f8 commit add7c62

File tree

5 files changed

+33
-1
lines changed

5 files changed

+33
-1
lines changed

packages/lu/src/parser/qnafile/parseQnAFile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module.exports = {
77
try {
88
QnAJSON = JSON.parse(QnAFileContent);
99
} catch (err) {
10-
throw (new exception(retCode.errorCode.INVALID_INPUT_FILE, 'Sorry, error parsing file as QnA JSON: ' + file));
10+
throw (new exception(retCode.errorCode.INVALID_INPUT_FILE, 'Sorry, error parsing QnA JSON content'))
1111
}
1212
return QnAJSON;
1313
}

packages/lu/test/commands/luis/convert.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,3 +516,19 @@ describe('luis:convert file creation', () => {
516516
})
517517
})
518518

519+
describe('luis:convert empty file handling', () => {
520+
test
521+
.stderr()
522+
.command(['luis:convert', '--in', `${path.join(__dirname, './../../fixtures/empty.lu')}`])
523+
.it('luis:convert errors out on empty lu file', async (ctx) => {
524+
expect(ctx.stderr).to.contain('[ERROR] Cannot parse empty')
525+
})
526+
527+
test
528+
.stderr()
529+
.command(['luis:convert', '--in', `${path.join(__dirname, './../../fixtures/empty.json')}`])
530+
.it('luis:convert errors out on empty json file', async (ctx) => {
531+
expect(ctx.stderr).to.contain('Sorry, error parsing content as LUIS JSON')
532+
})
533+
})
534+

packages/lu/test/commands/qnamaker/convert.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,19 @@ describe('qnamaker:convert file creation', () => {
117117
expect(ctx.stderr).to.contain('Path not found:')
118118
})
119119
})
120+
121+
describe('qnamaker:convert empty file handling', () => {
122+
test
123+
.stderr()
124+
.command(['qnamaker:convert', '--in', `${path.join(__dirname, './../../fixtures/empty.lu')}`])
125+
.it('qnamaker:convert errors out on empty lu file', async (ctx) => {
126+
expect(ctx.stderr).to.contain('[ERROR] Cannot parse empty')
127+
})
128+
129+
test
130+
.stderr()
131+
.command(['qnamaker:convert', '--in', `${path.join(__dirname, './../../fixtures/empty.json')}`])
132+
.it('qnamaker:convert errors out on empty json file', async (ctx) => {
133+
expect(ctx.stderr).to.contain('Sorry, error parsing QnA JSON content')
134+
})
135+
})

packages/lu/test/fixtures/empty.json

Whitespace-only changes.

packages/lu/test/fixtures/empty.lu

Whitespace-only changes.

0 commit comments

Comments
 (0)