Skip to content

Commit

Permalink
[v0.11.2]: bug fixes for 'parseDatasetIdentifier' function when provi…
Browse files Browse the repository at this point in the history
…ded path is `datapackage.json` in cwd - refs datopian/data-cli#337
  • Loading branch information
anuveyatsu committed Apr 19, 2018
1 parent d7f3349 commit bcb429e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
4 changes: 2 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,11 +262,11 @@ const parseDatasetIdentifier = async (path_) => {
if (path_ === null || path_ === '') return out

out.type = isUrl(path_) ? 'url' : 'local'
let normalizedPath = path_.replace('/datapackage.json', '')
let normalizedPath = path_.replace(/\/?datapackage\.json/, '')
normalizedPath = normalizedPath.replace(/\/$/, '')
if (out.type === 'local') {
out.path = path.posix.resolve(normalizedPath)
out.name = path.basename(normalizedPath)
out.name = path.basename(out.path)
} else if (out.type === 'url') {
const urlparts = url.parse(normalizedPath)
const parts = urlparts.pathname.split('/')
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "data.js",
"version": "0.11.1",
"version": "0.11.2",
"description": "",
"main": "lib/index.js",
"directories": {
Expand Down
31 changes: 20 additions & 11 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,26 @@ test('isDataset function works', t => {
// parseDatasetIdentifier

test('parseDatasetIdentifier function with local path', async t => {
const path_ = '../dir/dataset/'
const res = await data.parseDatasetIdentifier(path_)
const exp = {
name: 'dataset',
owner: null,
path: path.posix.resolve(path_),
type: 'local',
original: path_,
version: ''
}
t.deepEqual(res, exp)
const paths = [
'../dir/dataset/',
'./',
'./datapackage.json',
'../datapackage.json',
'datapackage.json'
]
paths.forEach(async path_ => {
const res = await data.parseDatasetIdentifier(path_)
const normalizedPath = path.posix.resolve(path_).replace(/\/?datapackage\.json/, '')
const exp = {
name: path.basename(normalizedPath),
owner: null,
path: normalizedPath,
type: 'local',
original: path_,
version: ''
}
t.deepEqual(res, exp)
})
})

test('parseDatasetIdentifier function with random url', async t => {
Expand Down

0 comments on commit bcb429e

Please sign in to comment.