BREAKING CHANGE(core): update
This commit is contained in:
13
test/plugins.ts
Normal file
13
test/plugins.ts
Normal file
@ -0,0 +1,13 @@
|
||||
import * as path from 'path';
|
||||
import * as smartpath from '@push.rocks/smartpath';
|
||||
import * as smartfile from '@push.rocks/smartfile';
|
||||
import * as smartrequest from '@push.rocks/smartrequest';
|
||||
import * as smartstream from '@push.rocks/smartstream';
|
||||
|
||||
export {
|
||||
path,
|
||||
smartpath,
|
||||
smartfile,
|
||||
smartrequest,
|
||||
smartstream,
|
||||
}
|
97
test/test.ts
97
test/test.ts
@ -1,23 +1,14 @@
|
||||
import { tap, expect } from '@push.rocks/tapbundle';
|
||||
|
||||
import * as path from 'path';
|
||||
import * as smartpath from '@push.rocks/smartpath';
|
||||
import * as smartfile from '@push.rocks/smartfile';
|
||||
import * as smartrequest from '@push.rocks/smartrequest';
|
||||
|
||||
const testPlugins = {
|
||||
path,
|
||||
smartfile,
|
||||
smartrequest,
|
||||
};
|
||||
import * as plugins from './plugins.js';
|
||||
|
||||
const testPaths = {
|
||||
nogitDir: testPlugins.path.join(
|
||||
smartpath.get.dirnameFromImportMetaUrl(import.meta.url),
|
||||
nogitDir: plugins.path.join(
|
||||
plugins.smartpath.get.dirnameFromImportMetaUrl(import.meta.url),
|
||||
'../.nogit/'
|
||||
),
|
||||
remoteDir: testPlugins.path.join(
|
||||
smartpath.get.dirnameFromImportMetaUrl(import.meta.url),
|
||||
remoteDir: plugins.path.join(
|
||||
plugins.smartpath.get.dirnameFromImportMetaUrl(import.meta.url),
|
||||
'../.nogit/remote'
|
||||
),
|
||||
};
|
||||
@ -25,80 +16,40 @@ const testPaths = {
|
||||
import * as smartarchive from '../ts/index.js';
|
||||
|
||||
tap.preTask('should prepare .nogit dir', async () => {
|
||||
await testPlugins.smartfile.fs.ensureDir(testPaths.remoteDir);
|
||||
await plugins.smartfile.fs.ensureDir(testPaths.remoteDir);
|
||||
});
|
||||
|
||||
tap.preTask('should prepare downloads', async (tools) => {
|
||||
const downloadedFile: Buffer = (
|
||||
await testPlugins.smartrequest.getBinary(
|
||||
await plugins.smartrequest.getBinary(
|
||||
'https://verdaccio.lossless.digital/@pushrocks%2fwebsetup/-/websetup-2.0.14.tgz'
|
||||
)
|
||||
).body;
|
||||
await testPlugins.smartfile.memory.toFs(
|
||||
await plugins.smartfile.memory.toFs(
|
||||
downloadedFile,
|
||||
testPlugins.path.join(testPaths.nogitDir, 'test.tgz')
|
||||
plugins.path.join(testPaths.nogitDir, 'test.tgz')
|
||||
);
|
||||
});
|
||||
|
||||
tap.test('should extract existing files on disk', async () => {
|
||||
const testSmartarchive = new smartarchive.SmartArchive();
|
||||
await testSmartarchive.extractArchiveFromFilePathToFs(
|
||||
testPlugins.path.join(testPaths.nogitDir, 'test.tgz'),
|
||||
testPlugins.path.join(testPaths.nogitDir)
|
||||
);
|
||||
});
|
||||
|
||||
tap.test('should download a package from the registry', async () => {
|
||||
const testSmartarchive = new smartarchive.SmartArchive();
|
||||
await testSmartarchive.extractArchiveFromUrlToFs(
|
||||
'https://verdaccio.lossless.digital/@pushrocks%2fsmartfile/-/smartfile-7.0.11.tgz',
|
||||
testPaths.remoteDir
|
||||
);
|
||||
});
|
||||
|
||||
tap.test('should extract a package using tarStream', async (tools) => {
|
||||
const done = tools.defer();
|
||||
const testSmartarchive = new smartarchive.SmartArchive();
|
||||
const testTgzBuffer = (
|
||||
await testPlugins.smartfile.Smartfile.fromFilePath(
|
||||
testPlugins.path.join(testPaths.nogitDir, 'test.tgz')
|
||||
)
|
||||
).contentBuffer;
|
||||
const extractionFileObservable = await testSmartarchive.extractArchiveFromBufferToObservable(
|
||||
testTgzBuffer
|
||||
);
|
||||
const subscription = extractionFileObservable.subscribe(
|
||||
(file) => {
|
||||
console.log(file.path);
|
||||
},
|
||||
(err) => {
|
||||
console.log(err);
|
||||
},
|
||||
() => {
|
||||
done.resolve();
|
||||
}
|
||||
);
|
||||
await done.promise;
|
||||
});
|
||||
|
||||
tap.test('should extract a file from url to replaySubject', async (tools) => {
|
||||
const done = tools.defer();
|
||||
const testSmartarchive = new smartarchive.SmartArchive();
|
||||
const extractionFileObservable = await testSmartarchive.extractArchiveFromUrlToObservable(
|
||||
const testSmartarchive = await smartarchive.SmartArchive.fromArchiveUrl(
|
||||
'https://verdaccio.lossless.digital/@pushrocks%2fwebsetup/-/websetup-2.0.14.tgz'
|
||||
);
|
||||
const subscription = extractionFileObservable.subscribe(
|
||||
(file) => {
|
||||
console.log(file.path);
|
||||
const streamfileStream = await testSmartarchive.exportToStreamOfStreamFiles();
|
||||
|
||||
streamfileStream.pipe(new plugins.smartstream.SmartDuplex({
|
||||
objectMode: true,
|
||||
writeAndTransformFunction: async (chunkArg: plugins.smartfile.StreamFile, streamtools) => {
|
||||
console.log(chunkArg.relativeFilePath);
|
||||
const streamFile = chunkArg;
|
||||
const readStream = await streamFile.createReadStream();
|
||||
const writePath = plugins.path.join(testPaths.nogitDir + streamFile.relativeFilePath);
|
||||
const dir = plugins.path.parse(writePath).dir;
|
||||
await plugins.smartfile.fs.ensureDir(plugins.path.dirname(dir));
|
||||
const writeStream = plugins.smartfile.fsStream.createWriteStream(writePath);
|
||||
readStream.pipe(writeStream);
|
||||
},
|
||||
(err) => {
|
||||
console.log(err);
|
||||
},
|
||||
() => {
|
||||
done.resolve();
|
||||
}
|
||||
);
|
||||
await done.promise;
|
||||
}));
|
||||
});
|
||||
|
||||
tap.start();
|
||||
|
Reference in New Issue
Block a user