Skip to content

Commit e84bb3f

Browse files
committed
add tests
1 parent 1e99042 commit e84bb3f

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

packages/nextjs/test/config.test.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as fs from 'fs';
22
import * as os from 'os';
33
import * as path from 'path';
44
import * as rimraf from 'rimraf';
5+
import { DefinePlugin } from 'webpack';
56

67
import { withSentryConfig } from '../src/config';
78
import {
@@ -326,6 +327,43 @@ describe('webpack config', () => {
326327
);
327328
});
328329
});
330+
331+
describe('`distDir` value in default server-side `RewriteFrames` integration', () => {
332+
describe('`DefinePlugin` existence and inclusion of `__rewriteFramesDistDir__` definition', () => {
333+
it.each([
334+
['no custom `distDir`, pre-existing `DefinePlugin`', undefined, true],
335+
['no custom `distDir`, no pre-existing `DefinePlugin`', undefined, false],
336+
['custom `distDir`, pre-existing `DefinePlugin`', 'some/output/directory', true],
337+
['custom `distDir`, no pre-existing `DefinePlugin`', 'some/output/directory', false],
338+
])(
339+
'%s',
340+
async (_testTitle: string, customDistDir: string | undefined, existingDefinePlugin: boolean): Promise<void> => {
341+
const userNextConfigMaybeWithDistDir = {
342+
...userNextConfig,
343+
...(customDistDir && { distDir: customDistDir }),
344+
};
345+
const serverWebpackConfigMaybeWithDefinePlugin = {
346+
...serverWebpackConfig,
347+
...(existingDefinePlugin && { plugins: [new DefinePlugin({ __dogName__: 'Maisey' })] }),
348+
};
349+
350+
const finalWebpackConfig = await materializeFinalWebpackConfig({
351+
userNextConfig: userNextConfigMaybeWithDistDir,
352+
incomingWebpackConfig: serverWebpackConfigMaybeWithDefinePlugin,
353+
incomingWebpackBuildContext: getBuildContext('server', userNextConfigMaybeWithDistDir),
354+
});
355+
356+
expect(finalWebpackConfig.plugins).toEqual(expect.arrayContaining([expect.any(DefinePlugin)]));
357+
358+
const definePluginInstance = findWebpackPlugin(finalWebpackConfig, 'DefinePlugin') as DefinePlugin;
359+
expect(definePluginInstance.definitions.__rewriteFramesDistDir__).toEqual(customDistDir);
360+
},
361+
);
362+
});
363+
describe('`RewriteFrames` ends up with correct `distDir` value', () => {
364+
// TODO: this, along with any number of other parts of the build process, should be tested with an integration test
365+
});
366+
});
329367
});
330368

331369
describe('Sentry webpack plugin config', () => {

0 commit comments

Comments
 (0)