Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for file not found #9

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions test/fromFile.test.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,57 @@
const { strictEqual, throws } = require('assert')
const { strictEqual } = require('assert')
const assert = require('assert/strict')
const { resolve } = require('path')
const { promisify } = require('util')
const { isReadable } = require('isstream')
const { describe, it } = require('mocha')
const rdf = require('rdf-ext')
const { finished } = require('readable-stream')
const fromFile = require('../fromFile')
const example = require('./support/example')

describe('fromFile', () => {
it('should create a quad stream', async () => {
const stream = fromFile(resolve(__dirname, 'support/example.nt'))

stream.resume()

strictEqual(isReadable(stream), true)
})

it('should forward options to parser', async () => {
const stream = fromFile(resolve(__dirname, 'support/example.ttl'), { baseIRI: 'http://example.org/' })
const dataset = await rdf.dataset().import(stream)

strictEqual(dataset.toCanonical(), example().toCanonical())
})

it('should throw an error if the file extension is unknown', () => {
throws(() => {
assert.throws(() => {
fromFile('test.jpg')
}, {
name: 'Error',
message: 'Unknown file extension: jpg'
})
})

it('should throw an error if the media type is unknown', () => {
throws(() => {
assert.throws(() => {
fromFile('test.jpg', {
extensions: {
jpg: 'image/jpeg'
}
})
}, {
name: 'Error',
message: 'No parser available for media type: image/jpeg'
})
})

it('should throw an error if the file does not exist', async () => {
await assert.rejects(async () => {
const stream = fromFile('void.ttl')
stream.resume()
await promisify(finished)(stream)
}, {
name: 'Error',
message: "ENOENT: no such file or directory, open 'void.ttl'"
})
})
})