Skip to content

Commit

Permalink
add unit tests for extractBuildMetadataConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
dario-piotrowicz committed Dec 27, 2023
1 parent c67335e commit 2229136
Showing 1 changed file with 45 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { vi, describe, test, expect } from 'vitest';
import { getNextConfig } from '../../../src/buildApplication/nextConfig';
import {
extractBuildMetadataConfig,
getNextConfig,
} from '../../../src/buildApplication/nextConfig';

const mocks = vi.hoisted(() => ({
nextConfigJsFileExists: true,
Expand Down Expand Up @@ -86,3 +89,44 @@ describe('getNextConfigJs', () => {
});
});
});

describe('extractBuildMetadataConfig', () => {
test('handles an empty object correctly', async () => {
expect(extractBuildMetadataConfig({})).toEqual({});
});

test('extracts the desired metadata', async () => {
expect(
extractBuildMetadataConfig({
experimental: {
allowedRevalidateHeaderKeys: ['a', 'b', 'c'],
fetchCacheKeyPrefix: 'my-prefix',
},
}),
).toEqual({
experimental: {
allowedRevalidateHeaderKeys: ['a', 'b', 'c'],
fetchCacheKeyPrefix: 'my-prefix',
},
});
});

test('extract only the desired data', async () => {
expect(
extractBuildMetadataConfig({
experimental: {
allowedRevalidateHeaderKeys: ['123'],
incrementalCacheHandlerPath: '../../../test',
},
trailingSlash: true,
eslint: {
ignoreDuringBuilds: true,
},
}),
).toEqual({
experimental: {
allowedRevalidateHeaderKeys: ['123'],
},
});
});
});

0 comments on commit 2229136

Please sign in to comment.