smartarchive/test/test.ts

52 lines
1.6 KiB
TypeScript
Raw Permalink Normal View History

2020-03-13 20:22:56 +00:00
import { tap, expect } from '@pushrocks/tapbundle';
2020-03-16 14:38:17 +00:00
import * as path from 'path';
import * as smartfile from '@pushrocks/smartfile';
2020-03-13 20:22:56 +00:00
import * as smartrequest from '@pushrocks/smartrequest';
2020-03-16 14:38:17 +00:00
const testPlugins = {
path,
smartfile,
smartrequest
};
const testPaths = {
2020-03-16 17:04:17 +00:00
nogitDir: testPlugins.path.join(process.cwd(), '.nogit/'),
remoteDir: testPlugins.path.join(process.cwd(), '.nogit/remote')
2020-03-16 15:13:58 +00:00
};
2020-03-16 14:38:17 +00:00
import * as smartarchive from '../ts/index';
tap.preTask('should prepare .nogit dir', async () => {
await testPlugins.smartfile.fs.ensureDir(testPaths.nogitDir);
2020-03-16 17:04:17 +00:00
await testPlugins.smartfile.fs.ensureDir(testPaths.remoteDir);
2020-03-13 20:22:56 +00:00
});
2020-03-16 14:38:17 +00:00
tap.preTask('should prepare downloads', async tools => {
const downloadedFile: Buffer = (
2020-03-16 15:13:58 +00:00
await testPlugins.smartrequest.getBinary(
'https://verdaccio.lossless.one/@pushrocks%2fwebsetup/-/websetup-2.0.14.tgz'
)
2020-03-16 14:38:17 +00:00
).body;
2020-03-16 15:13:58 +00:00
await testPlugins.smartfile.memory.toFs(
downloadedFile,
testPlugins.path.join(testPaths.nogitDir, 'test.tgz')
);
2020-03-16 14:38:17 +00:00
});
tap.test('should extract files on disk', async () => {
const testSmartarchive = new smartarchive.SmartArchive();
await testSmartarchive.extractArchiveFromFilePath(
testPlugins.path.join(testPaths.nogitDir, 'test.tgz'),
testPlugins.path.join(testPaths.nogitDir)
);
});
2020-03-13 20:22:56 +00:00
2020-03-16 17:04:17 +00:00
tap.test('should download a package from the registry', async () => {
const testSmartarchive = new smartarchive.SmartArchive();
await testSmartarchive.extractArchiveFromUrl('https://verdaccio.lossless.one/@pushrocks%2fsmartfile/-/smartfile-7.0.11.tgz', testPaths.remoteDir);
});
2020-03-13 20:22:56 +00:00
tap.start();