smartarchive/test/test.ts

56 lines
1.9 KiB
TypeScript
Raw Permalink Normal View History

2023-07-26 14:13:33 +00:00
import { tap, expect } from '@push.rocks/tapbundle';
2020-03-16 14:38:17 +00:00
2023-11-06 17:14:21 +00:00
import * as plugins from './plugins.js';
2020-03-16 14:38:17 +00:00
const testPaths = {
2023-11-06 17:14:21 +00:00
nogitDir: plugins.path.join(
plugins.smartpath.get.dirnameFromImportMetaUrl(import.meta.url),
2023-07-26 14:13:33 +00:00
'../.nogit/'
),
2023-11-06 17:14:21 +00:00
remoteDir: plugins.path.join(
plugins.smartpath.get.dirnameFromImportMetaUrl(import.meta.url),
2023-07-26 14:13:33 +00:00
'../.nogit/remote'
),
2020-03-16 15:13:58 +00:00
};
2020-03-16 14:38:17 +00:00
2022-04-04 12:15:51 +00:00
import * as smartarchive from '../ts/index.js';
2020-03-16 14:38:17 +00:00
tap.preTask('should prepare .nogit dir', async () => {
2023-11-06 17:14:21 +00:00
await plugins.smartfile.fs.ensureDir(testPaths.remoteDir);
2020-03-13 20:22:56 +00:00
});
2021-04-19 11:49:25 +00:00
tap.preTask('should prepare downloads', async (tools) => {
2020-03-16 14:38:17 +00:00
const downloadedFile: Buffer = (
2023-11-06 17:14:21 +00:00
await plugins.smartrequest.getBinary(
2023-07-26 14:13:33 +00:00
'https://verdaccio.lossless.digital/@pushrocks%2fwebsetup/-/websetup-2.0.14.tgz'
2020-03-16 15:13:58 +00:00
)
2020-03-16 14:38:17 +00:00
).body;
2023-11-06 17:14:21 +00:00
await plugins.smartfile.memory.toFs(
2020-03-16 15:13:58 +00:00
downloadedFile,
2023-11-06 17:14:21 +00:00
plugins.path.join(testPaths.nogitDir, 'test.tgz')
2020-03-16 15:13:58 +00:00
);
2020-03-16 14:38:17 +00:00
});
2020-03-17 00:21:05 +00:00
tap.test('should extract existing files on disk', async () => {
2023-11-06 17:14:21 +00:00
const testSmartarchive = await smartarchive.SmartArchive.fromArchiveUrl(
2023-07-26 14:13:33 +00:00
'https://verdaccio.lossless.digital/@pushrocks%2fwebsetup/-/websetup-2.0.14.tgz'
);
2023-11-06 17:14:21 +00:00
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);
2023-07-26 14:13:33 +00:00
},
2023-11-06 17:14:21 +00:00
}));
2020-03-16 17:04:17 +00:00
});
2020-03-13 20:22:56 +00:00
tap.start();