Skip to content
This repository has been archived by the owner on Oct 19, 2021. It is now read-only.

Commit

Permalink
Test output for invalid syntax in elm input file.
Browse files Browse the repository at this point in the history
  • Loading branch information
dillonkearns committed Aug 5, 2017
1 parent a5dd4f1 commit 362a13b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
1 change: 1 addition & 0 deletions InvalidIpc.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is not a valid elm file.
6 changes: 3 additions & 3 deletions src/elm-electron.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ if (fs.existsSync(inputPath)) {
fs.writeFileSync(elmPath, elmCode)
})

app.ports.parsingError.subscribe(function(outputFile: any) {
console.log(`Error parsing input file ${inputPath}\n`)
console.log(outputFile)
app.ports.parsingError.subscribe(function(errorString: string) {
console.error(`Error parsing input file ${inputPath}\n`)
console.error(errorString)
process.exit(1)
})
} else {
Expand Down
12 changes: 11 additions & 1 deletion tests/e2e/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const expectCommandSuccess = (command: string) => {
}

describe('end to end', function() {
it('gives error for invalid input file', () => {
it('gives error for non-existent input file', () => {
const binFile = path.join(__dirname, '../../bin/elm-electron')
const ipcFile = path.join(__dirname, 'NonExistentIpc.elm')
const outputElmPath = path.join(__dirname, '../../generated', 'Result.elm')
Expand All @@ -81,6 +81,16 @@ describe('end to end', function() {
assertCommandOutput(command, 'nonexistentInputFileError')
}).timeout(30000)

it('gives error for invalid syntax input file', () => {
const binFile = path.join(__dirname, '../../bin/elm-electron')
const ipcFile = path.join(__dirname, '../../InvalidIpc.elm')
const outputElmPath = path.join(__dirname, '../../generated', 'Result.elm')
const outputTsPath = path.join(__dirname, '../../generated', 'result.ts')
const command = `/usr/local/bin/node ${binFile} ${ipcFile} --ts ${outputTsPath} --elm ${outputElmPath}`
expectCommandSuccess(`/usr/local/bin/npm run build`)
assertCommandOutput(command, 'invalidSyntaxInputFileError')
}).timeout(30000)

it('generates ts and elm files with a valid input file', () => {
const binFile = path.join(__dirname, '../../bin/elm-electron')
const ipcFile = path.join(__dirname, 'Ipc.elm')
Expand Down
6 changes: 6 additions & 0 deletions tests/e2e/invalidSyntaxInputFileError.approved.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"type": "error-result",
"stderr": "Error parsing input file /Users/dillon/Dropbox/opensource/elm-electron/InvalidIpc.elm\n\nErr ((),{ data = \"This is not a valid elm file.\\n\", input = \"This is not a valid elm file.\\n\", position = 0 },[\"expected end of input\"])\n",
"stdout": "",
"status": 1
}

0 comments on commit 362a13b

Please sign in to comment.