Skip to content

Commit 994d578

Browse files
committed
add error-path tests for command execution
1 parent 5ea73d3 commit 994d578

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

test/commands/CommandExecution.test.ts

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ beforeAll(() => {
1818

1919
afterEach(async () => {
2020
await clearDocuments(services.shared, services.shared.workspace.LangiumDocuments.all.toArray())
21-
fs.rmSync(outDir, { recursive: true })
21+
fs.rmSync(outDir, {
22+
recursive: true,
23+
force: true
24+
})
2225
})
2326

2427
describe('Command execution tests', () => {
@@ -31,4 +34,34 @@ describe('Command execution tests', () => {
3134
const outContent = fs.readdirSync(outDir)
3235
expect(outContent).toHaveLength(1)
3336
})
37+
38+
test('test plantUML command with invalid file extension', async () => {
39+
const file = path.join(__dirname, '..', 'invalid-files', 'test.txt')
40+
41+
const result = await commandHandler.executeCommand('org.contextmapper.GeneratePlantUML', [file, outDir])
42+
expect(result).toBeUndefined()
43+
44+
const outContentExists = fs.existsSync(outDir)
45+
expect(outContentExists).toEqual(false)
46+
})
47+
48+
test('test plantUML command with invalid file', async () => {
49+
const file = path.join(__dirname, '..', 'invalid-files', 'invalid.cml')
50+
51+
const result = await commandHandler.executeCommand('org.contextmapper.GeneratePlantUML', [file, outDir])
52+
expect(result).toBeUndefined()
53+
54+
const outContentExists = fs.existsSync(outDir)
55+
expect(outContentExists).toEqual(false)
56+
})
57+
58+
test('test plantUML command with non-existing file', async () => {
59+
const file = path.join(__dirname, '..', 'invalid-files', 'non-existing.cml')
60+
61+
const result = await commandHandler.executeCommand('org.contextmapper.GeneratePlantUML', [file, outDir])
62+
expect(result).toBeUndefined()
63+
64+
const outContentExists = fs.existsSync(outDir)
65+
expect(outContentExists).toEqual(false)
66+
})
3467
})

test/invalid-files/invalid.cml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
ContextMap {
2+
contains TestContext
3+
}
4+
5+
BoundedContext TestContext {

test/invalid-files/test.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Invalid file extension

0 commit comments

Comments
 (0)