|
| 1 | +import * as isBuildModule from '../../src/utils/isBuild'; |
1 | 2 | import { defaultsObject, exportedNextConfig, runtimePhase, userNextConfig } from './fixtures';
|
2 | 3 | import { materializeFinalNextConfig } from './testUtils';
|
3 | 4 |
|
| 5 | +const isBuildSpy = jest.spyOn(isBuildModule, 'isBuild').mockReturnValue(true); |
| 6 | + |
4 | 7 | describe('withSentryConfig', () => {
|
5 | 8 | it('includes expected properties', () => {
|
6 | 9 | const finalConfig = materializeFinalNextConfig(exportedNextConfig);
|
@@ -59,4 +62,37 @@ describe('withSentryConfig', () => {
|
59 | 62 | // directly
|
60 | 63 | expect('sentry' in finalConfig).toBe(false);
|
61 | 64 | });
|
| 65 | + |
| 66 | + describe('conditional use of `constructWebpackConfigFunction`', () => { |
| 67 | + // Note: In these tests, it would be nice to be able to spy on `constructWebpackConfigFunction` to see whether or |
| 68 | + // not it's called, but that sets up a catch-22: If you import or require the module to spy on the function, it gets |
| 69 | + // cached and the `require` call we care about (inside of `withSentryConfig`) doesn't actually run the module code. |
| 70 | + // Alternatively, if we call `jest.resetModules()` after setting up the spy, then the module code *is* run a second |
| 71 | + // time, but the spy belongs to the first instance of the module and therefore never registers a call. Thus we have |
| 72 | + // to test whether or not the file is required instead. |
| 73 | + |
| 74 | + it('imports from `webpack.ts` if `isBuild` returns true', () => { |
| 75 | + jest.isolateModules(() => { |
| 76 | + // In case this is still set from elsewhere, reset it |
| 77 | + delete process.env.SENTRY_WEBPACK_MODULE_LOADED; |
| 78 | + |
| 79 | + materializeFinalNextConfig(exportedNextConfig); |
| 80 | + |
| 81 | + expect(process.env.SENTRY_WEBPACK_MODULE_LOADED).toEqual('true'); |
| 82 | + }); |
| 83 | + }); |
| 84 | + |
| 85 | + it("doesn't import from `webpack.ts` if `isBuild` returns false", () => { |
| 86 | + jest.isolateModules(() => { |
| 87 | + isBuildSpy.mockReturnValueOnce(false); |
| 88 | + |
| 89 | + // In case this is still set from elsewhere, reset it |
| 90 | + delete process.env.SENTRY_WEBPACK_MODULE_LOADED; |
| 91 | + |
| 92 | + materializeFinalNextConfig(exportedNextConfig); |
| 93 | + |
| 94 | + expect(process.env.SENTRY_WEBPACK_MODULE_LOADED).toBeUndefined(); |
| 95 | + }); |
| 96 | + }); |
| 97 | + }); |
62 | 98 | });
|
0 commit comments