Skip to content
This repository has been archived by the owner on May 4, 2024. It is now read-only.

Commit

Permalink
some tests for index.js parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs committed Jul 31, 2019
1 parent 67f2d8d commit 4e1e4d2
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
14 changes: 14 additions & 0 deletions test/fixtures/indexjs-bad/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**package
* {
* "name": "indexjs-test",
* "version": "1.2.3",
* "description": "Did you know npm could do this, even?",
* "main": "index.js"
*
* but alas, 'twas not to be,
* for, when parse the comment we,
* json is not there to see
*
* }
**/
console.log('just a broken single-file package')
9 changes: 9 additions & 0 deletions test/fixtures/indexjs/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**package
* {
* "name": "indexjs-test",
* "version": "1.2.3",
* "description": "Did you know npm could do this, even?",
* "main": "index.js"
* }
**/
console.log('just a simple single-file package')
32 changes: 32 additions & 0 deletions test/indexjs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const t = require('tap')
const read = require('../')
const { resolve } = require('path')
t.test('read from an index.js file', t => {
const fixture = resolve(__dirname, 'fixtures/indexjs/package.json')
read(fixture, (er, data) => {
if (er) {
throw er
}
t.match(data, {
name: 'indexjs-test',
version: '1.2.3',
description: 'Did you know npm could do this, even?',
main: 'index.js',
readme: 'ERROR: No README data found!',
_id: '[email protected]'
})
t.end()
})
})

t.test('read broken json', t => {
const fixture = resolve(__dirname, 'fixtures/indexjs-bad/package.json')
read(fixture, (er, data) => {
t.match(er, {
code: 'ENOENT',
path: fixture
})
t.notOk(data)
t.end()
})
})

0 comments on commit 4e1e4d2

Please sign in to comment.