我一直在创建一个单元测试来测试我的导入函数实现,但是我不能从.pipe()
行通过。以下是我的一些函数行,以获得更多上下文:
const { Body } = await s3.send(command);
console.log('body');
console.log(Body);
const input = (Body as any).pipe(zlib.createGunzip());
console.log('done body');
const lines = readline.createInterface({
input,
crlfDelay: Infinity,
});
console.log('done lines');
字符串
下面是我的单元测试代码:
describe('Import function', function () {
it('Import file', async () => {
const stream = createReadStream('./tests/data/test.csv');
const sdkStream = sdkStreamMixin(stream);
s3Mock.on(GetObjectCommand).resolves({ Body: sdkStream });
const event: any;
let context: any;
const result = await handler(event, context);
console.log(result);
});
});
型
正在打印console.log('body');
和console.log(Body);
行,Body
具有下一个值:
console.log
ReadStream {
fd: null,
path: './tests/data/GLOBAL.csv',
flags: 'r',
mode: 438,
start: undefined,
end: Infinity,
pos: undefined,
bytesRead: 0,
_readableState: ReadableState {
objectMode: false,
highWaterMark: 65536,
...
型
即使Body
有一个值,当我运行测试时,我得到了下一个错误:
console.log
TypeError: Cannot read properties of undefined (reading 'on')
at ReadStream.Readable.pipe (node:internal/streams/readable:711:8)
型
知道发生什么事了吗
我使用以下代码实现了s3 read mockup:https://www.npmjs.com/package/aws-sdk-client-mock之后,我尝试向s3Mock
对象添加另一个.on
值,但没有成功。
1条答案
按热度按时间luaexgnf1#
最后,我不得不将这些代码行移到一个新文件中,这样我就可以模拟文件导入