Files
vercel/packages/node/test/unit/prepare-cache.test.ts
Nathan Rajlich 139e8cdb17 [node] Use vitest for unit tests (#11631)
Similar to #11302, but for the `@vercel/node` package.
2024-05-23 18:20:18 +00:00

39 lines
1.2 KiB
TypeScript

import { describe, test, expect } from 'vitest';
import path from 'path';
import assert from 'assert';
import { prepareCache } from '../../src';
describe('prepareCache()', () => {
test('should cache `**/node_modules/**`', async () => {
const files = await prepareCache({
files: {},
entrypoint: '.',
config: {},
workPath: path.resolve(__dirname, '../cache-fixtures/'),
repoRootPath: path.resolve(__dirname, '../cache-fixtures/'),
});
expect(files['foo/node_modules/file']).toBeDefined();
expect(files['node_modules/file']).toBeDefined();
expect(files['index.js']).toBeUndefined();
});
test('should ignore root modules', async () => {
const files = await prepareCache({
files: {},
entrypoint: '.',
config: {},
workPath: path.resolve(__dirname, '../cache-fixtures/foo/'),
repoRootPath: path.resolve(__dirname, '../cache-fixtures/foo/'),
});
const file = files['node_modules/file'];
expect(file).toBeDefined();
assert(file.type === 'FileFsRef');
expect(
file.fsPath.includes('cache-fixtures/foo/node_modules/file')
).toBeTruthy();
expect(files['index.js']).toBeUndefined();
});
});