Security: Sync from Public / sync-from-public (push) Has been cancelled
Test: Benchmark Nightly / build (push) Has been cancelled
Test: Benchmark Nightly / Notify Cats on failure (push) Has been cancelled
CI: Python / Checks (push) Has been cancelled
Test: Evals Python / Workflow Comparison Python (push) Has been cancelled
Util: Check Docs URLs / check-docs-urls (push) Has been cancelled
Test: Visual Storybook / Cloudflare Pages (push) Has been cancelled
Test: E2E Performance / build-and-test-performance (push) Has been cancelled
Test: Workflows Nightly / Run Workflow Tests (push) Has been cancelled
Util: Cleanup CI Docker Images / Delete stale CI images (push) Has been cancelled
Test: Benchmark Destroy Env / build (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Coverage Tests (push) Has been cancelled
46 lines
1.5 KiB
TypeScript
46 lines
1.5 KiB
TypeScript
import { NodeTestHarness } from '@nodes-testing/node-test-harness';
|
|
import type fs from 'fs';
|
|
import fsPromises, { type FileHandle } from 'fs/promises';
|
|
import { Readable } from 'stream';
|
|
|
|
describe('Test Crypto Node', () => {
|
|
jest.mock('fast-glob', () => async () => ['/test/binary.data']);
|
|
jest.mock('fs/promises');
|
|
fsPromises.access = async () => {};
|
|
fsPromises.stat = jest.fn(async (path: fs.PathLike) => {
|
|
if (path === '/test/binary.data') {
|
|
return {
|
|
isFile: () => true,
|
|
dev: 123456,
|
|
ino: 654321,
|
|
} as fs.Stats;
|
|
}
|
|
throw Object.assign(new Error('File not found'), { code: 'ENOENT' });
|
|
}) as unknown as typeof fsPromises.stat;
|
|
fsPromises.open = jest.fn(async (path: fs.PathLike) => {
|
|
if (path === '/test/binary.data') {
|
|
return {
|
|
close: async () => {},
|
|
// eslint-disable-next-line @typescript-eslint/require-await
|
|
stat: async () =>
|
|
({
|
|
isFile: () => true,
|
|
dev: 123456,
|
|
ino: 654321,
|
|
}) as fs.Stats,
|
|
createReadStream: () => {
|
|
const stream = Readable.from(Buffer.from('test')) as fs.ReadStream;
|
|
// Emit 'open' event asynchronously to match real fs.ReadStream behavior
|
|
setImmediate(() => stream.emit('open'));
|
|
return stream;
|
|
},
|
|
} as FileHandle;
|
|
}
|
|
throw Object.assign(new Error('File not found'), { code: 'ENOENT' });
|
|
}) as unknown as typeof fsPromises.open;
|
|
const realpathSpy = jest.spyOn(fsPromises, 'realpath');
|
|
realpathSpy.mockImplementation(async (path) => path as string);
|
|
|
|
new NodeTestHarness().setupTests();
|
|
});
|