Files
vercel/packages/static-build/test/prepare-cache.test.ts
Nathan Rajlich 58f479c603 [static-build] Add support for Build Output v3 detection (#7669)
Adds detection logic for a framework / build script outputting Build Output v3
format to the filesystem. In this case, `static-build` will simply stop processing
after the Build Command since deserialization happens in the build-container side
of things (this is different compared to the v1 output which gets handled in this
Builder. The reason for that is because the v3 output matches what `vc build`
outputs vs. v1 which is a different format).
2022-04-12 09:09:50 -07:00

63 lines
2.2 KiB
TypeScript
Vendored

import path from 'path';
import { prepareCache } from '../src';
describe('prepareCache()', () => {
test('should cache node_modules and .shadow-cljs', async () => {
const files = await prepareCache({
config: { zeroConfig: true },
workPath: path.resolve(__dirname, './cache-fixtures/default'),
entrypoint: 'index.js',
files: {},
});
expect(files['node_modules/file']).toBeDefined();
expect(files['.shadow-cljs/file5']).toBeDefined();
expect(files['index.js']).toBeUndefined();
});
test('should cache index.js and other/file2.js as defined in .vercel_build_output/config/build.json', async () => {
const files = await prepareCache({
config: { zeroConfig: true },
workPath: path.resolve(__dirname, './cache-fixtures/withCacheConfig'),
entrypoint: 'index.js',
files: {},
});
expect(files['node_modules/file']).toBeUndefined();
expect(files['.shadow-cljs/file5']).toBeUndefined();
expect(files['index.js']).toBeDefined();
expect(files['other/file2.js']).toBeDefined();
});
test('should cache node_modules, .cache and public folders for gatsby deployments', async () => {
const files = await prepareCache({
config: { zeroConfig: true },
workPath: path.resolve(__dirname, './cache-fixtures/gatsby'),
entrypoint: 'package.json',
files: {},
});
expect(files['node_modules/file2']).toBeDefined();
expect(files['.cache/file']).toBeDefined();
expect(files['public/file3']).toBeDefined();
expect(files['package.json']).toBeUndefined();
});
test('should cache ./vendor/bundle, ./vendor/bin, ./vendor/cache folders for jekyll deployments', async () => {
const files = await prepareCache({
config: { zeroConfig: true, framework: 'jekyll' },
workPath: path.resolve(__dirname, './cache-fixtures/jekyll'),
entrypoint: 'Gemfile',
files: {},
});
expect(files['vendor/bundle/b1']).toBeDefined();
expect(files['vendor/bin/jekyll']).toBeDefined();
expect(files['vendor/cache/c1']).toBeDefined();
expect(files['vendor/skip']).toBeUndefined();
expect(files['_config.yml']).toBeUndefined();
expect(files['_posts/hello.markdown']).toBeUndefined();
});
});