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

Commit 4e1e4d2

Browse files
committed
some tests for index.js parsing
1 parent 67f2d8d commit 4e1e4d2

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

test/fixtures/indexjs-bad/index.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**package
2+
* {
3+
* "name": "indexjs-test",
4+
* "version": "1.2.3",
5+
* "description": "Did you know npm could do this, even?",
6+
* "main": "index.js"
7+
*
8+
* but alas, 'twas not to be,
9+
* for, when parse the comment we,
10+
* json is not there to see
11+
*
12+
* }
13+
**/
14+
console.log('just a broken single-file package')

test/fixtures/indexjs/index.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**package
2+
* {
3+
* "name": "indexjs-test",
4+
* "version": "1.2.3",
5+
* "description": "Did you know npm could do this, even?",
6+
* "main": "index.js"
7+
* }
8+
**/
9+
console.log('just a simple single-file package')

test/indexjs.js

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
const t = require('tap')
2+
const read = require('../')
3+
const { resolve } = require('path')
4+
t.test('read from an index.js file', t => {
5+
const fixture = resolve(__dirname, 'fixtures/indexjs/package.json')
6+
read(fixture, (er, data) => {
7+
if (er) {
8+
throw er
9+
}
10+
t.match(data, {
11+
name: 'indexjs-test',
12+
version: '1.2.3',
13+
description: 'Did you know npm could do this, even?',
14+
main: 'index.js',
15+
readme: 'ERROR: No README data found!',
16+
_id: 'indexjs-test@1.2.3'
17+
})
18+
t.end()
19+
})
20+
})
21+
22+
t.test('read broken json', t => {
23+
const fixture = resolve(__dirname, 'fixtures/indexjs-bad/package.json')
24+
read(fixture, (er, data) => {
25+
t.match(er, {
26+
code: 'ENOENT',
27+
path: fixture
28+
})
29+
t.notOk(data)
30+
t.end()
31+
})
32+
})

0 commit comments

Comments
 (0)