mirror of
https://github.com/harish2704/npm-offline-registry.git
synced 2026-09-10 06:21:09 +00:00
More tests
* Make functions as async * handle failures
This commit is contained in:
+56
-12
@@ -1,4 +1,4 @@
|
|||||||
/* globals describe, it */
|
/* globals describe, it, before */
|
||||||
|
|
||||||
var utils = require( '../utils' );
|
var utils = require( '../utils' );
|
||||||
var assert = require('assert');
|
var assert = require('assert');
|
||||||
@@ -8,25 +8,69 @@ var path = require('path');
|
|||||||
|
|
||||||
var fetchAndCacheMetadata = utils.fetchAndCacheMetadata;
|
var fetchAndCacheMetadata = utils.fetchAndCacheMetadata;
|
||||||
var fetchAndCacheTarball = utils.fetchAndCacheTarball;
|
var fetchAndCacheTarball = utils.fetchAndCacheTarball;
|
||||||
|
var exec = utils.exec;
|
||||||
|
|
||||||
/* TODO: write test */
|
/* TODO: write test */
|
||||||
// var patchData = utils.patchData;
|
// var patchData = utils.patchData;
|
||||||
|
|
||||||
|
var homeDir = process.env.HOME;
|
||||||
|
var testCacheFile = homeDir + '/.npm/registry.npmjs.org/lodash/.cache.json';
|
||||||
|
var testPackageFile = homeDir + '/.npm/lodash/4.2.1/package.tgz';
|
||||||
|
|
||||||
describe( 'Utility functions ', function(){
|
|
||||||
|
|
||||||
it.skip( 'should fetchAndCacheMetadata', function( ){
|
|
||||||
var cacheFile = '/home/hari/.npm/registry.npmjs.org/lodash/.cache.json';
|
describe( 'Utility function s', function(){
|
||||||
fetchAndCacheMetadata( 'lodash', cacheFile );
|
|
||||||
assert( fs.existsSync( cacheFile ) );
|
|
||||||
|
before( function(done){
|
||||||
|
var cmd = [
|
||||||
|
'if [[ -f $testCacheFile ]]; then rm $testCacheFile; fi',
|
||||||
|
'if [[ -f $testPackageFile ]]; then rm $testPackageFile; fi'
|
||||||
|
].join( ';' );
|
||||||
|
|
||||||
|
return exec( cmd , {
|
||||||
|
testCacheFile: testCacheFile,
|
||||||
|
testPackageFile: testPackageFile
|
||||||
|
})
|
||||||
|
.then( done );
|
||||||
});
|
});
|
||||||
|
|
||||||
it( 'should fetchAndCacheTarball', function(){
|
|
||||||
var cacheFile = '/home/hari/.npm/lodash/4.2.1/package.tgz';
|
|
||||||
var packageJsonFile = path.dirname( cacheFile ) + '/package/package.json';
|
|
||||||
|
|
||||||
fetchAndCacheTarball( 'lodash', '4.2.1', cacheFile );
|
it( 'should fetchAndCacheMetadata', function( done ){
|
||||||
assert( fs.existsSync( cacheFile ) );
|
|
||||||
assert( fs.existsSync( packageJsonFile ) );
|
fetchAndCacheMetadata( 'lodash', testCacheFile )
|
||||||
|
.then( function(){
|
||||||
|
assert( fs.existsSync( testCacheFile ) );
|
||||||
|
done();
|
||||||
|
})
|
||||||
|
.catch( done );
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
it( 'should fetchAndCacheTarball', function( done ){
|
||||||
|
var packageJsonFile = path.dirname( testPackageFile ) + '/package/package.json';
|
||||||
|
|
||||||
|
fetchAndCacheTarball( 'lodash', '4.2.1', testPackageFile )
|
||||||
|
.then( function(){
|
||||||
|
assert( fs.existsSync( testPackageFile ) );
|
||||||
|
assert( fs.existsSync( packageJsonFile ) );
|
||||||
|
done();
|
||||||
|
})
|
||||||
|
.catch( done );
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
it( 'should fail if downloading fails', function( done ){
|
||||||
|
fetchAndCacheMetadata( '456613231')
|
||||||
|
.then( function(){
|
||||||
|
return done( new Error('This should not resolve' ) );
|
||||||
|
})
|
||||||
|
.catch( function(e){
|
||||||
|
assert.ok( e );
|
||||||
|
assert.ok ( !fs.existsSync( homeDir + '/.npm/registry.npmjs.org/456613231/.cache.json' ) );
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user