-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4ceacc3
commit 307fc2c
Showing
2 changed files
with
54 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,7 +46,6 @@ t.test('clean up bundleddddddDependencies', async t => { | |
}), | ||
}) + '/package.json'), { bundleDependencies: [] })) | ||
|
||
|
||
t.test('handle bundleDependencies: false', t => | ||
t.resolveMatch(rpj(t.testdir({ | ||
'package.json': JSON.stringify({ | ||
|
@@ -77,29 +76,29 @@ t.test('clean up scripts', async t => { | |
'package.json': JSON.stringify({ | ||
scripts: { | ||
foo: 'bar', | ||
bar: [ 'baz' ], | ||
bar: ['baz'], | ||
baz: { bar: { foo: 'barbaz' } }, | ||
}, | ||
}) | ||
}), | ||
}) + '/package.json'), { | ||
scripts: { | ||
foo: 'bar', | ||
bar: undefined, | ||
baz: undefined, | ||
} | ||
}, | ||
})) | ||
}) | ||
|
||
t.test('convert funding string to object', t => | ||
t.resolveMatch(rpj(t.testdir({ | ||
'package.json': JSON.stringify({ funding: 'hello' }) | ||
'package.json': JSON.stringify({ funding: 'hello' }), | ||
}) + '/package.json'), { funding: { url: 'hello' } })) | ||
|
||
t.test('cleanup bins', async t => { | ||
t.test('handle string when a name is set', t => | ||
t.resolveMatch(rpj(t.testdir({ | ||
'package.json': JSON.stringify({ name: 'x', bin: 'y' }), | ||
}) + '/package.json'), { bin: { x: 'y' }})) | ||
}) + '/package.json'), { bin: { x: 'y' } })) | ||
|
||
t.test('delete string bin when no name', t => | ||
t.resolveMatch(rpj(t.testdir({ | ||
|
@@ -117,49 +116,49 @@ t.test('cleanup bins', async t => { | |
x: 'y', | ||
y: 1234, | ||
z: { a: 'b' }, | ||
}}), | ||
}) + '/package.json'), { bin: {x:'y', y: undefined, z: undefined }})) | ||
} }), | ||
}) + '/package.json'), { bin: { x: 'y', y: undefined, z: undefined } })) | ||
}) | ||
|
||
t.test('dedupe optional deps out of regular deps', async t => { | ||
t.test('choose optional deps in conflict', t => | ||
t.resolveMatch(rpj(t.testdir({ | ||
'package.json': JSON.stringify({ | ||
optionalDependencies: { | ||
whowins: '1.2.3-optional' | ||
whowins: '1.2.3-optional', | ||
}, | ||
dependencies: { | ||
whowins: '1.2.3-prod' | ||
} | ||
whowins: '1.2.3-prod', | ||
}, | ||
}), | ||
}) + '/package.json'), { | ||
optionalDependencies: { | ||
whowins: '1.2.3-optional' | ||
whowins: '1.2.3-optional', | ||
}, | ||
})) | ||
|
||
t.test('do not create regular deps if only optional specified', t => | ||
t.resolveMatch(rpj(t.testdir({ | ||
'package.json': JSON.stringify({ | ||
optionalDependencies: { | ||
whowins: '1.2.3-optional' | ||
whowins: '1.2.3-optional', | ||
}, | ||
}), | ||
}) + '/package.json'), { | ||
optionalDependencies: { | ||
whowins: '1.2.3-optional' | ||
whowins: '1.2.3-optional', | ||
}, | ||
})) | ||
}) | ||
|
||
t.test('set _id if name and version set', t => | ||
t.resolveMatch(rpj(t.testdir({ | ||
'package.json': JSON.stringify({name:'a', version: '1.2.3'}), | ||
'package.json': JSON.stringify({ name: 'a', version: '1.2.3' }), | ||
}) + '/package.json'), { _id: '[email protected]' })) | ||
|
||
t.test('exports the normalize function', async t => | ||
t.same(rpj.normalize({ bundledDependencies: true, dependencies: {a:'1'}}), | ||
{ bundleDependencies: ['a'], dependencies: {a:'1'}})) | ||
t.same(rpj.normalize({ bundledDependencies: true, dependencies: { a: '1' } }), | ||
{ bundleDependencies: ['a'], dependencies: { a: '1' } })) | ||
|
||
t.test('preserve indentation', async t => { | ||
const obj = { | ||
|
@@ -278,20 +277,22 @@ t.test('strip _fields', async t => { | |
t.test('load directories.bin', async t => { | ||
const { basename } = require('path') | ||
const fs = require('fs') | ||
const rpj = t.mock('../', { | ||
const rpjMock = t.mock('../', { | ||
fs: { | ||
...fs, | ||
lstat: (p, cb) => { | ||
if (basename(p) === 'staterror') | ||
if (basename(p) === 'staterror') { | ||
cb(new Error('stat error')) | ||
else | ||
} else { | ||
return fs.lstat(p, cb) | ||
} | ||
}, | ||
readdir: (p, cb) => { | ||
if (basename(p) === 'readdirerror') { | ||
cb(new Error('readdir error')) | ||
} else | ||
} else { | ||
return fs.readdir(p, cb) | ||
} | ||
}, | ||
}, | ||
}) | ||
|
@@ -323,7 +324,7 @@ t.test('load directories.bin', async t => { | |
}, | ||
}, | ||
}) | ||
t.strictSame(await rpj(`${path}/package.json`), { | ||
t.strictSame(await rpjMock(`${path}/package.json`), { | ||
name: 'foo', | ||
version: '1.2.3', | ||
_id: '[email protected]', | ||
|